有一个缓冲池,大小一定
一个线程读,一个线程写.
一个线程读,一个线程写.
解决方案 »
- 求教给位关于一个数组的问题
- 跪求 本科“超市管理系统的”毕业设计源代码……
- 一个JAVA基础的问题,我是初学者,不懂啊
- 开始玩blog了,大家看看啊,up有分
- 明天要去易达文科技面试,有谁知道该公司的情况请提供信息,来者有分!
- 如果用java编写计算程序,大家提提意见
- 急,怎么在JApplet 中打开一个网页?
- ¥¥¥¥¥¥¥¥¥¥ 我急啊 大家来帮我看看 ¥¥¥¥¥¥¥¥¥¥
- 哪里有WEBSPHERE的相关资料,我急需要!!谢谢大家,如果有文档,我的地址是[email protected]
- 为什么我的线程被修改了名字?
- 开始学习Java应该从什么开始啊?
- 有谁用过JDEVELOPER,感觉怎么样?有没有什么更好的JAVA开发工具?
import java.awt.Color;
import java.applet.Applet;
import java.text.*;
import java.util.*;public class ClockDemo extends Applet implements Runnable {
SimpleDateFormat formatter; // ノㄓ陪ボ丁妓Α
Date currentDate; // 瞷丁
Thread clockThread = null;
boolean keepRunning = true;
public void init() {
int x,y;
formatter = new SimpleDateFormat ("EEE MMM dd hh:mm:ss yyyy", Locale.getDefault());
currentDate = new Date();
}
public void start() {
if(clockThread == null) {
clockThread = new Thread(this);
clockThread.start();
}
}
public void run() {
while(keepRunning) {
repaint();
try { Thread.sleep(1000); }
catch(InterruptedException e) {}
}
}
// ノよ猭stopㄓ璶―磅︽氨ゎ磅︽
public void pleaseStop() { keepRunning = false; }
public void paint(Graphics g) {
int s, m, h;
String today; currentDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("s",Locale.getDefault());
try {
s = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
s = 0;
}
formatter.applyPattern("m");
try {
m = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
m = 0;
}
formatter.applyPattern("h");
try {
h = Integer.parseInt(formatter.format(currentDate));
} catch (NumberFormatException n) {
h = 0;
} formatter.applyPattern("EEE MMM dd HH:mm:ss yyyy");
today = formatter.format(currentDate); Clock myClock = new Clock(h, m, s);
g.drawString(today, 0, 160);
myClock.show(g, 70, 70, 70);
}
}class Clock {
Clock(int hrs, int min, int sec) {
hour = hrs % 12;
minute = min;
second = sec;
} void show(Graphics g, int center_x, int center_y, int radius) {
int hrs_nid_len = (int)(radius * 0.5), // ﹚皐
min_nid_len = (int)(radius * 0.7), // ﹚だ皐
sec_nid_len = (int)(radius * 0.85); // ﹚皐
double theta; // 礶牧
g.drawOval(center_x - radius, center_y - radius,
radius * 2, radius * 2);
g.drawString("9",0,center_y);
g.drawString("3",center_x*2-10,center_y);
g.drawString("12",center_x,10);
g.drawString("6",center_x,center_y*2);
// 礶皐
theta = (double)(hour * 60 * 60 + minute * 60 + second) /
43200.0 * 2.0 * Math.PI;
drawNiddle(g, Color.blue, center_x, center_y, hrs_nid_len, theta); // 礶だ皐
theta = (double)(minute * 60 + second) /
3600.0 * 2.0 * Math.PI;
drawNiddle(g, Color.blue, center_x, center_y, min_nid_len, theta); // 礶皐
theta = (double)second / 60.0 * 2.0 * Math.PI;
drawNiddle(g, Color.red, center_x, center_y, sec_nid_len, theta);
} private void drawNiddle(Graphics g, Color c, int x, int y,
int len, double theta) {
g.setColor(c);
g.drawLine(x, y, (int)(x + len * Math.sin(theta)),
(int)(y - len * Math.cos(theta)));
} int hour, minute, second;
}