如何在swt desiger中实现button的清空与登录功能即如何修改下列代码package com.accp.zxt;import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;public class Mine extends JFrame {
private JPasswordField passwordField;
private JTextField textField;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Mine frame = new Mine();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Create the frame
*/
public Mine() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 257, 313);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button.setText("登录");
button.setBounds(56, 197, 57, 23);
getContentPane().add(button); final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button_1.setText("清空");
button_1.setBounds(135, 197, 57, 23);
getContentPane().add(button_1); textField = new JTextField();
textField.setBounds(107, 60, 85, 23);
getContentPane().add(textField); passwordField = new JPasswordField();
passwordField.setBounds(107, 112, 85, 23);
getContentPane().add(passwordField); final JLabel label = new JLabel();
label.setText("用户名");
label.setBounds(56, 60, 45, 23);
getContentPane().add(label); final JLabel label_1 = new JLabel();
label_1.setText("密 码");
label_1.setBounds(56, 116, 45, 15);
getContentPane().add(label_1);
//
}}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;public class Mine extends JFrame {
private JPasswordField passwordField;
private JTextField textField;
/**
* Launch the application
* @param args
*/
public static void main(String args[]) {
try {
Mine frame = new Mine();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} /**
* Create the frame
*/
public Mine() {
super();
getContentPane().setLayout(null);
setBounds(100, 100, 257, 313);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button.setText("登录");
button.setBounds(56, 197, 57, 23);
getContentPane().add(button); final JButton button_1 = new JButton();
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
button_1.setText("清空");
button_1.setBounds(135, 197, 57, 23);
getContentPane().add(button_1); textField = new JTextField();
textField.setBounds(107, 60, 85, 23);
getContentPane().add(textField); passwordField = new JPasswordField();
passwordField.setBounds(107, 112, 85, 23);
getContentPane().add(passwordField); final JLabel label = new JLabel();
label.setText("用户名");
label.setBounds(56, 60, 45, 23);
getContentPane().add(label); final JLabel label_1 = new JLabel();
label_1.setText("密 码");
label_1.setBounds(56, 116, 45, 15);
getContentPane().add(label_1);
//
}}
解决方案 »
- myeclipse下如何配置jfreechart?
- 一个关于时间和多线程的代码请高手指正一下
- 200分请教,网络传输是不是永远没有USB移动硬盘传递快?
- 请问我如果用jdk1.5,tomcat5.5开发,那么hibernate,spring,struts有支持jdk1.5的版了吗
- 一个简单的算法问题
- eclipse3.01有官方的多国语言包吗?
- 关于文件输出的问题!!!
- 如何用java垂直显示字符串
- 如何让已经固定布局的控键随着怎个窗体的大小进行相映的变化
- 新手送分题(又是无法显示)!!
- 见文章中的代码,我想问一下虽然只实现了一个 Addsql,但放在线程里去了却不了一个?
- 一个tomcat下两个站点.怎么设置能实现既可以用ip访问,又可以用域名访问啊?
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;public class LoginDemo extends Shell
{ private Text txtPsd; private Text txtUser; /**
* Launch the application
* @param args
*/
public static void main(String args[])
{
try
{
Display display = Display.getDefault();
LoginDemo shell = new LoginDemo(display, SWT.SHELL_TRIM);
shell.open();
shell.layout();
while(!shell.isDisposed())
{
if(!display.readAndDispatch())
{
display.sleep();
}
}
display.dispose();
}
catch(Exception e)
{
e.printStackTrace();
}
} /**
* Create the shell
* @param display
* @param style
*/
public LoginDemo(Display display, int style)
{
super(display, style);
createContents();
} /**
* Create contents of the window
*/
protected void createContents()
{
setText("SWT Application");
setSize(416, 279); final Label lbUser = new Label(this, SWT.NONE);
lbUser.setText("用户名");
lbUser.setBounds(45, 80, 52, 21); final Label lbPsd = new Label(this, SWT.NONE);
lbPsd.setText("密 码");
lbPsd.setBounds(45, 120, 52, 21); txtUser = new Text(this, SWT.BORDER);
txtUser.setBounds(103, 75, 260, 25); txtPsd = new Text(this, SWT.BORDER);
txtPsd.setEchoChar('*');
txtPsd.setBounds(103, 113, 260, 25); final Button btnLogin = new Button(this, SWT.NONE);
btnLogin.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
}
});
btnLogin.setText("登陆");
btnLogin.setBounds(80, 191, 84, 25); final Button btnClear = new Button(this, SWT.NONE);
btnClear.addSelectionListener(new SelectionAdapter()
{
public void widgetSelected(final SelectionEvent e)
{
}
});
btnClear.setText("清空");
btnClear.setBounds(244, 191, 84, 25);
//
} @Override
protected void checkSubclass()
{
// Disable the check that prevents subclassing of SWT components
}
}