资源简介
这是一个完整的纯java编写的模拟windows时钟日历的程序,将程序下载下来,打开Eclipse或者能编译java的工具,新建一个java文件,然后通过记事本打开程序,将程序复制到你的新建的java文件中,这里要注意一点,需要将里面的package 后面指向你的报名,否则将报错。
代码片段和文件信息
package JavaTestFortheen;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.*;
import java.awt.GridLayout;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.text.SimpleDateFormat;
import javax.swing.JComboBox;
import javax.swing.Jframe;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.border.titledBorder;
public class ClockCalender extends Jframe{
public ClockCalender(){
Draw_Clock clock = new Draw_Clock();
Calender cal = new Calender();
@SuppressWarnings(“unused“)
JPanel jp2 = new JPanel();
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setSize(560320);
this.setLocationRelativeTo(null);
setVisible(true);
this.setContentPane(clock);
this.getContentPane().add(cal BorderLayout.EAST);
this.setResizable(false);
}
public static void main(String args[]){
new ClockCalender();
}
//钟表设计
public class Clock_Design extends JPanel implements Runnable{
Thread thread;//一个新的线程
//启动时钟
public void start(){
thread = new Thread(this);
thread.start();
}
//停止时钟
public void stop(){
thread = null;
}
private double CenterXCenterY;
private double Radius = 100;
private double HPointXHPointYMPointXMPointYSPointXSPointY;
private int Year MonthDayHourMinuteSecond;
private String WeekDay;
private final double PI = 3.1415926;
public synchronized void paintComponent(Graphics g)
{
//钟表的原点
super.paintComponent(g);
CenterX = this.getWidth()/2;
CenterY = this.getHeight()/2;
//设置钟表的颜色背景字体
g.setColor(Color.DARK_GRAY);
g.setFont(new Font(“微软雅黑“Font.BOLD14));
g.setColor(Color.orange);
g.fillOval((int)(CenterX-Radius) (int)(CenterY-Radius) (int)(2*Radius)(int)(2*Radius));
g.setColor(Color.blue); //设置表盘颜色
g.fillOval((int)(CenterX-20)(int)(CenterY-20)4040); //画表盘
g.setColor(Color.BLACK);//设置字体以及颜色
double HRadian=(PI/6)*Hour+(PI/360)*Minute+(PI/21600)*Second;
double MRadian=(PI/30)*Minute+(PI/1800)*Second;
double SRadian=(PI/30)*Second;
HPointX=CenterX+Radius*0.6*Math.sin(HRadian);
HPointY=CenterY-Radius*0.6*Math.cos(HRadian);
MPointX=CenterX+Radius*0.8*Math.sin(MRadian);
MPointY=CenterY-Radius*0.8*Math.cos(MRadian);
SPointX=CenterX+Radius*Math.sin(SRadian);
SPointY=CenterY-Radius*Math.cos(SRadian);
//钟表的外面的圈
g.drawOval((int)(CenterX-Radius) (int)(CenterY-Radius) (int)(2*Radius)(int)(2*Radius));//椭圆
//钟表的刻度
g.drawString(“12“(int)(CenterX-10)(int)(CenterY-Radius)+10);//字符串
g.drawString(“1“(int)(CenterX + Radius/2)-6(int)(CenterY - (Math.sqrt(3)/2)*Radius)+10);//字符串
g.drawString(“2“(int)(CenterX
- 上一篇:人工智能 动物产生式系统 java
- 下一篇:java web实验报告
评论
共有 条评论