如何解决repaint的问题啊??
import java.awt.*;import javax.swing.*;
import java.awt.event.*;
class MyGraphics extends JPanel implements ActionListener
{
JPanel pal1=new JPanel();
JPanel pal2=new JPanel();
JButton btn1,btn2,btn3;
public MyGraphics()
{
setLayout(new BorderLayout());
btn1=new JButton("三角形");
btn2=new JButton("矩形");
btn3=new JButton("椭圆形");
add(pal1,"North");
add(pal2,"Center");
pal1.add(btn1);
pal1.add(btn2);
pal1.add(btn3);
pal2.setLayout(new GridLayout(3,3));
//pal2.add(btn1);
//pal2.add(btn2);
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand()=="矩形")
{
pal2.add(new RectangleDemo());
System.out.println("1");
}
pal2.repaint();
pal1.repaint();
repaint();
}
public class RectangleDemo extends JPanel
{
public void paintComponent(Graphics g)
{
String s="123";
g.fillRect(10,10,20,20);
//g.drawString(s,20,20);
System.out.println("2");
//repaint();
System.out.println("3");
}
}
}
public class MyGraphicsDemo extends JFrame
{
public MyGraphicsDemo()
{
setSize(400,300);
Container con=getContentPane();
con.add(new MyGraphics());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String []args)
{
new MyGraphicsDemo().show();
}
}
如何解决a