override the paint(Graphics g) in class frame

解决方案 »

  1.   

    Kert_ake,你说的办法我试过,不行,好象在 Frame 类里没有 paint 方法
    可以 Override。不知道哪位大侠可以帮我,一定给分。
      

  2.   

    import java.awt.Graphics;
    import java.awt.Color;
    import javax.swing.*;public class DrawCircles extends JFrame{
         public DrawCircles()
         {
             super("DrwaCircles");
             pack();
             setSize(300,300);
             show();
         }
         public void paint (Graphics g)
    {
    int red, green,blue,x;
    String red1,green1,blue1;

    for (x=0;x<370;x+=30)
      { 
      red=(int)Math.floor(Math.random()*256);
      green=(int)Math.floor(Math.random()*256);
      blue=(int)Math.floor(Math.random()*256);
      g.setColor(new Color(red,green,blue));
      g.drawRect(x,10,30,30);
      g.drawOval(x,10,30,30);
      g.fillOval(x,10,30,30);
      //red1=(char)red;
      //green1=(char)green;
      //blue1=(char)blue;
      //g.drawString(red1+" " +green+ " "+blue,5,40);
      g.drawOval(x,80,30,30);
      x=x+5;
      }
    }
          public static void main (String args[])
          {
               new DrawCircles();
          }
    }