




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1.抽象类(注:前5个类的主函数没有测试,直接在最后一个测试类中测试的)(1)package com.drawing;public abstract class Shape abstract void draw(); (2)package com.drawing;public class Point extends Shape private int x; private int y; public Point(int x,int y) super(); this.x=x; this.y=y; public Point() this.x=0; this.y=0; public int getX() return x;public void setX(int x) this.x = x;public int getY() return y;public void setY(int y) this.y = y; public void draw() System.out.println(Point is drawing!); public void print() System.out.println(x=+x+ y=+y); public static void main(String args) (3)package com.drawing;public class Line extends Shapeprivate Point pStart=null;private Point pEnd=null;public Line(Point pStart,Point pEnd)super();this.pStart=pStart;this.pEnd=pEnd;public Line()super();public Point getpStart() return pStart;public void setpStart(Point pStart) this.pStart = pStart;public Point getpEnd() return pEnd;public void setpEnd(Point pEnd) this.pEnd = pEnd;public String toString()return Line:+pStart.toString()+pEnd.toString();public void draw()System.out.println(Line is drawing!);public void print()System.out.println(pStart:+pStart.getX()+,+pStart.getY()+;pEnd:+pEnd.getX()+,+pEnd.getY();public boolean equals(Object o)if(this=o)return true;if(o=null)return false;if(o.getClass()!=this.getClass()return false;elseLine l=(Line)o;if(l.pStart=this.pStart&l.pEnd=this.pEnd)return true;elsereturn false;public double distance()return Math.sqrt(pStart.getX()-pEnd.getX()*(pStart.getX()-pEnd.getX()+(pStart.getY()-pEnd.getY()*(pStart.getY()-pEnd.getY();public static void main(String args)(4)package com.drawing;public class Circle extends Shapeprivate Point center=null;private double radius=0;public Circle(Point center,double radius)super();this.center=center;this.radius=radius;public Circle()super();public void draw()System.out.println(Center is drawing!);public String toString()return center:+(+center.getX()+,+center.getY()+)+,+radius:+radius;public void print()System.out.println(center is +(+center.getX()+,+center.getY()+)+;+radius is:+radius);public double area()return Math.PI*radius*radius;public double circurmference()return Math.PI*radius*2;public static void main(String args)(5)package com.drawing;public class Rectangle extends Shape private Point pLefttop=null;private Point pRightbottom=null;public Rectangle(Point pLefttop, Point pRightbottom) super();this.pLefttop = pLefttop;this.pRightbottom = pRightbottom;public Rectangle() super();public Point getpLefttop() return pLefttop;public void setpLefttop(Point pLefttop) this.pLefttop = pLefttop;public Point getpRightbottom() return pRightbottom;public void setpRightbottom(Point pRightbottom) this.pRightbottom = pRightbottom;public void draw()System.out.println(Rectangle is drawing!);public boolean equals(Object o)if(this=o)return true;if(o=null)return false;if(o.getClass()!=this.getClass()return false;elseRectangle e=(Rectangle)o;if(e.getpLefttop().equals(this.pLefttop) & e.getpRightbottom().equals(this.pRightbottom)return true;elsereturn false;public double area()return Math.sqrt(Math.pow(pLefttop.getX()-pRightbottom.getX(),2)*Math.sqrt(Math.pow(pLefttop.getY()-pRightbottom.getY(),2);public double circurmference()return Math.abs(pLefttop.getX()-pRightbottom.getX()*2+Math.abs(pLefttop.getY()-pRightbottom.getY()*2;public static void main(String args)(6)package com.drawing;public class Test public static void main(String args) Point p=new Point(1,2);p.print();p.draw();Point p4=new Point(5,3);Point p5=new Point(3,4);Line line=new Line(p4,p5);Line l1=new Line(new Point(5,3),new Point(3,4);line.draw();line.print();Shape s=line;s=new Point(5,9);(Point)s).print();System.out.println(line.equals(l1);System.out.println(Diatance is :+line.distance();Point p1=new Point(1,1);Circle c1=new Circle(p1,2);Circle c2=new Circle(new Point(0,1),3);c1.print();System.out.println(c1);c1.draw();System.out.println(area is :+c1.area();System.out.println(circurmference is :+c1.circurmference();Shape s1=new Circle(new Point(3,2),4);(Circle)s1).print();System.out.println(c1.equals(c2);运行结果:x=1 y=2Point is drawing!Line is drawing!pStart:5,3;pEnd:3,4x=5 y=9falseDiatance is :2.23606797749979center is (1,1);radius is:2.0center:(1,1),radius:2.0Center is drawing!area is :12.566370614359172circurmference is :12.566370614359172center is (3,2);radius is:4.0false2.定时器import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.Timer;public class TimePrinter implements ActionListener public void actionPerformed(ActionEvent event) System.out.println(Hello Curreat Data is:+new Date(); public static void main(String args) ActionListener listener=new TimePrinter(); Timer t=new Timer(2000, listener); t.start(); JOptionPane.showConfirmDialog(null, exit); System.exit(0); 运行结果:Hello Curreat Data is:Thu May 19 19:13:18 CST 2011Hello Curreat Data is:Thu May 19 19:13:20 CST 2011Hello Curreat Data is:Thu May 19 19:13:22 CST 2011Hello Curreat Data is:Thu May 19 19:13:24 CST 2011Hello Curreat Data is:Thu May 19 19:13:26 CST 2011Hello Curreat Data is:Thu May 19 19:13:28 CST 2011等等.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 辽宁省盘锦市兴隆台区辽河中学2024-2025学年八年级下学期期中生物试题(含答案)
- 设备维护管理规范
- 自动控制系统实验指导书
- 设备供货方案
- 广东省清远市四校联盟2024-2025学年高一下学期期中联考生物试卷(含答案)
- 幼儿园《小壁虎借尾巴》课件
- 2025年Android知识体系!阿里P8面试官都说太详细了一线互联网公司面经总结-android p8知识体系图
- 2025年android适配器ui2025年Android面经分享面试总结-android 适配器模式面试
- 建筑施工特种作业-建筑架子工(普通脚手架)真题库-5
- 山东数学特色题目及答案
- 2022年黑龙江省龙东地区中考地理试题及参考答案
- 混凝土模板支撑工程专项施工方案(140页)
- T∕CADERM 3041-2020 扩展的创伤重点超声评估规范
- 苏教版四年级数学下册试卷(全套)
- 五年级北师大版英语下学期语法填空易错专项练习题
- 100道结构力学弯矩图
- GRACE评分表教学提纲
- 机械连接扭矩检查记录
- 水利水电工程砖砌体单元评定表
- GB_T 24359-2021 第三方物流服务质量及测评(高清-现行)
- 院士专家工作站管理办法
评论
0/150
提交评论