2. [文件] MyTimerFrame.java ~ 2KB 下载(55)
01 |
package com.lag.ch03227.time; |
03 |
import java.awt.Color; |
06 |
import javax.swing.JButton; |
07 |
import javax.swing.JFrame; |
08 |
import javax.swing.border.LineBorder; |
10 |
public class MyTimerFrame extends JFrame{ |
13 |
private JButton
but1,but2; |
15 |
private TimeThread
time; |
17 |
public MyTimerFrame(){ |
19 |
this .setBounds( 200 , 200 , 300 , 200 ); |
22 |
lab= new MyLabel( "00:00:00" ); |
23 |
this .lab.setBounds( 100 , 50 , 100 , 20 ); |
24 |
this .lab.setBorder( new LineBorder(Color.BLACK)); |
25 |
this .lab.setFont( new Font( "ºÚÌå" ,Font.BOLD, 20 )); |
26 |
this .lab.setHorizontalAlignment( 0 ); |
31 |
but1
= new JButton( "¿ªÊ¼" ); |
32 |
but1.setBounds( 40 , 110 , 100 , 20 ); |
34 |
but2
= new JButton( "ÖØÖÃ" ); |
35 |
but2.setBounds( 160 , 110 , 100 , 20 ); |
38 |
Handler
h= new Handler( this ); |
40 |
but1.addActionListener(h); |
41 |
but2.addActionListener(h); |
46 |
this .setVisible( true ); |
47 |
this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
49 |
time
= new TimeThread(lab); |
54 |
public JButton
getBut1() { |
58 |
public void setBut1(JButton
but1) { |
62 |
public JButton
getBut2() { |
66 |
public void setBut2(JButton
but2) { |
70 |
public MyLabel
getLab() { |
74 |
public void setLab(MyLabel
lab) { |
79 |
public static void main(String[]
args) { |
3. [文件] MyLabel.java ~ 2KB 下载(41)
001 |
package com.lag.ch03227.time; |
003 |
import java.text.DecimalFormat; |
005 |
import javax.swing.JLabel; |
007 |
public class MyLabel extends JLabel{ |
008 |
private int min,senconds,ps; |
009 |
private boolean flag= false ; |
010 |
private DecimalFormat
df = new DecimalFormat( "00" ); |
012 |
public MyLabel(String
names) { |
016 |
public int getMin()
{ |
020 |
public void setMin( int min)
{ |
024 |
public int getSenconds()
{ |
028 |
public void setSenconds( int senconds)
{ |
029 |
this .senconds
= senconds; |
036 |
public void setPs( int ps)
{ |
042 |
public boolean isFlag()
{ |
046 |
public void setFlag( boolean flag)
{ |
051 |
public DecimalFormat
getDf() { |
055 |
public void setDf(DecimalFormat
df) { |
068 |
this .setText( "00:00:00" ); |
074 |
public synchronized void timer(){ |
078 |
} catch (InterruptedException
e) { |
093 |
this .setText(df.format(min)+ ":" +df.format(senconds)+ ":" +df.format(ps)); |
098 |
public synchronized void notifyLabel()
{ |
4. [文件] Handler.java ~ 671B 下载(43)
01 |
package com.lag.ch03227.time; |
03 |
import java.awt.event.ActionEvent; |
04 |
import java.awt.event.ActionListener; |
06 |
public class Handler implements ActionListener{ |
07 |
private MyTimerFrame
win; |
09 |
public Handler(MyTimerFrame
win) { |
14 |
public void actionPerformed(ActionEvent
e) { |
16 |
if (e.getActionCommand().equals( "开始" )){ |
17 |
win.getBut1().setText( "暂停" ); |
18 |
win.getLab().setFlag( true ); |
19 |
win.getLab().notifyLabel(); |
20 |
} else if (e.getActionCommand().equals( "暂停" ))
{ |