当前位置: 代码迷 >> Java相关 >> 如何解决repaint的问题啊??
  详细解决方案

如何解决repaint的问题啊??

热度:276   发布时间:2005-04-13 14:47:00.0
如何解决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
搜索更多相关的解决方案: repaint  

----------------解决方案--------------------------------------------------------
不明白什么意思?
----------------解决方案--------------------------------------------------------
你要解决什么?

问题呢?
----------------解决方案--------------------------------------------------------