package zwzw;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class b implements ActionListener {
JFrame f;
JPanel a;
JLabel c;
JButton d;
public b (){
f=new JFrame("这是一个窗口");
a=new JPanel();
c=new JLabel("hit me");
d=new JButton("ok");
d.addActionListener(this);
c.setBounds(150, 82, 80, 55);
d.setBounds(50, 200, 80, 40);
a.add(c);
a.add(d);
a.setBackground(Color.pink);
f.add(a);
f.setVisible(true);
f.setSize(400, 500);
}
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
a.setBackground(Color.blue);
c.setVisible(false);
}
public static void main(String args[]) {
new b();
}
}
一、导入包 二、声明组件 三、构造方法 new组件 四、添加组件 5、main方法