(1)、事件的处理 JComboBox JList JTextField
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
public class jiemian {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
final JFrame f=new JFrame("登陆界面");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLayout(null);
f.setBounds(400,500,500, 400);
f.setVisible(true);
final JFrame f1=new JFrame("本学科科目");
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setLayout(null);
f1.setBounds(400, 500,500, 400);
JLabel l=new JLabel();
l.setText("姓名");
l.setBounds(100, 50,80, 50);
l.setFont(new java.awt.Font("姓名", 1, 20));
JLabel l1=new JLabel();
l1.setText("学号");
l1.setBounds(100, 100,80, 50);
l1.setFont(new java.awt.Font("学号", 1, 20));
JLabel l2=new JLabel();
l2.setText("班级");
l2.setBounds(100, 150, 80, 50);
l2.setFont(new java.awt.Font("班级", 1, 20));
JLabel L=new JLabel();
L.setText("科目");
L.setBounds(100, 50,80, 50);
L.setFont(new java.awt.Font("科目", 1, 20));
JTextField t=new JTextField();
t.setEditable(true);
t.setHorizontalAlignment(SwingConstants.LEFT);
t.setColumns(3);
t.setBounds(150, 50,200, 30);
JTextField t1=new JTextField();
t1.setEditable(true);
t1.setHorizontalAlignment(SwingConstants.LEFT);
t1.setColumns(3);
t1.setBounds(150, 100,200, 30);
JTextField t2=new JTextField();
t2.setEditable(true);
t2.setHorizontalAlignment(SwingConstants.LEFT);
t2.setColumns(3);
t2.setBounds(150, 150,200, 30);
JButton b=new JButton("登陆");
b.setBounds(150, 200,80, 30);
JButton b1=new JButton("退出");
b1.setBounds(250, 200,80,30);
String[] s={"大学英语4","概率统计","数据库原理与设计","JAVA","体育","毛概","多媒体应用"};
JComboBox c=new JComboBox(s);
c.setEditable(true);
c.setMaximumRowCount(4);
c.setBounds(150, 50, 200,30);
f.add(l);
f.add(l1);
f.add(l2);
f.add(t);
f.add(t1);
f.add(t2);
f.add(b);
f.add(b1);
f1.add(L);
f1.add(c);
b.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
f1.setVisible(true);
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
});
b1.addMouseListener(new MouseListener(){
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
f.setVisible(false);
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
});
}
}