import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
import java.net.*;
import java.awt.image.*;
class RotateG
{
private Graphics g;
private int ox = 0;
private int oy = 0;
private double radians = 0.0;
private double cos = 1.0;
private double sin = 0.0;
public RotateG(Graphics g)
{
this.g = g.create();
}
public void setOrigin(int x, int y)
{
ox = x;
oy = y;
}
public void setAngle(double a)
{
radians = (a * Math.PI) / 180;
cos = Math.cos(radians);
sin = Math.sin(radians);
}
public void setColor(Color c)
{
g.setColor(c);
}
public int rotate_x(int x, int y)
{
return ((int) (ox + x * cos - y * sin));
}
public int rotate_y(int x, int y)
{
return ((int) (oy + y * cos + x * sin));
}
public void drawLine(int x1, int y1, int x2, int y2)
{
g.drawLine(rotate_x(x1, y1),
rotate_y(x1, y1),
rotate_x(x2, y2),
rotate_y(x2, y2));
}
public void drawOval(int x, int y, int width, int height)
{
g.drawOval(x,y,width,height);
}
public void fillOval(int x, int y, int width, int height)
{
g.fillOval(x,y,width,height);
}
public void drawPolygon(int x[], int y[], int n)
{
int new_x[] = new int[n];
int new_y[] = new int[n];
for (int i = 0; i < n; i++)
{
new_x[i] = rotate_x(x[i], y[i]);
new_y[i] = rotate_y(x[i], y[i]);
}
g.drawPolygon(new_x, new_y, n);
}
public void fillPolygon(int x[], int y[], int n)
{
int new_x[] = new int[n];
int new_y[] = new int[n];
for (int i = 0; i < n; i++)
{
new_x[i] = rotate_x(x[i], y[i]);
new_y[i] = rotate_y(x[i], y[i]);
}
g.fillPolygon(new_x, new_y, n);
}
public void drawImage(Image img,int x, int y,ImageObserver observer)
{
g.drawImage(img,x,y,observer);
}
}
public class Clock extends Applet implements Runnable
{
private Date date;
private int iHour,iMinute,iSecond;
private Thread thread = null;
private Image offI,backG;
private Graphics offG;
private int ixHour[]={4,4,0,-4,-4}
,iyHour[]={0,-30,-35,-30,0}
,ixMinute[]={3,3,0,-3,-3}
,iyMinute[]={0,-45,-50,-45,0};
public void init()
{
this.setLayout(null);
date = new Date();
SimpleDateFormat df = new SimpleDateFormat("'现在时刻' hh:mm:ss");
String lasttime = df.format(date);
offI = createImage(300,300);
offG = offI.getGraphics();
backG = getImage(getCodeBase(),"Clock.jpg");
}
public void start()
{
if(thread == null)
{
thread = new Thread(this);
thread.start();
}
}
public void run()
{
RotateG g = new RotateG(offG);
while(true)
{
try
{
thread.sleep(1000);
date = new Date();
SimpleDateFormat df = new SimpleDateFormat("'现在时刻' hh:mm:ss");
String lasttime = df.format(date);
System.out.println(lasttime);
iSecond = date.getSeconds();
iMinute = date.getMinutes();
iHour = date.getHours();
offG.setColor(Color.white);
offG.fillRect(0,0,300,300);
g.setOrigin(0,0);
g.drawImage(backG,0,0,this);
g.setOrigin(107,107);
System.out.println(iHour);
g.setAngle(iHour*30+iMinute*0.5);
g.setColor(Color.green);
g.fillPolygon(ixHour,iyHour,5);
g.setAngle(iMinute*6);
g.setColor(Color.red);
g.fillPolygon(ixMinute,iyMinute,5);
g.setAngle(iSecond*6);
g.setColor(Color.blue);
g.drawLine(0,0,0,-65);
g.setColor(Color.black);
g.fillOval(102,102,10,10);
repaint();
}
catch(InterruptedException e){}
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(offI,0,0,this);
}
}
java-clock.rar_Java 小程序_clock_java clock
版权申诉
193 浏览量
2022-09-19
14:19:16
上传
评论
收藏 11KB RAR 举报
小贝德罗
- 粉丝: 68
- 资源: 1万+
最新资源
- 2022NOC软件创意编程赛项真题python小学高年级-决赛(有解析)
- mathml转换latex需要的xsl文件
- 2022NOC软件创意编程赛项真题图形化小学高年级-决赛赛(有解析)
- gbase驱动下载gbase-connector-java-8.3.81.53驱动下载
- 2022NOC软件创意编程赛项真题图形化小学低年级-决赛赛(有解析)
- InsightFace从青铜到王者,超大规模人脸识别的优雅解法
- python后端开发spider框架详解
- 基于 STM32 与 ESP8266 的智能家居系统源码.zip
- 毕业设计:基于SSM的mysql-个性化点餐配送系统(源码 + 数据库 + 说明文档)
- 基于matlab的鱼苗计数识别(GUI界面).zip代码57
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈