51,410
社区成员
发帖
与我相关
我的任务
分享import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
class DrawJPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
Rectangle2D rect = new Rectangle2D.Double(top_x,top_y,WIDTH,HEIGHT);
g2.draw(rect);
Ellipse2D ellipse = new Ellipse2D.Double(top_x,top_y,WIDTH,HEIGHT);
ellipse.setFrame(rect);
g2.draw(ellipse);
Line2D line = new Line2D.Double(new Point2D.Double(top_x,top_y),new Point2D.Double(top_x+WIDTH,top_y+HEIGHT));
g2.draw(line);
Ellipse2D circle = new Ellipse2D.Double();
circle.setFrameFromCenter(centerX,centerY,centerX+radius,centerY+radius);
g2.draw(circle);
double centerX = rect.getCenterX();
double centerY = rect.getCenterY();
double radius = 150;
double top_x = 200;
double top_y = 150;
double WIDTH = 200;
double HEIGHT = 100;
}
}
class DrawJFrame extends JFrame
{
public DrawJFrame()
{
setTitle("SHAPE");
setSize(Frame_WIDTH,Frame_HEIGHT);
DrawJPanel panel = new DrawJPanel();
add(panel);
}
public static final int Frame_WIDTH = 800;
public static final int Frame_HEIGHT = 600;
}
class DrawTest
{
public static void main(String[] args)
{
DrawJFrame frame = new DrawJFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}求助大神 这个为什么运行会报错import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
class DrawJPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
double top_x = 200;
double top_y = 150;
double WIDTH = 200;
double HEIGHT = 100;
Rectangle2D rect = new Rectangle2D.Double(top_x,top_y,WIDTH,HEIGHT);
g2.draw(rect);
Ellipse2D ellipse = new Ellipse2D.Double(top_x,top_y,WIDTH,HEIGHT);
ellipse.setFrame(rect);
g2.draw(ellipse);
Line2D line = new Line2D.Double(new Point2D.Double(top_x,top_y),new Point2D.Double(top_x+WIDTH,top_y+HEIGHT));
g2.draw(line);
double centerX = rect.getCenterX();
double centerY = rect.getCenterY();
double radius = 150;
Ellipse2D circle = new Ellipse2D.Double();
circle.setFrameFromCenter(centerX,centerY,centerX+radius,centerY+radius);
//circle.setFrameFromCenter(300,200,450,350);
g2.draw(circle);
}
}
class DrawJFrame extends JFrame
{
public DrawJFrame()
{
setTitle("SHAPE");
setSize(Frame_WIDTH,Frame_HEIGHT);
DrawJPanel panel = new DrawJPanel();
add(panel);
}
public static final int Frame_WIDTH = 800;
public static final int Frame_HEIGHT = 600;
}
class DrawTest
{
public static void main(String[] args)
{
DrawJFrame frame = new DrawJFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}