首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请完成下列Java程序:创建一个进度条,可以控制其开始和暂停。要求进度条与线程关联,由线程控制,点击开始按钮开始进度条的滚动,点击停止按钮,暂停,继续点击开始按钮则继续进行。 注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当
请完成下列Java程序:创建一个进度条,可以控制其开始和暂停。要求进度条与线程关联,由线程控制,点击开始按钮开始进度条的滚动,点击停止按钮,暂停,继续点击开始按钮则继续进行。 注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当
admin
2009-01-15
73
问题
请完成下列Java程序:创建一个进度条,可以控制其开始和暂停。要求进度条与线程关联,由线程控制,点击开始按钮开始进度条的滚动,点击停止按钮,暂停,继续点击开始按钮则继续进行。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
public class ex15_2 extends JPanel {
ThreadProg thProgress;
JProgressBar jPb;//声明一个进程条对象
static JFrame jf;
public ex15_2(){
setLayout(new BorderLayout());
jPb=new JProgressBar();
add(jpb,"Center");
JPanel btnPanel=new JPanel();
JButton btnStart=new JButton("开始");
btnPanel.add(btnStart);
btnStart.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
__________;
}
});
JButton btnStop=new JButton("停止");
btnPanel.add(btnStop);
btnStop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
__________;
}
});
add(btnPanel,BorderLayout.SOUTH);
}
public void startProgress(){
if(thProgress==null||!thProgress.isAlive()){
thProgress=new ThreadProg(jpb);
thProgress.start();
}
}
public void stopProgress(){
thProgress.setStop(true);
}
pubUc static VOid main(String args[]){
jf=new JPrame("ex15_2");
ex15_2 obj15_2=new ex15_2();
jf.getContentPane().add("Center",obj15_2);
jf.setSize(250,80);
jf.addWindowListener(new WindowAdapter(){
pubhc void windowClosing(WindowEvent we){
System.exit(0);
}
});
jf.setVisible(true);
}
}
class ThreadProg extends Thread{
private JProgressBar jpb;
private boolean bStop=false;
private boolean bAlive=false;
pubhc ThreadProg(JProgressBar jpb){
this.jpb=jpb;
}
public VOid setStop(boolean b){
bStop=b;
}
public void run(){
int min=0;
int max=60;
jpb.setMinimum(min);
jpb.setMaximum(max);
jpb.setValue(min);
for(int x=min;x<=max;x++){
if(bStop){
break;
}else{
jpb.setValue(x);
try{
Thread.sleep(150);
} catch(InterruptedException e){
}
}
}
bAlive=false;
}
}
选项
答案
startProgress() stopProgress()
解析
转载请注明原文地址:https://jikaoti.com/ti/mkkiFFFM
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
表中所列城市2006年空气质量达到及好于二级的天数占全年的比重最高是( )按从高到低排序,2006年南京空气中二氧化硫含量在表内所列城市中的排名是( )
价格机制的核心内容是()。
春夏秋冬四季的循环往复变化使得地球景观绚丽多彩,这是大自然赋予地球的珍贵礼物。然而四季这个礼物似乎分配不公,地球上只有温带才有明显的四季变化,而寒带和热带则是长冬无夏和长夏无冬。其原因是()。
对于实施西部大开发战略,下列叙述错误的是()。
电脑作为日常工具走进寻常百姓家,既给我们的生活带来便利,同时电脑病毒、黑客等问题也给我们带来困扰。以下关于计算机病毒的叙述,正确的是()。①我们平常所说的“黑客”与“计算机病毒”其实是一回事②若用杀毒盘清毒后,感染病毒的文件可以
市场在资源配置中发挥着越来越重要的作用,但面对世界金融危机,市场的失灵引起了各国政府的重视。市场不具有的功能是()。
()被称为武器装备的“心脏”,是现代军事技术的核心和基础,广泛应用于雷达、计算机、通信设备、导航设备、火控系统、制导设备和电子对抗设备等各类军用设备上。
设函数f(u)有连续的一阶导数,f(0)=1,且函数(x≠0),求x的表达式.
在考生文件夹下有“web.mdb”数据库。(1)以个人信息表为数据源,创建“个人信息”窗体,布局为“纵栏表”,样式为“标准”。在个性信息窗体中添加以详细信息表为数据源的子窗体“详细信息”,子窗体显示详细信息表的全部字段。(2)创建“按照帐
在考生文件夹下有一个“Acc3.mdb”数据库。(1)以“部门人员”表为数据源,创建“部门人员”窗体,布局为“纵栏表”,样式为“标准”。(2)以“工资”表为数据源,创建“工资表”窗体,布局为“纵栏表”,样式为“标准”。(3)创建宏“查询工资”,实现打
随机试题
A.肺内结缔组织、血管、淋巴管和神经等B.肺泡C.Ⅱ型肺泡上皮细胞D.肺泡孔E.肺巨噬细胞相邻肺泡之间气体流通的小孔
属手厥阴心包经的腧穴是
磷酸戊糖途径的主要产物之一是
通常,认为证券市场是有效市场的机构投资者倾向于选择()。
凡是因减免税而需进行“三税”退库的,城建税即可同时退库。()
在上述定量测定之前,进行了蛋白质含量变化的预测实验,请填充实验原理,判断实验步骤上画线部分是否正确,并更正错误之处;写出实验结果。实验步骤:①将三份等量大豆种矛分别萌发l、5、9天后取出,各加入适量蒸馏水,研碎、提取、定容后离心得到蛋白质制备液;②取3
2017年勒索病毒全球蔓延,特别是5月全球爆发的永恒之蓝勒索蠕虫(WannaCry)和随后流行的Petya病毒,致使关键信息基础设施领域遭受到了前所未有的重大损失。根据受害者感染勒索病毒途径分布图,下列风险预防措施恰当的有()。
事业单位人员聘用合同中的约定条款,只要不违法律、法规、规章和政策的规定,则与必备条款具有同等效力。聘用合同缺乏约定条款不影响其效力。()
某市政府计划对全市的危旧房进行全面改造,通过政策和资金支持,以期较大幅度地建造普通住宅,缓解本市居民住房的紧张状况。市政府同时又计划适当提高普通住宅的市场售价,用以贴补上述房改的费用。这样做的理由是,本市居民是上述改造的直接受益者,应当承担部分开支。以
IfIhadn’tstoodundertheladdertocatchyouwhenyoufell,you______now.
最新回复
(
0
)