云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 软件测试期末作业

软件测试期末作业

  • 62 次阅读
  • 3 次下载
  • 2025/12/10 17:16:37

//数字时钟

public class ShiZhong extends JFrame implements Runnable {

Thread clock;

final int Xpoint=180; final int Ypoint=180; final int R=80;

int xHour=0,yHour=0,xSecond=0,ySecond=0,xMin=0,yMin=0; public ShiZhong() {

super(\数字时钟\); //调用父类构造函数

setFont(new Font(\宋体\,Font.BOLD,20)); //设置时钟的显示字体

start(); //开始进程

setSize(360,360); //设置窗口尺寸 setVisible(true); //窗口可视

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //关闭窗口时退出程序 }

public void start() { //开始进程

if(clock==null)//如果进程为空值

{

clock=new Thread(this); //实例化进程 clock.start(); //开始进程 } }

public void run()//运行进程 {

while (clock!=null) {

repaint(); //调用paint方法重绘界面 try {

Thread.sleep(1000); //线程暂停一秒(1000毫秒) }

catch (InterruptedException ex){ ex.printStackTrace(); //输出出错信息 } } }

public void stop()//停止进程 {

clock=null;

}

public void paint(Graphics g)//重载组件的paint方法 {

Graphics2D g2=(Graphics2D)g; //得到Graphics2D对象 DateFormat dateFormat =

DateFormat.getDateInstance(DateFormat.FULL);

Calendar now=new GregorianCalendar(); //实例化日历对象 now.setTime(new

Date());//dateFormat.format(now.getTime()) String timeInfo=\; //输出信息

int hour=now.get(Calendar.HOUR_OF_DAY); //得到小时数 int minute=now.get(Calendar.MINUTE); //得到分数 int second=now.get(Calendar.SECOND); //得到秒数 if (hour<=9)

timeInfo+=\+hour+\; //格式化输出 else

timeInfo+=hour+\; if (minute<=9)

timeInfo+=\+minute+\; else

timeInfo+=minute+\; if (second<=9)

timeInfo+=\+second; else

timeInfo+=second;

g.setColor(Color.yellow); //设置当前颜色为黄色 Dimension dim=getSize(); //得到窗口尺寸

g.fillRect(0,0,dim.width,dim.height); //填充背景色为白色

g.setColor(Color.red); //设置当前颜色为红色 g.drawString(timeInfo,130,340); //显示时间字符串 g.setColor(Color.green);

g.drawString(dateFormat.format(now.getTime()),20,60); g.setColor(Color.black);

g.setFont(new Font(\,Font.BOLD,15)); for(int i=0,num=12;i<360;i+=6) {

double alfa = Math.toRadians(i); int xPos=Xpoint+(int)(R*Math.sin(alfa)); int yPos=Ypoint-(int)(R*Math.cos(alfa)); if(i==0) {

if (num%3==0)

g.setColor(Color.red); // 数字3,6,9,12为红色

搜索更多关于: 软件测试期末作业 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

//数字时钟 public class ShiZhong extends JFrame implements Runnable { Thread clock; final int Xpoint=180; final int Ypoint=180; final int R=80; int xHour=0,yHour=0,xSecond=0,ySecond=0,xMin=0,yMin=0; public ShiZhong() { super(\数字时钟\); //调用父类构造函数 setFont(new Font(\宋体\,Font.BOLD,20)); //设置时钟的显示字体 start(); //开始进程

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com