想出现一个窗口,里面画一个方框,支持重绘,窗口是出来了,框一直出不来,请教各位:
import javax.swing.*;
import java.awt.*;public class test extends JFrame
{
    public static void main(String[] args)
    {
        JFrame frame=new JFrame("LZ");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setVisible(true);
    }
    public void paint(Graphics g)
    {
super.paint(g);
g.setColor(Color.red);
g.fillRect(100,100,200,200);
    }
}

解决方案 »

  1.   

    你继承Frame JFrame好象不会重绘
      

  2.   

    import javax.swing.*; 
    import java.awt.*; public class test

        public static void main(String[] args) 
        { 
            FillFrame frame=new FillFrame(); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    frame.show();
        } }class FillFrame extends JFrame
    {
    public FillFrame()
    {
    setTitle("LZ");
    setSize(500,500);

    FillPanel panel = new FillPanel();
    Container contentPane = getContentPane(); contentPane.add(panel);
    }

    }class FillPanel extends JPanel
    {
    public void paintComponent(Graphics g)
    {
    super.paintComponent(g); g.setColor(Color.red);
    g.fillRect(100,100,200,200);


    }
    }//这样行不?