Java图形界面-画图程序
2015-08-06 17:53
351 查看
//主函数 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基础 牛逼老师的总结
- 【Android注释技巧】Android函数上面的注释你是怎么写的?(Eclipse中)
- Java--内部类,局部类与匿名类
- eclipse构建及运行maven web项目
- jrebel 6.2.1 eclipse破解安装
- Java类加载器总结
- Java 输出日历格式
- java.util.logging.Logger使用详解
- Spring注解运行时抛出null
- Java程序设计之算出一年第多少天
- 【Thinking in Java】编写构造器时应注意:尽量避免调用其他非private方法
- Java发送邮件的一个简单Demo
- java代码拷贝到word中保持代码高亮方法
- 深入学习java.lang.Class类
- Java import static
- 关于java Struts框架简要说明
- 图解Eclipse j2ee开发环境的搭建过程
- Java NIO 和IO 对比
- java倒计时弹出框
- 深入学习java.lang.Runtime类