//主函数
package shapes;
public class MyPic {
public static void main(String[] args)
{
Picture pic = new Picture(420,300);
//Rectangle r1 = new Rectangle(100, 100, 100, 100);
//Triangle t1 = new Triangle(100, 100, 200, 100, 150, 50);
Line l1 = new Line(149,230,149,400);
Line l2 = new Line(151,230,151,400);
Circle c1 = new Circle(150,150,20);
Circle c2 = new Circle(150,150,40);
Circle c3 = new Circle(150,150,60);
Circle c4 = new Circle(150,150,80);
Src b1 = new Src(217,-125,500,500,150,120);
//pic.add(r1);
//pic.add(t1);
pic.add(l1);
pic.add(l2);
pic.add(c1);
pic.add(c2);
pic.add(c3);
pic.add(c4);
pic.add(b1);
pic.draw();
}
}
//类:Circle
package shapes;
import java.awt.Graphics;
public class Circle extends Shape {
private int x;
private int y;
private int radius;
public Circle(int x, int y, int radius)
{
this.x = x;
this.y = y;
this.radius = radius;
}
@Override
public void draw(Graphics g) {
g.drawOval(x-radius, y-radius, radius*2, radius*2);
}
}
//类:Line
package shapes;
import java.awt.Graphics;
public class Line extends Shape {
private int x1;
private int y1;
private int x2;
private int y2;
public Line(int x1, int y1, int x2, int y2)
{
this.x1 = x1; this.y1 = y1;
this.x2 = x2; this.y2 = y2;
}
@Override
public void draw(Graphics g) {
g.drawLine(x1, y1, x2, y2);
}
}
//类:Triangle
package shapes;
import java.awt.Graphics;
public class Triangle extends Shape {
private int[] x = new int[3];
private int[] y = new int[3];
public Triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
x[0] = x1; x[1] = x2; x[2] = x3;
y[0] = y1; y[1] = y2; y[2] = y3;
}
@Override
public void draw(Graphics g) {
g.drawPolygon(x, y, x.length);
}
}
//类:Picture
package shapes;
import java.awt.Graphics;
public class Triangle extends Shape {
private int[] x = new int[3];
private int[] y = new int[3];
public Triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
x[0] = x1; x[1] = x2; x[2] = x3;
y[0] = y1; y[1] = y2; y[2] = y3;
}
@Override
public void draw(Graphics g) {
g.drawPolygon(x, y, x.length);
}
}
//类:Rectangle
package shapes;
import java.awt.Graphics;
public class Rectangle extends Shape {
private int x;
private int y;
private int width;
private int height;
public Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
@Override
public void draw(Graphics g) {
g.drawRect(x, y, width, height);
}
}
//类:Shape
package shapes;
import java.awt.Graphics;
public abstract class Shape {
public abstract void draw(Graphics g);
}
Java图形界面-画图程序
最新推荐文章于 2024-02-23 15:09:51 发布