1 package LHB.inherit; 2 import javax.swing.*; 3 import java.awt.*; 4 import java.awt.event.ActionEvent; 5 import java.awt.event.ActionListener; 6 public class Windows implements ActionListener 7 { 8 JFrame f; 9 JPanel p;10 JLabel a1,a2;11 JTextField c1,c2;12 JButton b1,b2;13 public Windows()14 {15 f=new JFrame("登陆");16 p=new JPanel();17 a1=new JLabel("用户名:");18 a2=new JLabel(" 口令:");19 b1=new JButton("确定");20 b2=new JButton("取消");21 c1=new JTextField(5);22 c2=new JTextField(5);23 f.setVisible(true);24 f.setSize(180,150);25 b1.addActionListener((ActionListener) this);26 p.add(a1);27 p.add(c1);28 p.add(a2);29 p.add(c2);30 p.add(b1);31 p.add(b2);32 f.add(p);33 }34 public void actionPerformed(ActionEvent e) 35 {36 p.setBackground(Color.blue);37 }38 public static void main(String[] args) 39 {40 new Windows();41 }42 43 }