求Java 从对话框中(Dialog)输入一个数,输入1画线,2画圈,三画方框.每个图形个数1-7.窗口大小为(300,300);
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/14 06:07:22
求Java 从对话框中(Dialog)输入一个数,输入1画线,2画圈,三画方框.每个图形个数1-7.窗口大小为(300,300);
求Java 从对话框中(Dialog)输入一个数,输入1画线,2画圈,三画方框.每个图形个数1-7.
窗口大小为(300,300);
求Java 从对话框中(Dialog)输入一个数,输入1画线,2画圈,三画方框.每个图形个数1-7.窗口大小为(300,300);
//只是做了 能够显示 线 圈 方框
//其他地方 楼主自己修改下
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.geom.Arc2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
class J_Panel extends JPanel
{
protected void paintComponent(Graphics g)
{
int[] x =
{ 55,67,109 };
int[] y =
{ 0,36,36 };
Graphics2D g2d = (Graphics2D) g;
g.clearRect(0,0,getWidth(),getHeight());
g.drawLine(30,30,30,90);
g2d.translate(80,20);
g2d.draw(new Rectangle(0,10,60,40));
g2d.translate(50,20);
g2d.rotate(Math.PI / 2);
g2d.rotate(-Math.PI / 2);
g2d.translate(40,-30);
g2d.draw(new Arc2D.Double(0,30,40,40,0,360,Arc2D.OPEN));
g2d.translate(70,0);
g2d.draw(new Polygon(x,y,x.length));
}
}
public class pic extends JFrame
{
public pic()
{
super("图形显示");
Container c = getContentPane();
c.add(new J_Panel(),BorderLayout.CENTER);
}
public static void main(String args[])
{
pic pp = new pic();
pp.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pp.setSize(300,300);
pp.setVisible(true);
}
}