import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class FrameTest
{
public static void main(String[] agrs)
{
DrawFrame frame=new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class DrawFrame extends JFrame
{
public void DrameFrame()
{
setTitle("DrawTest");
setLocation(20,20);
setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
Mypanel component=new Mypanel();
add(component);
}
public final int DEFAULT_WIDTH=500;
public final int DEFAULT_HEIGHT=600;
}
class Mypanel extends JPanel
{
public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D) g;
double leftX=100;
double topY=100;
double width=100;
double height=150;
Rectangle2D rect=new Rectangle2D.Double(leftX,topY,width,height);
g2.draw(rect);
Ellipse2D ellipse=new Ellipse2D.Double();
ellipse.setFrame(rect);
g2.draw(ellipse);
g2.draw(new Line2D.Double(leftX,topY,leftX+width,topY+height));
double centerX=rect.getCenterX();
double centerY=rect.getCenterY();
double radious=150;
Ellipse2D circle=new Ellipse2D.Double();
circle.setFrameFromCenter(centerX,centerY,centerX+radious,centerY+radious);
g2.draw(circle);
}
}
运行结束后,正常情况定下是一个圆,里面套个矩形,再套个椭圆,然后穿个线。但是运行后只出现一个小框框..啥都没有,求教,我是按照书里的码字打得
------解决方案--------------------------------------------------------
public static void main(String[] agrs) {
DrawFrame frame = new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.drameFrame();
}
------解决方案--------------------------------------------------------
黄色的杠杠,是因为,你是在main函数中调用你的内部类和内部类的方法,而main函数是static,static函数调用非static函数,会有这样的警告