package frame;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.swing.*;
public class frame implements ActionListener {
JFrame f=new JFrame();
JButton button=new JButton("Change colors");
JButton button2=new JButton("Change label");
JLabel label=new JLabel("I'm just a label");
public static void main(String[] args) {
frame gg=new frame();
gg.go();
}
public void go(){
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.addActionListener(new colorListener());
button2.addActionListener(new textListener());
DrawPanel d=new DrawPanel();
f.getContentPane().add(BorderLayout.CENTER,d);
f.getContentPane().add(BorderLayout.SOUTH,button);
f.getContentPane().add(BorderLayout.WEST,label);
f.setSize(500,400);
f.setVisible(true);
f.getContentPane().add(BorderLayout.EAST,button2);
}
class colorListener implements ActionListener{
public void actionPerformed(ActionEvent event2){
f.repaint();
}
}
class textListener implements ActionListener{
public void actionPerformed(ActionEvent event){
label.setText("I've changed!");
}
}
public void actionPerformed(ActionEvent event3){}
}
为什么我按button2的时候,repaint也会执行?