不知道问题出在哪
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Test6 extends JFrame implements ActionListener
{
JLabel a1 = new JLabel("姓名");
JLabel a2 = new JLabel("密码");
JTextField t1 = new JTextField("");
JPasswordField t2 = new JPasswordField();
JButton bt = new JButton("登陆");
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
public Test6(String s)
{
super(s);
Container con = getContentPane();
setLayout(new FlowLayout());
con.add(p1);
con.add(p2);
p1.setLayout(new GridLayout(2,2));
p1(a1);
p1(t1);
p1(a2);
p1(t2);
p2.setLayout(new FlowLayout());
p2(bt);
bt.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
if(t1.equals("JAVA") && t2.equals("123"))
{
JOptionPane.showMessageDialog(null,"成功","提示消息",JOptionPane.CLOSED_OPTION);
}
else
{
JOptionPane.showMessageDialog(null,"错误","提示消息",JOptionPane.CLOSED_OPTION);
t1.setText("");
t2.setText("");
t1.requestDefaultFocus();
}
}
public static void main(String[] args)
{
Test6 x = new Test6();
x.setSize(200,200);
x.setLocation(300,300);
x.setTitle("good");
x.setVisible(true);
}
}
[此贴子已经被作者于2006-10-22 0:30:16编辑过]