GetContentPane和SetContentPane Eror

时间:2017-11-05 09:56:23

标签: java swing jframe jpanel contentpane

package javagraphics;
import java.awt.BasicStroke;
import java.awt.Color;
import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import javax.swing.JPanel;
import static java.lang.Math.*;
import java.util.Random;

public class JavaGraphics extends JFrame{  




class DrawArea extends JFrame
{   

   Point A,B,C,D,E,F = null;     
   int Loop =25; 
   int length = 100; 
    public DrawArea()
    {    
    //x=1366,y=705
     A = new Point (200,200);

    }

   @Override
    public void paintComponent(Graphics g){

         }

    for (int i = 0; i <500; i++) {

    **some code to draw a line**
        }

     }

}
 public static void main(String[] args) 
    {
    JavaGraphics canvas = new JavaGraphics();
    canvas.setSize(1366,768); 
    canvas.setLocationRelativeTo(null);
    canvas.setDefaultCloseOperation(EXIT_ON_CLOSE);    
    canvas.setContentPane(new DrawArea());
    canvas.pack();
    canvas.setVisible(true);
    }

}

我的问题是关于setcontentpane和getcontentpane 在最后一栏“canvas.setContentPane(new DrawArea());” ,我设置的contentpane是错误的 你可以找到答案,并告诉我为什么会出现这样的错误? 谢谢你..

“canvas.setContentPane(new DrawArea());” 当它运行我的窗口时只是灰色而不是显示我已编码的线条模式,它说“非静态变量,这不能从静态上下文中反映”

0 个答案:

没有答案