JAVA的一个题,由于本人没学JAVA,所以,请大侠帮个忙,高分! 楼主头像很不错啊给景甜顶一个SWING包是画界面用的很多画的方法你自己看看吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个程序就是 java面向对象设计 多线程的例子吧课程设计的时候,老师让写一个多线程例子,N多学生全用的这个一个个全是表盘。。 这个程序就是 java面向对象设计 多线程的例子吧课程设计的时候,老师让写一个多线程例子,N多学生全用的这个一个个全是表盘。。 看看是不是你要的我在csdn中拷贝的,谢谢原著的代码:import java.awt.Color;import java.awt.Graphics;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.Calendar;import java.util.GregorianCalendar;import javax.swing.JFrame;import javax.swing.JPanel;/** * 时间类 * @author xiaohei * */public class Clock extends JFrame { /** * */ private static final long serialVersionUID = 1L; public Clock() { ClockPaint cp = new ClockPaint(20, 20, 70); this.getContentPane().add(cp); this.setSize(200, 200); this.setResizable(false); this.setLocation(260, 120); this.setTitle("小时钟"); this.setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } public static void main(String[] s) { new Clock(); }}class ClockPaint extends JPanel implements Runnable { /** * */ private static final long serialVersionUID = 1L; int x, y, r; int h, m, s;// 小时,分钟,秒 double rad = Math.PI / 180; public ClockPaint(int x, int y, int r) { this.x = x; this.y = y; this.r = r; Calendar now = new GregorianCalendar(); s = now.get(Calendar.SECOND) * 6;// 获得秒转换成度数 m = now.get(Calendar.MINUTE) * 6;// 获得分钟 h = (now.get(Calendar.HOUR_OF_DAY) - 12) * 30 + now.get(Calendar.MINUTE) / 12 * 6;// 获得小时 Thread t = new Thread(this); t.start(); } public void paint(Graphics g) { // 清屏 super.paint(g); g.setColor(Color.BLACK); g.fillRect(0, 0, r * 3, r * 3); // 画圆 g.setColor(Color.WHITE); g.drawOval(x, y, r * 2, r * 2); // 秒针 g.setColor(Color.RED); int x1 = (int) ((r - 10) * Math.sin(rad * s)); int y1 = (int) ((r - 10) * Math.cos(rad * s)); g.drawLine(x + r, y + r, x + r + x1, y + r - y1); // 分针 g.setColor(Color.BLUE); x1 = (int) ((r - r / 2.5) * Math.sin(rad * m)); y1 = (int) ((r - r / 2.5) * Math.cos(rad * m)); g.drawLine(x + r, y + r, x + r + x1, y + r - y1); // 时针 g.setColor(Color.CYAN); x1 = (int) ((r - r / 1.5) * Math.sin(rad * h)); y1 = (int) ((r - r / 1.5) * Math.cos(rad * h)); g.drawLine(x + r, y + r, x + r + x1, y + r - y1); // 数字 g.setColor(Color.YELLOW); int d = 29; for (int i = 1; i <= 12; i++) { x1 = (int) ((r - 10) * Math.sin(rad * d)); y1 = (int) ((r - 10) * Math.cos(rad * d)); g.drawString(i + "", x + r + x1 - 4, x + r - y1 + 5); d += 30; } // 小点 d = 0; for (int i = 0; i < 60; i++) { x1 = (int) ((r - 2) * Math.sin(rad * d)); y1 = (int) ((r - 2) * Math.cos(rad * d)); g.drawString(".", x + r + x1 - 1, x + r - y1 + 1); d += 6; } // 显示时间 Calendar now1 = new GregorianCalendar(); g.drawString(now1.get(Calendar.HOUR_OF_DAY) + ":" + now1.get(Calendar.MINUTE) + ":" + now1.get(Calendar.SECOND), 0, 10); } public void run() { while (true) { try { Thread.sleep(1000); } catch (Exception ex) { } s += 6; if (s >= 360) { s = 0; m += 6; if (m == 72 || m == 144 || m == 216 || m == 288) { h += 6; } if (m >= 360) { m = 0; h += 6; } if (h >= 360) { h = 0; } } this.repaint(); } }} web应用中 内存没有被回收,why??? 网页靠什么来统计访问量? 新人请教个EJB3数据库更新的问题 JBuilder2005中配置struts自带连接池的问题 帮我看看这段代码?????? 怎样将字符串中的字符转化为HTML所认识的字符 各位的公司都用什么工具开发Struts或WebWork应用?? JAVA POI导出word文件乱码??? SpringBoot 怎么再拦截器里面注入Service 这个怎么改啊! hibernate关联查询异常 求几本关于J2EE性能方面的书,谢谢
一个个全是表盘。。
一个个全是表盘。。
我在csdn中拷贝的,谢谢原著的代码:import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JFrame;
import javax.swing.JPanel;/**
* 时间类
* @author xiaohei
*
*/
public class Clock extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L; public Clock() {
ClockPaint cp = new ClockPaint(20, 20, 70); this.getContentPane().add(cp);
this.setSize(200, 200);
this.setResizable(false);
this.setLocation(260, 120);
this.setTitle("小时钟");
this.setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} public static void main(String[] s) {
new Clock();
}
}class ClockPaint extends JPanel implements Runnable {
/**
*
*/
private static final long serialVersionUID = 1L;
int x, y, r;
int h, m, s;// 小时,分钟,秒
double rad = Math.PI / 180; public ClockPaint(int x, int y, int r) {
this.x = x;
this.y = y;
this.r = r;
Calendar now = new GregorianCalendar();
s = now.get(Calendar.SECOND) * 6;// 获得秒转换成度数
m = now.get(Calendar.MINUTE) * 6;// 获得分钟
h = (now.get(Calendar.HOUR_OF_DAY) - 12) * 30
+ now.get(Calendar.MINUTE) / 12 * 6;// 获得小时 Thread t = new Thread(this);
t.start();
} public void paint(Graphics g) {
// 清屏
super.paint(g);
g.setColor(Color.BLACK);
g.fillRect(0, 0, r * 3, r * 3);
// 画圆
g.setColor(Color.WHITE);
g.drawOval(x, y, r * 2, r * 2);
// 秒针
g.setColor(Color.RED);
int x1 = (int) ((r - 10) * Math.sin(rad * s));
int y1 = (int) ((r - 10) * Math.cos(rad * s));
g.drawLine(x + r, y + r, x + r + x1, y + r - y1);
// 分针
g.setColor(Color.BLUE);
x1 = (int) ((r - r / 2.5) * Math.sin(rad * m));
y1 = (int) ((r - r / 2.5) * Math.cos(rad * m));
g.drawLine(x + r, y + r, x + r + x1, y + r - y1);
// 时针
g.setColor(Color.CYAN);
x1 = (int) ((r - r / 1.5) * Math.sin(rad * h));
y1 = (int) ((r - r / 1.5) * Math.cos(rad * h));
g.drawLine(x + r, y + r, x + r + x1, y + r - y1);
// 数字
g.setColor(Color.YELLOW);
int d = 29;
for (int i = 1; i <= 12; i++) {
x1 = (int) ((r - 10) * Math.sin(rad * d));
y1 = (int) ((r - 10) * Math.cos(rad * d));
g.drawString(i + "", x + r + x1 - 4, x + r - y1 + 5);
d += 30;
}
// 小点
d = 0;
for (int i = 0; i < 60; i++) {
x1 = (int) ((r - 2) * Math.sin(rad * d));
y1 = (int) ((r - 2) * Math.cos(rad * d));
g.drawString(".", x + r + x1 - 1, x + r - y1 + 1);
d += 6;
}
// 显示时间
Calendar now1 = new GregorianCalendar();
g.drawString(now1.get(Calendar.HOUR_OF_DAY) + ":"
+ now1.get(Calendar.MINUTE) + ":" + now1.get(Calendar.SECOND),
0, 10); } public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (Exception ex) {
}
s += 6;
if (s >= 360) {
s = 0;
m += 6;
if (m == 72 || m == 144 || m == 216 || m == 288) {
h += 6;
}
if (m >= 360) {
m = 0;
h += 6;
}
if (h >= 360) {
h = 0;
}
}
this.repaint();
}
}
}