import
java.awt.Button;
import
java.awt.Color;
import
java.awt.Font;
import
java.awt.Graphics;
import
java.awt.GridLayout;
import
java.awt.Label;
import
java.awt.Panel;
import
java.awt.event.ActionEvent;
import
java.awt.event.ActionListener;
import
javax.swing.ImageIcon;
import
javax.swing.JFrame;
import
javax.swing.SwingConstants;
public class Main
{
public
static Label Lab = new Label(" 0.0");
public
static Label Lab1 = new Label("");
public
static Label Lab2 = new Label("");
public
static Label Lab3 = new Label("");
public
static Label Lab4 = new Label("");
public
static Label Lab5 = new Label("");
public
static Button ButClean=new Button("Ñáðîñ");
public
static Button ButStop=new Button("Ñòîï");
public
static Button ButStart=new Button("Ñòàðò");
public
static double time=0;
public
static boolean stop=true;
public
static void main(String[] args) {
JFrame
Ex = new JFrame ("Ñåêóíäîìåð");
Ex.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Ex.setSize(600,
400);
Panel
Pan = new Panel();
Pan.add(Lab3);
Pan.add(Lab);
Pan.add(Lab4);
Pan.add(Lab5);
Pan.add(Lab1);
Pan.add(Lab2);
Pan.add
(ButStart);
Pan.add
(ButStop);
Pan.add
(ButClean);
GridLayout
gr = new GridLayout(3,3);
Pan.setLayout(gr);
ButStart.setBackground(new
Color(200,255,200));
ButStop.setBackground(new
Color(255,200,200));
ButClean.setBackground(new
Color(200,200,255));
Pan.setBackground(new
Color(252,239,148));
Lab.setFont(new
Font("Arial",10,60));
ButStart.setFont(new
Font("Arial",10,60));
ButStop.setFont(new
Font("Arial",10,60));
ButClean.setFont(new
Font("Arial",10,60));
ButStop.setEnabled(false);
ButClean.addActionListener(new
ActionListener(){
public
void actionPerformed(ActionEvent evt) {
stop=true;
time=0;
Lab.setText("
0.0");
ButStart.setEnabled(true);
ButClean.setEnabled(false);
}});
ButClean.setEnabled(false);
ButStop.addActionListener(new
ActionListener(){
public
void actionPerformed(ActionEvent evt) {
ButClean.setEnabled(true);
ButStart.setEnabled(false);
stop=false;
}});
ButStart.addActionListener(new
ActionListener(){
public
void actionPerformed(ActionEvent evt) {
ButStop.setEnabled(true);
final
TwoThread MyThread = new TwoThread();
MyThread.start();
ButStart.setEnabled(false);
}});
Ex.add(Pan);
Ex.setVisible(true);
}
}
class TwoThread
extends Thread
{public void
run()
{while
(Main.stop)
{
try{
TwoThread.sleep(100);
Main.time+=1;
Main.Lab.setText("
"+Main.time/10+"");
}
catch(InterruptedException
MyError){}
}
}
}
Оставьте свой комментарий
Авторизуйтесь, чтобы задавать вопросы.