import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class test1 extends JFrame implements ActionListener//,ItemListener
{
JFrame jf = new JFrame ("用户登录");
Container con = jf.getContentPane();
JButton jbtnOK = new JButton("确定");
JButton jbtnCancel = new JButton("取消");
JButton jbtnExit = new JButton("退出");
JLabel jlbName = new JLabel("用户名");
JLabel jlbPass = new JLabel("密码");
JLabel jlbCategory = new JLabel("用户类型");
JComboBox jcbCategory = new JComboBox();
JTextField jtxtUser = new JTextField(10);
JTextField jtxtPass = new JTextField(10);
test1()
{
con.setLayout(new FlowLayout());
jf.setVisible(true);
jf.validate();
jf.setSize(200,300);
con.add(jlbCategory); con.add(jcbCategory);
con.add(jlbName); con.add(jtxtUser);
con.add(jlbPass); con.add(jtxtPass);
con.add(jbtnOK); con.add(jbtnCancel);
con.add(jbtnExit);
jbtnOK.addActionListener(this);
jbtnCancel.addActionListener(this);
jbtnExit.addActionListener(this);
jtxtUser.addActionListener(this);
jtxtPass.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
int type = JOptionPane.YES_OPTION;
if(e.getSource() == jbtnOK)
{
if (jtxtUser.getText() == "")
{
JOptionPane.showMessageDialog("用户名不可为空","信息提示框",type);//第一个参数可以申请为null,同时也可以使用jf来代替:具有居中面板的功效。你的所有问题依然如此!
}
else if (jtxtUser.getText() == "teacher" && jtxtPass.getText() == "teacher")
{
JOptionPane.showMessageDialog("教师用户登录成功");
}
else if (jtxtUser.getText() == "student" && jtxtPass.getText() == "student")
{
JOptionPane.showMessageDialog("学生用户登录成功");
}
}
}
}
public class test
{
public static void main(String args[])
{
new test1();
}
}
JOptionPane.showMessageDialog(jf,"教师用户登录成功");这样试试
你的JOptionpane.showMessageDialog方法写错错了
public static void showMessageDialog(Component parentComponent,
Object message)