如何在swt desiger中实现button的清空与登录功能

sunyraindrop 2007-12-23 02:50:37
如何在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);
//
}

}
...全文
81 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
craky 2007-12-24
  • 打赏
  • 举报
回复

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
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧