[请教]为什么有些方法可以直接写,不用加对象名或类名
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class testpanel
extends JFrame {
JPanel jp1;
JPanel jp2;
Container cp = getContentPane();
JButton b1 = new JButton("1");
JButton b5 = new JButton("2");
public testpanel() {
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cp.remove(jp1);
cp.add(jp2);
setVisible(true); ?????????????????????????
repaint(); ?????????????????????????
}
});
b5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cp.remove(jp2);
cp.add(jp1);
setVisible(true);
repaint();
}
});
jp1 = new JPanel();
jp1.setLayout(new BorderLayout());
jp1.add(BorderLayout.CENTER, b1);
jp2 = new JPanel();
jp2.setLayout(new BorderLayout());
jp2.add(BorderLayout.CENTER, img);
cp.add(jp1);
setSize(500, 500);
setVisible(true);
}
public static void main(String[] args) {
testpanel app = new testpanel();
app.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
-------------------------------------------------------------------------------------
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cp.remove(jp1);
cp.add(jp2);
setVisible(true); ?????????????????????????
repaint(); ?????????????????????????
}
});
到底哪个对象被setVisible(true);
和被repaint()了
请教了,谢谢