timer.docx

上传人:b****5 文档编号:6247262 上传时间:2023-01-04 格式:DOCX 页数:15 大小:17.64KB
下载 相关 举报
timer.docx_第1页
第1页 / 共15页
timer.docx_第2页
第2页 / 共15页
timer.docx_第3页
第3页 / 共15页
timer.docx_第4页
第4页 / 共15页
timer.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

timer.docx

《timer.docx》由会员分享,可在线阅读,更多相关《timer.docx(15页珍藏版)》请在冰豆网上搜索。

timer.docx

timer

packagecom.lk.main;

importjava.applet.Applet;

importjava.applet.AudioClip;

importjava.awt.Color;

importjava.awt.Container;

importjava.awt.Font;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.KeyEvent;

importjavax.swing.JButton;

importjavax.swing.JComponent;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JSeparator;

importjavax.swing.JSlider;

importjavax.swing.JTextField;

importjavax.swing.KeyStroke;

importjavax.swing.event.ChangeEvent;

importjavax.swing.event.ChangeListener;

importcom.jgoodies.forms.factories.DefaultComponentFactory;

importcom.swtdesigner.SwingResourceManager;

publicclassMainFrameextendsJFrame{

privateJTextFieldtextField;

privateJTextFieldmiaofiled;

privateJTextFieldfenfiled;

privateJTextFieldshifield;

publicJLabelxinxilabel;

publicJLabellabel_5;

publicintshi;

publicintfen;

publicintmiao;

privateDaojishithreaddaojishi=newDaojishithread();

privateMiaobiaothreadmiaobiao=newMiaobiaothread();

publicJLabelshilabel;

publicJLabelfenlabel;

publicJLabelmiaolabel;

/**

*@paramargs

*/

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

newMainFrame().setVisible(true);

}

privateJSliderslider;

privatedoublestep=1.0;

privateAudioClipclip=null;

publicMainFrame(){

super();

setTitle("草尼玛计时器--By理赔,QQ521052249");

setBounds(100,100,289,487);

//设置音频

Stringfilename="D:

\\tick.wav";

try{

clip=Applet.newAudioClip((newjava.io.File(filename)).toURL());

}catch(Exceptionex){

ex.printStackTrace();

}

getContentPane().setLayout(null);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setResizable(false);

finalJPaneltimepanel=newJPanel();

timepanel.setActionMap(null);

timepanel.setForeground(newColor(128,0,0));

timepanel.setFont(newFont("",Font.BOLD,12));

timepanel.setLayout(null);

timepanel.setBounds(0,0,284,221);

getContentPane().add(timepanel);

shilabel=newJLabel();

shilabel.setForeground(newColor(128,0,0));

shilabel.setFont(newFont("",Font.BOLD,24));

shilabel.setText("00");

shilabel.setBounds(53,68,34,53);

timepanel.add(shilabel);

finalJLabellabel_4=newJLabel();

label_4.setFont(newFont("",Font.BOLD,22));

label_4.setText(":

");

label_4.setBounds(93,79,23,25);

timepanel.add(label_4);

fenlabel=newJLabel();

fenlabel.setForeground(newColor(128,0,0));

fenlabel.setFont(newFont("",Font.BOLD,24));

fenlabel.setText("00");

fenlabel.setBounds(122,68,40,53);

timepanel.add(fenlabel);

finalJLabellabel_6=newJLabel();

label_6.setFont(newFont("",Font.BOLD,22));

label_6.setText(":

");

label_6.setBounds(168,79,34,25);

timepanel.add(label_6);

miaolabel=newJLabel();

miaolabel.setForeground(newColor(128,0,0));

miaolabel.setFont(newFont("",Font.BOLD,24));

miaolabel.setText("00");

miaolabel.setBounds(195,68,66,53);

timepanel.add(miaolabel);

xinxilabel=newJLabel();

xinxilabel.setFont(newFont("隶书",Font.BOLD,16));

xinxilabel.setBounds(53,10,166,36);

timepanel.add(xinxilabel);

label_5=newJLabel();

label_5.setBounds(108,148,83,18);

timepanel.add(label_5);

finalJLabellabel_7=newJLabel();

label_7.setIcon(SwingResourceManager.getIcon(MainFrame.class,"8823.jpg"));

label_7.setText("NewJLabel");

label_7.setBounds(0,0,284,221);

timepanel.add(label_7);

finalJPanelcontrolpanel=newJPanel();

controlpanel.setInputVerifier(null);

controlpanel.setLayout(null);

controlpanel.setBounds(0,227,284,235);

getContentPane().add(controlpanel);

finalJLabellabel=newJLabel();

label.setForeground(newColor(204,0,51));

label.setText("(时)");

label.setBounds(70,35,22,18);

controlpanel.add(label);

shifield=newJTextField();

shifield.setBounds(14,33,50,22);

controlpanel.add(shifield);

fenfiled=newJTextField();

fenfiled.setBounds(98,33,50,22);

controlpanel.add(fenfiled);

finalJLabellabel_1=newJLabel();

label_1.setForeground(newColor(204,0,51));

label_1.setText("(分)");

label_1.setBounds(154,35,22,18);

controlpanel.add(label_1);

miaofiled=newJTextField();

miaofiled.setBounds(182,33,50,22);

controlpanel.add(miaofiled);

finalJLabellabel_2=newJLabel();

label_2.setForeground(newColor(204,0,51));

label_2.setText("(秒)");

label_2.setBounds(238,35,22,18);

controlpanel.add(label_2);

finalJComponentseparator=DefaultComponentFactory.getInstance().createSeparator("倒计时控制");

separator.setBounds(10,101,274,57);

controlpanel.add(separator);

finalJButtonkaishibutton_1=newJButton();

kaishibutton_1.setForeground(newColor(0,0,0));

kaishibutton_1.setBackground(newColor(102,153,255));

kaishibutton_1.addActionListener(newActionListener(){

publicvoidactionPerformed(finalActionEvente){

kaishidaojishi(e);

}

});

kaishibutton_1.setText("开始");

kaishibutton_1.setBounds(82,128,76,22);

controlpanel.add(kaishibutton_1);

//监听类

classSymListenerimplementsActionListener{

publicvoidactionPerformed(ActionEvente){

Objectobj=e.getSource();

if(obj==kaishibutton_1)

kaishidaojishiActionPerformed(e);

}

}

SymListenersy=newSymListener();

kaishibutton_1.registerKeyboardAction(sy,

KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),

JComponent.WHEN_IN_FOCUSED_WINDOW);

//调节步长

slider=newJSlider(0,100);

slider.setMajorTickSpacing(10);

slider.setMinorTickSpacing(5);

slider.setBounds(98,77,80,20);

slider.addChangeListener(newChangeListener(){

publicvoidstateChanged(ChangeEventevent){

if((JSlider)event.getSource()==slider){

step=slider.getValue()*0.01;

Stringstr=""+step+"秒";

textField.setText(str);

}

}

});

controlpanel.add(slider);

finalJButtonstopbutton_1=newJButton();

stopbutton_1.setForeground(newColor(0,0,0));

stopbutton_1.setBackground(newColor(102,153,255));

stopbutton_1.addActionListener(newActionListener(){

publicvoidactionPerformed(finalActionEvente){

stopdao(e);

}

});

stopbutton_1.setText("停止");

stopbutton_1.setBounds(182,128,76,22);

controlpanel.add(stopbutton_1);

finalJComponentseparator_1=DefaultComponentFactory.getInstance().createSeparator("秒表控制");

separator_1.setBounds(10,151,274,84);

controlpanel.add(separator_1);

finalJButtonkaishibutton_2=newJButton();

kaishibutton_2.setForeground(newColor(0,51,0));

kaishibutton_2.setBackground(newColor(102,153,255));

kaishibutton_2.addActionListener(newActionListener(){

publicvoidactionPerformed(finalActionEvente){

kaishimiao(e);

}

});

kaishibutton_2.setText("开始");

kaishibutton_2.setBounds(82,168,76,22);

controlpanel.add(kaishibutton_2);

finalJButtonstopbutton_2=newJButton();

stopbutton_2.setForeground(newColor(0,51,51));

stopbutton_2.setBackground(newColor(102,153,255));

stopbutton_2.addActionListener(newActionListener(){

publicvoidactionPerformed(finalActionEvente){

stopmiao(e);

}

});

stopbutton_2.setText("停止");

stopbutton_2.setBounds(182,168,76,22);

controlpanel.add(stopbutton_2);

finalJButtonbutton_5=newJButton();

button_5.setForeground(newColor(0,51,51));

button_5.setBackground(newColor(102,153,255));

button_5.addActionListener(newActionListener(){

publicvoidactionPerformed(finalActionEvente){

miaolabel.setText("00");

fenlabel.setText("00");

shilabel.setText("00");

xinxilabel.setText("");

label_5.setText("");

}

});

button_5.setText("重置");

button_5.setBounds(182,203,76,22);

controlpanel.add(button_5);

finalJComponentseparator_2=DefaultComponentFactory.getInstance().createSeparator("控制键");

separator_2.setBounds(10,0,274,15);

controlpanel.add(separator_2);

finalJLabellabel_3=newJLabel();

label_3.setText("步长:

");

label_3.setBounds(26,77,66,18);

controlpanel.add(label_3);

textField=newJTextField();

textField.setBounds(198,75,80,22);

controlpanel.add(textField);

finalJLabellabel_8=newJLabel();

label_8.setIcon(SwingResourceManager.getIcon(MainFrame.class,"107.jpg"));

label_8.setText("NewJLabel");

label_8.setBounds(0,0,284,235);

controlpanel.add(label_8);

}

publicvoidkaishidaojishiActionPerformed(finalActionEvente){

kaishidaojishi(e);

}

classDaojishithreadextendsThread{

privatebooleanrunning=true;

Stringm;

Stringf;

Strings;

publicvoidrun(){

while(running){

try{

Thread.sleep((int)(step*1000));

}catch(InterruptedExceptione){

//TODOAuto-generatedcatchblock

e.printStackTrace();

}

//播放声音

clip.play();

if(miao==0&&fen>=0){

miao=59;

if(fen==0&&shi>0){

fen=59;

shi--;

}else{

fen--;

}

}else{

miao--;

}

if(miao<10){

m="0"+miao;

}else{

m=miao+"";

}if(fen<10){

f="0"+fen;

}else{

f=fen+"";

}if(shi<10){

s="0"+shi;

}else{

s=shi+"";

}

miaolabel.setText(m);

fenlabel.setText(f);

shilabel.setText(s);

if(miao==0&&fen==0&&shi==0){

tingzhidaojishi();

label_5.setText("倒计时结速");

}

}

}

publicvoidtingzhidaojishi(){

this.running=false;

}

}

classMiaobiaothreadextendsThread{

privatebooleangooo=true;

Stringm;

Stringf;

Strings;

publicvoidrun(){

while(gooo){

try{

Thread.sleep(1000);

}catch(InterruptedException

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 机械仪表

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1