51,410
社区成员
发帖
与我相关
我的任务
分享package drawTest1;
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class DrawTest1 {
public static void main(String[] args)
{
DrawTest1 t=new DrawTest1();
EventQueue.invokeLater(new Runnable()
{
public void run()
{
DrawSomeThingInterest picture=new DrawSomeThingInterest();//显示的是这行出错了
picture.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
picture.setVisible(true);
}
});
}
}
class DrawSomeThingInterest extends JFrame
{
public DrawSomeThingInterest()
{
setTitle("interest pictures");
setSize(DEFAULT_WIDTH,DEFAULT_HIGHT);
DrawingRun gameforme=new DrawingRun();
add(gameforme);
}
public static final int DEFAULT_WIDTH=600;
public static final int DEFAULT_HIGHT=500;
}
class DrawingRun extends JComponent
{
public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D) g;
double x1=10;
double y1=20;
double x2=100;
double y2=200;
Rectangle2D a1=new Rectangle2D.Double(x1,y1,x2,y2);
g2.draw(a1);
Ellipse2D ellipse=new Ellipse2D.Double();
ellipse.setFrame(a1);
g2.draw(ellipse);
g2.draw(new Line2D.Double(x1,y1,x1+x2,y1+y2));
double centerX=a1.getCenterX();
double centerY=a1.getCenterY();
double radius=200;
Ellipse2D circle=new Ellipse2D.Double();
circle.setFrameFromCenter(centerX,centerY,centerX+radius,centerY+radius);
g2.draw(circle);
}
}