public class myJFrame extends JFrame implements ActionListener {
private JButton but1, but2, but;
Container cp = this.getContentPane();
JPanel p = new JPanel(new FlowLayout(1, 5, 5));
public myJFrame() {
super("彭杰的窗口");
but1 = new JButton("放大");
but2 = new JButton("缩小");
but1.addActionListener(this);
but2.addActionListener(this);
p.add(but1);
p.add(but2);
cp.add(p, BorderLayout.SOUTH);
}
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.green);
g.fillOval(150, 150, 100, 100);
}
public void actionPerformed(ActionEvent e) {
JButton but = new JButton();
but = (JButton) e.getSource();
if (but1 == but) {
System.out.println("你点击了放大");
}
if (but2 == but) {
System.out.println("你点击了缩小");
}
}
}