未分类题
请完成下面的程序:实现一个可以每秒跳动的时钟。运行如下图所示。请填写横线处的内容。
注意:请勿改动main主方法和其他已有语句内容,仅在下划线处填入适当的语句。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
.jpg)
import java.util.*;
public class Example2_12 extends JFrame (1) implements Runnable
{
Thread thread1;
Color handColor;
Color numberColor;
JLabel jlabell = new JLabel();
public Example2_12()
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
getContentPane().add(jlabell, BorderLayout. SOUTH);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
public static void main(String args[])
{
Example2 12_clock1 = new Example2_12();
clock1.init();
clock1.start();
clock1.setSize(260, 230);
clock1.setResizable(false);
clock1.show();
}
public void init()
{
int x, y;
handColor = Color.blue;
numberColor = Color.darkGray;
setBackground(Color.white);
}
public void paint (Graphics g)
{
int xh, yh, xm, ym, xs, ys, s = 0, m = 10, h = 10, xpoint, ypoint;
String today;
Calendar c1 = ______;
s = c1.get(Calendar.SECOND);
m = c1.get(Calendar.MINUTE);
h = c1.get(Calendar.HOUR);
int day, month, year, weekday;
day = c1.get(Calendar.DATE);
month = c1.get(Calendar.MONTH) + 1;
year = c1. get (Calendar. YEAR);
weekday = c1.get (Calendar. DAY_OF_WEEK);
jlabell.setText('Today is '+ year + '/' + month + '/' + day + '/ '+ 'Time:' + h + ':' + m + ':' + s);
xpoint = 130;
ypoint = 100;
xs =(int) (Math.cos(s * 3.14f / 30 - 3.14f / 2) * 45 + xpoint);
ys =(int) (Math.sin(s * 3.14f / 30 - 3.14f / 2) * 45 + ypoint);
xm =(int) (Math.cos (m * 3.14f / 30 - 3.14f / 2) * 40 + xpoint);
ym =(int) (Math.sin(m * 3.14f / 30 - 3.14f / 2) * 40 + ypoint);
xh =(int) (Math.cos( (h * 30 + m / 2) * 3.14f / 180 - 3.14f / 2) * 30 + xpoint);
yh =(int) (Math.sin( (h * 30 + m / 2) * 3.14f / 180 - 3.14f / 2) * 30 + ypoint);
g.setColor (handColor);
g.clearRect(0, 0, 260, 200);
g.drawOval(xpoint / 2 + 10, ypoint / 2 - 5, 110, 110);
g.setColor(numberColor);
g.drawString('9', xpoint - 45, ypoint + 3);
g.drawString('3', xpoint + 40, yp
A.swing.*;
B.awt.*;
C.awt.event.*;
D.shangxueba.cn/images/ct_ctjjm_simpapp_00014(20092).jpg'
E.util.*;
F.WINDOW_EVENT_MASK);
G.add(jlabell,
H.out.println(e.getMessage());
I.init();
J.start();
K.setSize(260,
L.setResizable(false);
M.show();
N.blue;
O.darkGray;
P.white);
Q.get(Calendar.SECOND);
R.get(Calendar.MINUTE);
S.get(Calendar.HOUR);
T.get(Calendar.DATE);
U.get(Calendar.MONTH)
V.get
W.setText('Today
X.cos(s
Y.14f
Z.14f
[.sin(s
.14f
].14f
^.cos
_.14f
`.14f
a.sin(m
b.14f
c.14f
d.cos(
e.14f
f.14f
g.sin(
h.14f
i.14f
j.setColor
k.clearRect(0,
l.drawOval(xpoint
m.setColor(numberColor);
n.drawString('9',
o.drawString('3',
【参考答案】
①Calendar.getInstance()②start()
①Calendar.getInstance()②......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)