Java编写一个窗体,用户可以输入用户名密码,求大神帮助
要求:按确定的时候,弹出提示框,显示"你输入的姓名为:"+用户输入的姓名.
按退出按钮时,窗体关闭.
求大神帮助我呀 展开
2014-06-28
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class FrameTest extends JFrame implements ActionListener {
private JTextField textField;
private JPasswordField passwordField;
private JButton button;
public FrameTest() {
super("窗体测试");
textField = new JTextField("这里写姓名,下面写密码");
passwordField = new JPasswordField("");
button = new JButton("确定");
textField.setBounds(60, 10, 200, 30);
passwordField.setBounds(60, 70, 200, 30);
button.setBounds(70, 120, 150, 35);
button.addActionListener(this);
this.setLayout(null);
this.add(textField);
this.add(passwordField);
this.add(button);
this.setSize(300, 200);
this.setDefaultCloseOperation(3);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(this, "你输入的姓名为:" + textField.getText());
}
public static void main(String[] args) {
new FrameTest();
}
}