Ik heb een timer gemaakt in Java. Deze werkt prima onder 98 maar niet onder xp. Ik weet niet zeker of het aan de browser ligt. In de applet viewer doet hij het wel. Andere applets doen het wel, maar deze dus niet.
Zou iemand me kenne helpen. Ik ving ergens iets op dat xp heel precies kijkt op Threading. Ik heb al andere manieren geprobeerd, zonder succes
Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
| import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; import java.lang.Runnable; public class TimeThis extends Applet implements Runnable { private String getSeconds(int irem_time) { String sec = String.valueOf((int)(irem_time % 60)); return sec; } private String getMinutes(int irem_time) { String min = String.valueOf((int)(Math.floor((irem_time / 60) % 60))); return min; } private String getHours(int irem_time) { String hour = String.valueOf((int)(Math.floor(irem_time / 3600))); return hour; } private String addZero(String itime) { int length = itime.length(); if (length == 1) itime = "0" + itime; return itime; } private int getRem(int istart_time, int itotal_time) { int current_time = Math.round((int)System.currentTimeMillis()/1000); int rem_time = itotal_time - (current_time - istart_time); return rem_time; } private int getLines(int imax_time, int irem_time, int imax_lines) { int lines_done; if (irem_time > 0) { int time_done = imax_time - irem_time; double lines_per_sec = (float)(imax_lines) / (float)(imax_time); lines_done = (int)Math.round(lines_per_sec * time_done); } else { lines_done = imax_lines; } return lines_done; } private void drawTimer(Graphics ig, int imax_time, int irem_time, int ileft, int itop, int iwidth, int iheight) { int lines_done = getLines(imax_time, irem_time, iwidth - 2); ig.setColor(Color.blue); ig.fillRect(ileft + 1 , itop, lines_done, iheight); ig.setColor(Color.white); ig.drawRect(ileft , itop, iwidth - 1, iheight); } private void drawTime(Graphics ig, int irem_time, int ileft, int itop) { String sec = getSeconds(irem_time); String min = getMinutes(irem_time); String hour = getHours(irem_time); sec = addZero(sec); min = addZero(min); ig.setColor(Color.white); ig.drawString(hour + ":" + min + ":" + sec, ileft, itop); } private Thread timerThread = null; private int start_time = 0; private int max_time = 0; private int total_time = 0; private int rem_time = 0; public void start() { if (timerThread == null) { start_time = Math.round((int)System.currentTimeMillis()/1000); try { max_time = Integer.parseInt(getParameter("max_time")); total_time = Integer.parseInt(getParameter("rem_time")); } catch (NumberFormatException ne) { //Doesn't work } timerThread = new Thread(this, "TimeThis"); timerThread.start(); } } public void run() { Thread thisThread = Thread.currentThread(); rem_time = getRem(total_time, start_time); while (timerThread == thisThread && rem_time > 0) { repaint(); rem_time = getRem(total_time, start_time); try { Thread.sleep(1000); } catch (InterruptedException ie) { //No sleeping } } repaint(); } public void stop() { timerThread = null; } public void paint(Graphics g) { int width = 60; int height = 25; int distance = 5; width = (width < 50) ? 50 : width; distance = (distance < 0) ? 0 : distance; height = (height - 10 - distance < 5) ? 15 + distance : height; g.setColor(Color.black); g.fillRect(0, 0, width, height); int text_left = (width / 2) - 22; drawTimer(g, max_time, rem_time, 0, 0, width, height - 10 - distance); drawTime(g, rem_time, text_left, height); } } |
Zou iemand me kenne helpen. Ik ving ergens iets op dat xp heel precies kijkt op Threading. Ik heb al andere manieren geprobeerd, zonder succes
[ Voor 4% gewijzigd door Fles op 09-04-2003 22:31 ]