package zuoye;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;
public class zuoye0 {
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f=new JFrame("用户登录");
JPanel p3=new JPanel();
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(3,2));
p3.setLayout(new GridLayout(2,1));
JLabel c0=new JLabel("用户类型:");
p1.add(c0);
JComboBox c1=new JComboBox();
c1.addItem("学生用户");
c1.addItem("教师用户");
p1.add(c1);
JLabel c2=new JLabel("用户名:");
p1.add(c2);
JTextField c3=new JTextField();
p1.add(c3);
JLabel c4=new JLabel("密码:");
p1.add(c4);
JTextField c5=new JTextField();
p1.add(c5);
p3.add(p1);
JPanel p2=new JPanel();
JButton a1=new JButton("确定");
//a1.addActionListener()(new ActionListener(){
// public void actionPerformed(ActionEvent e){
//};
p2.add(a1);
JButton a2=new JButton("取消");
p2.add(a2);
JButton a3=new JButton("退出");
p2.add(a3);
p3.add(p2);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p3);
f.setVisible(true);
final JDialog jd=new JDialog(f,"提示信息");
jd.setSize(200,200);
jd.setLocation(50,60);
final JLabel jLable1=new JLabel();
a1.addActionListener(new ActionListener(){
String xx;
public void itemStateChanged(ItemEvent e)
{xx=(String)c1.getSelectedItem();}
public void actionPerformed(ActionEvent e){//jd.setModal(true);
if (e.getSource() == a1) {
if (xx=="学生用户"&&jd.getComponents().length==1) {jLable1.setText("学生");
}
else if (xx=="教师用户"&&jd.getComponents().length==1) {jLable1.setText("教师");
}
}
jd.add(jLable1);
jd.setVisible(true);}
});
}
}
//为什么弹窗中没有文本信息?希望可以修改的简单些!!!