- 浏览: 337291 次
- 性别:
- 来自: 广州
-
文章分类
- 全部博客 (299)
- 私人 (3)
- linux (22)
- web service (1)
- java applet (1)
- java (41)
- c# (1)
- socket (1)
- android (10)
- htc (1)
- root (1)
- ftp (3)
- 系统备份 (0)
- jquery (3)
- 图表 (1)
- 实用 (4)
- web (9)
- css (3)
- java applet mplayer (1)
- mplayer (4)
- javascript (8)
- eclipse (1)
- 正则表达式 (1)
- jmf (1)
- tomcat (6)
- 驱动 (1)
- 嵌入式 (1)
- usb (3)
- ffmpeg (1)
- player (1)
- encode (1)
- ajax (1)
- 单纯形复法 (1)
- rom (1)
- ndk (1)
- 打印 (1)
- vs2010 (2)
- myeclipse注册机 (1)
- c++ (5)
- capture (0)
- 串口 (1)
- windows (2)
- mingw (1)
- 网卡 (1)
- 绿色版 (1)
- cywin (1)
- x264 (1)
- 恢复文件 (1)
- servlet init 连数据库 (1)
- 51 单片机 (1)
- 操作系统 (1)
- vlc (3)
- 网线 (1)
- CListBox (1)
- mfc (1)
- setTimer (1)
- 分屏 (1)
- 供求信息 (1)
- 导航 (1)
- 批处理 (1)
- dos (1)
- mysql (5)
- MySQL新建用户 (1)
- demo (1)
- vc (1)
- webservice (1)
- 书签 (1)
- 浏览器 (1)
- spring mvc (1)
- excel (1)
- VPN (0)
- sql (1)
- pdf (3)
- arp (1)
- jsp (2)
- IE (1)
- html (1)
- test (3)
- httpclient (1)
- spring mvc 上传 (1)
- easyui (1)
- mybatis (1)
- spring (1)
- 微信 (1)
- weixin (2)
- pay (2)
- maven (2)
- fastdfs (2)
- ELK (2)
- logstash (1)
- rocketMQ (0)
- jmeter (0)
- 测试 (0)
- softether (0)
- util (0)
最新评论
-
ice24:
ftp client applet -
wuzijingaip:
499700647 写道你好,看了您的文章《ftp clien ...
ftp client applet -
zxcv193188:
感谢楼主
java JMF的使用 -
499700647:
你好,看了您的文章《ftp client aplet》很受启发 ...
ftp client applet -
JoeBaby_:
非常感谢,看文档的时候觉得JMF好难的样子,但是看过代码后思路 ...
java JMF的使用
import java.awt.*; import javax.swing.*; import java.util.*; //定义测试类 //所有变量名冲突的变量名串1了,不过就效果不好~~ public class TimerTest { //定义主函数 public static void main(String[] args) { //定义JFrame类的一个对象,并创建该对象 MyTimer1 f = new MyTimer1(); //调用MyTimer的show()方法 f.show(); //---------------------------------------------------- //调用类的构造函数 MyTimer myTimer=new MyTimer(); //调用类的显示时间函数 myTimer.displayCurrentTime(); //调用类的设置时间函数 myTimer.setCurrentTime(); //调用类的显示时间函数 myTimer.displayCurrentTime(); //调用类的显示时间函数 myTimer.displayCurrentTime(); System.exit(0); } } //定义MyTimer类 class MyTimer1 extends JFrame { static int count=0; //判断是否重定义了时间 //构造函数 public MyTimer1() { //定义窗口大小 setSize(320, 200); //定义窗口标题 setTitle("测试自定义时钟类!"); Container c = getContentPane(); // new ClockCanvas("北京时间", "GMT+8") c.add(new ClockCanvas("北京时间", "GMT+8")); } } //定义接口 interface TimerListener1 { void timeElapsed(Timer1 t); } class Timer1 extends Thread //类Timer1 { private TimerListener1 target; private int interval; public Timer1(int i, TimerListener1 t) { target = t; interval = i; setDaemon(true); } public void run() { try { while (!interrupted()) { sleep(interval); target.timeElapsed(this); } } catch(InterruptedException e) {} } } class ClockCanvas extends JPanel //clockcanvas implements TimerListener1 { static int seconds = 0; private String city; private GregorianCalendar calendar; //构造函数 public ClockCanvas(String c, String tz) { city = c; calendar = new GregorianCalendar(TimeZone.getTimeZone(tz)); Timer1 t = new Timer1(1000, this); t.start(); setSize(180, 180); } //绘制钟面 public void paintComponent(Graphics g) { super.paintComponent(g); g.drawOval(100, 5, 120, 120); g.drawOval(101, 6, 118, 118); //分离时间 double hourAngle = 2 * Math.PI * (seconds - 3 * 60 * 60) / (12 * 60 * 60); double minuteAngle = 2 * Math.PI * (seconds - 15 * 60) / (60 * 60); double secondAngle = 2 * Math.PI * (seconds - 15) / 60; g.drawLine(160, 64, 160 + (int)(20* Math.cos(hourAngle)), 64 + (int)(30 * Math.sin(hourAngle))); g.drawLine(160, 65, 160 + (int)(20* Math.cos(hourAngle)), 65 + (int)(30 * Math.sin(hourAngle))); g.drawLine(160, 66, 160 + (int)(20* Math.cos(hourAngle)), 66 + (int)(30 * Math.sin(hourAngle))); g.drawLine(160, 63, 160 + (int)(20* Math.cos(hourAngle)), 63 + (int)(30 * Math.sin(hourAngle))); g.drawLine(160, 67, 160 + (int)(20* Math.cos(hourAngle)), 67 + (int)(30 * Math.sin(hourAngle))); g.drawLine(160, 65, 160 + (int)(32* Math.cos(minuteAngle)), 65 + (int)(40 * Math.sin(minuteAngle))); g.drawLine(160, 64, 160 + (int)(32* Math.cos(minuteAngle)), 64 + (int)(40 * Math.sin(minuteAngle))); g.drawLine(160, 65, 160 + (int)(55* Math.cos(secondAngle)), 65 + (int)(45 * Math.sin(secondAngle))); g.drawString(city, 130, 150);//*/ } public void timeElapsed(Timer1 t) { calendar.setTime(new Date()); if(MyTimer1.count==1) {int a=1; seconds=MyTimer.intHour*60*60+MyTimer.intMinute*60+MyTimer.intSecond; seconds+=a;//a为秒自加 repaint();} else { seconds = calendar.get(Calendar.HOUR) * 60 * 60 + calendar.get(Calendar.MINUTE) * 60 + calendar.get(Calendar.SECOND); repaint();} } } //定义时钟类 class MyTimer implements TimerListener { //定义时钟类的属性 static int intHour,intMinute,intSecond; //构造函数 public MyTimer() { setCurrentTimeAsSystemTime(); Timer t = new Timer(1000, this); //实例Timer类,里面有run方法 t.start(); } //显示当前时间 public void displayCurrentTime() { JOptionPane.showMessageDialog(null,intHour+":"+intMinute+":"+intSecond); } //设定当前时间 public void setCurrentTime() { //从对话框输入时,分秒 String strTemp=JOptionPane.showInputDialog(null,"请输入当前小时(24小时制):"); int iHour=Integer.parseInt(strTemp); strTemp=JOptionPane.showInputDialog(null,"请输入当前分:"); int iMinute=Integer.parseInt(strTemp); strTemp=JOptionPane.showInputDialog(null,"请输入当前秒:"); int iSecond=Integer.parseInt(strTemp); //设定当前时间为对话框输入的时间 if(iHour>=0&&iHour<24) intHour=iHour; else intHour=0; if(iMinute>=0&&iMinute<60) intMinute=iMinute; else intMinute=0; if(iSecond>=0&&iSecond<60) intSecond=iSecond; MyTimer1.count++; // ClockCanvas.seconds=iHour*60*60+iMinute*60+iSecond; } //设定当前时间为系统时间,构造函数调用 public void setCurrentTimeAsSystemTime() { //定义Date类的一个对象,用来获取系统时间 Date timeCurrent=new Date(); //将系统的时,分秒设定为当前时间 intHour=timeCurrent.getHours(); intMinute=timeCurrent.getMinutes(); intSecond=timeCurrent.getSeconds(); } //走时 public void timeElapsed(Timer t) { //系统走时 intSecond++; if (intSecond==60) { intMinute++; intSecond=0; } if (intMinute==60) { intHour++; intMinute=0; } if (intHour==24) { intHour=0; } } } interface TimerListener //接口 { void timeElapsed(Timer t); } class Timer extends Thread //类 { private TimerListener target; private int interval; public Timer(int i, TimerListener t) { target = t; interval = i; setDaemon(true); //Thread 里面方法 目的跟着老大走 } public void run() { try { while (!interrupted()) { sleep(interval); target.timeElapsed(this); } } catch(InterruptedException e) {} } }
第二个.
import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Calendar; import java.util.GregorianCalendar; import javax.swing.JFrame; public class Clock extends JFrame implements ActionListener { int x, y, x0, y0, r, h, olds_x, olds_y, oldm_x, oldm_y, oldh_x, oldh_y, ss, mm, hh, old_m, old_h, ang; final double RAD = Math.PI / 180; // 度数转换成弧度的比例 // 构造函数创建了一个窗体 public Clock() { super("Java时钟"); setDefaultCloseOperation(3); Image image = getToolkit().getImage("clock.gif"); setIconImage(image); getContentPane().setBackground(Color.black); setDefaultCloseOperation(3); setSize(200, 200); // 容器大小,运行时窗口的大小 setLocation(300, 150); setResizable(false); setVisible(true); int delay = 1000; // 创建一个监听事件 ActionListener drawClock = new ActionListener() { public void actionPerformed(ActionEvent evt) { repaint(); } }; // 创建一个时间计数器,每一秒触发一次 // new Timer(delay, drawClock).start(); } // 实现ActionListener接口必须实现的方法 public void actionPerformed(ActionEvent e) { } // 绘制图形 public void paint(Graphics g) { super.paint(g); // 新加这句话,背景随时变。。。。。。。。。。。。。。。。。。。。 Graphics2D g2 = (Graphics2D) g; Insets insets = getInsets(); int L = insets.left / 2, T = insets.top / 2; h = getSize().height; g.setColor(Color.white); // 圆圈和字的颜色....................................... // 画圆 g2.setStroke(new BasicStroke(4.0f)); g.drawOval(L + 40, T + 40, h - 80, h - 80); r = h / 2 - 40; x0 = 40 + r - 5 + L; y0 = 40 + r - 5 - T; ang = 60; // 绘制时钟上的12 个字 for (int i = 1; i <= 12; i++) { x = (int) ((r + 10) * Math.cos(RAD * ang) + x0); y = (int) ((r + 10) * Math.sin(RAD * ang) + y0); g.drawString(" " + i, x, h - y); ang -= 30; } // 获得现在的时间 Calendar now = new GregorianCalendar(); int nowh = now.get(Calendar.HOUR_OF_DAY); int nowm = now.get(Calendar.MINUTE); int nows = now.get(Calendar.SECOND); String st; if (nowh < 10) st = "0" + nowh; else st = " " + nowh; if (nowm < 10) st += ":0" + nowm; else st += ":" + nowm; if (nows < 10) st += ":0" + nows; else st += ":" + nows; // 在窗体上显示时间 g.setColor(Color.magenta); g.fillRect(L, T, 57, 28); g.setColor(Color.blue); g.drawString(st, L + 2, T + 26); // 计算时间与度数的关系 ss = 90 - nows * 6; mm = 90 - nowm * 6; hh = 90 - nowh * 30 - nowm / 2; x0 = r + 40 + L; y0 = r + 40 + T; g2.setStroke(new BasicStroke(1.2f)); // 擦除秒针/////////////////////////////////////////////////////////////////////擦除是不必要的,后边也是 // if(olds_x>0){ // g.setColor(getBackground()); // g.drawLine(x0,y0,olds_x,h-olds_y); // } // else{ old_m = mm; old_h = hh; // } // 绘制秒针 x = (int) (r * 0.9 * Math.cos(RAD * ss)) + x0; y = (int) (r * 0.9 * Math.sin(RAD * ss)) + y0 - 2 * T; g.setColor(Color.yellow); g.drawLine(x0, y0, x, h - y); olds_x = x; olds_y = y; g2.setStroke(new BasicStroke(2.2f)); // 擦除分针 // if(old_m!=mm){ // g.setColor(getBackground()); // g.drawLine(x0,y0,oldm_x,h-oldm_y); // } // 绘制分针 x = (int) (r * 0.7 * Math.cos(RAD * mm)) + x0; y = (int) (r * 0.7 * Math.sin(RAD * mm)) + y0 - 2 * T; g.setColor(Color.green); g.drawLine(x0, y0, x, h - y); oldm_x = x; oldm_y = y; old_m = mm; g2.setStroke(new BasicStroke(3.4f)); // 擦除时针 // if(old_h!=hh){ // g.setColor(getBackground()); // g.drawLine(x0,y0,oldh_x,h-oldh_y); // } // 绘制时针 x = (int) (r * 0.5 * Math.cos(RAD * hh)) + x0; y = (int) (r * 0.5 * Math.sin(RAD * hh)) + y0 - 2 * T; g.setColor(Color.red); g.drawLine(x0, y0, x, h - y); oldh_x = x; oldh_y = y; old_h = hh; } public static void main(String[] args) { Clock clock = new Clock(); } }
相关推荐
这个"Java圆形时钟,钟表源码"项目是一个很好的学习平台,可以帮助初学者深入理解Java时间处理、图形用户界面(GUI)设计以及事件处理等方面的知识。 首先,我们来探讨Java时间相关操作。在Java中,处理时间主要...
这个“Java圆形电子时钟源代码”项目提供了一个实例,展示了如何利用Java来创建一个实时更新时间的动态圆形时钟。 1. **Java GUI基础**: - 该项目可能使用了Java的Swing或JavaFX库来构建图形界面。Swing是Java的...
java圆形时钟代码
Java圆形电子时钟源代码是基于Java编程语言实现的一个实用示例,它展示了如何利用Java图形用户界面(GUI)库来创建一个动态显示时间的圆形时钟。这个项目对于学习Java GUI编程、事件处理和时间管理等核心概念非常有...
使用Java的`Graphics`类,开发者可以进行基本的图形绘制,如线条、圆形、矩形等。在这个时钟程序中,开发者可能通过`Graphics`类的`drawLine()`方法来绘制时钟的时针、分针和秒针。 4. **双缓冲技术**: 双缓冲是...
java 语言描述的时钟算法 比较简单 希望能对大家有些帮助
使用Java的Graphics2D API,可以实现复杂的图形绘制,包括时钟的圆形背景、刻度、指针等。Graphics2D允许精确控制线条、颜色和形状,以模拟真实的时钟界面。 5. **类的继承**: 报告中提到的`TestClock`类继承自`...
Java圆形电子时钟源代码.zip
我们使用Graphics类来绘制时钟的圆形和指针,使用Font类来设置时钟的文字样式。 Java面向对象编程 Java面向对象编程(OOP)是一种编程范式,强调使用对象和类来组织代码。Java语言是完全面向对象的语言,所有的...
在Java编程语言中,创建一个图形时钟是一个常见的学习任务,它可以帮助开发者了解图形用户界面(GUI)设计、事件处理以及时间管理等概念。在这个项目中,“java图形时钟[源码][附图]”提供了实现一个动态显示当前...
在本压缩包“Java圆形电子时钟源代码.zip”中,包含的是一个使用Java编程语言实现的圆形电子时钟程序的源代码。这个程序可能是基于Java Swing或JavaFX图形用户界面库来创建的,用于在屏幕上展示一个动态更新的圆形...
java写的一个简单GUI时钟程序,核心算法为等分圆画点,线程中画线走时。 绝对原创
时钟的显示方式是表盘形式,这通常会涉及到绘制圆形、线条以及角度计算。在Java中,可以使用`Graphics2D`类来进行绘制,该类允许开发者精确地控制线条、形状和颜色。为了绘制时钟的指针,开发者需要了解如何用直线或...
3. **Java 绘图**: 要创建圆形时钟,开发者可能使用了 `java.awt.Graphics2D` 类,它提供了丰富的绘图功能,包括画线、填充形状等。时钟的指针和数字可能都是通过这个类的方法绘制的。 4. **坐标系统和几何形状**: ...
在Java编程语言中,动态时钟效果的实现主要依赖于`javax.swing.Timer`类和图形用户界面(GUI)组件。`javax.swing.Timer`是Java Swing库中的一个关键类,用于在指定的时间间隔内触发事件。它非常适合创建动画效果,...
Java动态时钟是一种常见的编程练习,它通过使用Java Swing库来创建一个实时更新时间的可视化时钟。在本文中,我们将深入探讨如何使用Java Swing入门,以及如何利用Java的绘图功能来实现一个动态时钟。 Java Swing是...
4. 使用2D图形API绘制钟面,包括圆形背景,时钟的数字标记(12个汉字),以及表示小时、分钟和秒的指针。这里可能需要运用到`Graphics2D`类的旋转、移动和线条绘制方法。 5. 设计指针的动态更新逻辑,根据时间变化...
在Swing中,你可以利用`Graphics2D`来绘制圆形的时钟盘和指针。在JavaFX中,可以利用`RotateTransition`来创建旋转动画。 总结来说,创建Java模拟时钟和数字时钟涉及的知识点包括:多线程实现(`Thread`或`Runnable...
- 使用`Graphics`对象绘制时钟界面,包括圆形边框、数字标记以及指针等。 ```java xs = (int) (45 * Math.cos(s * Math.PI / 30 - Math.PI / 2) + cx); ys = (int) (45 * Math.sin(s * Math.PI / 30 - Math.PI ...
这个项目展示了如何利用Java的图形用户界面(GUI)库,如JavaFX或Swing,来创建一个实时更新的、视觉上吸引人的圆形时钟。下面我们将详细探讨相关的Java知识点和技术。 1. **JavaFX或Swing**: JavaFX和Swing是Java...