首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请完成下面的程序:实现一个可以每秒跳动的时钟。运行如下图所示。请填写横线处的内容。 注意:请勿改动main主方法和其他已有语句内容,仅在下划线处填入适当的语句。 import javax.swing.*; import java.awt.
请完成下面的程序:实现一个可以每秒跳动的时钟。运行如下图所示。请填写横线处的内容。 注意:请勿改动main主方法和其他已有语句内容,仅在下划线处填入适当的语句。 import javax.swing.*; import java.awt.
admin
2009-01-15
80
问题
请完成下面的程序:实现一个可以每秒跳动的时钟。运行如下图所示。请填写横线处的内容。
注意:请勿改动main主方法和其他已有语句内容,仅在下划线处填入适当的语句。
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
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, ypoint + 3);
g.drawString("12", xpoint - 5, ypoint - 37);
g.drawString("6", xpoint - 3, ypoint + 45);
g.setColor(getBackground ( ) );
g.setColor(numberColor);
g.drawString(" ", 5, 125);
g.drawLine(xpoint, ypoint, xs, ys);
g.setColor(handColor);
g.drawLine(xpoint, ypoint, xm, ym);
g.drawLine(xpoint, ypoint, xh, xh);
}
public void start()
{
thread1 = new Thread(this);
thread1. ______;
}
public void stop ()
{
thread1=null;
}
public void update (Graphics g)
{
paint (g);
}
public void run ()
{
Thread me = Thread. currentThread ();
while (thread1 == me)
{
try
{
Thread. currentThread ( ) . sleep ( 100 );
}
catch (InterruptedException e)
{
e.printStackTrace();
}
repaint ( );
}
}
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING)
System.exit(0);
}
}
选项
答案
①Calendar.getInstance() ②start()
解析
本题主要考查线程和日历类的知识。在图形程序处理中,经常会用到多线程。使用多线程的类必须实现Runnable,接口,Thread类已经实现了Runnable接口,其子类自动实现了此类。要开始一个线程,应调用该类的start方法(第2个空)。这时Java会自动开始在该线程中调用该类的run方法。另外,在Java中,有的类只能有一个实例,不能创建它的多个实例对象。这在设计模式中叫做Singleton(单例)模式。Calendar类就是这样的类,它只能通过 getInstance方法得到这个实例对象(第1个空)。
转载请注明原文地址:https://kaotiyun.com/show/Z1np777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
为“歌手”表增加一个字段“最后得分”的SQL语句是
在VisualFoxPro中,下列关于SQL表定义语句(CREATETABLE)的说法中错误的是
以下描述中错误的是
用树形结构表示实体之间联系的模型是
下列程序段执行以后,内存变量y的值是x=34567y=0DOWHILEx>0y=x%10+y*10x=int(x/10)ENDDO
下列选项中不属于软件生命周期开发阶段任务的是
使用如下3个数据库表:职员.dbf:职员号C(3),姓名C(6),性别C(2),组号N(1),职务C(10)客户.dbf:客户号C(4),客户名C(36),地址C(36),所在城市C(36)订单.dbf:订单号C(4),客户名C(4),职员号C(
负责数据库中查询操作的数据库语言是
表单名为myForm的表单中有_个页框myPageFrame。将该页框的第3页(Page3)的标题设置为“修改”,可以使用代码
URL是【】的缩写。
随机试题
控制储量是编制油田开发方案、进行油田开发建设投资决策和油田开发分析的依据。()
Debateisavaluablewaytopractisecommunicating.Itcanalsobringlong-lastingrewards,especiallyforpeopleworkingwithW
彭女士,39岁,在局麻下行手部脓肿切开引流术,用普鲁卡因局部麻醉后不久出现面色潮红,恶心,视物模糊,血压上升和烦躁不安等表现首先应考虑其出现了()
PowerPoint2003中的空演示文稿模板是不允许用户修改的。()
某化学老师在一次化学实验中设计了下列试题,并对部分学生的解题结果进行了统计和分析。【试题】美国普度大学研究开发出一种利用铝镓合金制备氢气的新工艺(流程如图3所示)。下列有关该工艺的说法错误的是A.这个过程中,能量的转化形式只有两种B.铝镓合金可
制定课程目标的直接依据应来自教育目的和培养目标,但()不是教育目的和培养目标的简单推演。
甲、乙两人承包一项工程,共得报酬610元。已知甲做10天,乙做13天,但因甲的技术比乙的技术好,预先就约定甲做4天的工资比乙做5天的工资还要多40元,甲、乙两人各分得多少元?
Maryalwaysgotuptoolate,andnever______enoughtimeforbreakfast.
A、 B、 C、 C
PresidentBarackObama’spicktoheadtheEnvironmentalProtectionAgency(EPA),LisaJackson,hasspent20yearsasanenvironme
最新回复
(
0
)