SlideShare a Scribd company logo
1 of 6
Download to read offline
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StopWatch extends JPanel
{
private Timer myTimer1;
public static final int ONE_SEC = 1000; //time step in milliseconds
public static final int TENTH_SEC = 100;
private Font myClockFont;
private JButton startBtn, stopBtn, resetBtn;
private JLabel timeLbl;
private JPanel topPanel, bottomPanel;
private int clockTick; //number of clock ticks; tick can be 1.0 s or 0.1 s
private double clockTime; //time in seconds
private String clockTimeString;
public StopWatch()
{
clockTick = 0; //initial clock setting in clock ticks
clockTime = ((double)clockTick)/10.0;
clockTimeString = new Double(clockTime).toString();
myClockFont = new Font("Serif", Font.PLAIN, 50);
timeLbl = new JLabel();
timeLbl.setFont(myClockFont);
timeLbl.setText(clockTimeString);
startBtn = new JButton("Start");
stopBtn = new JButton("Stop");
resetBtn = new JButton("Reset");
myTimer1 = new Timer(TENTH_SEC, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
clockTick++;
clockTime = ((double)clockTick)/10.0;
clockTimeString = new Double(clockTime).toString();
timeLbl.setText(clockTimeString);
//System.out.println(clockTime);
}
});
startBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
myTimer1.start();
}
});
stopBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
myTimer1.stop();
}
});
resetBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
clockTick = 0;
clockTime = ((double)clockTick)/10.0;
clockTimeString = new Double(clockTime).toString();
timeLbl.setText(clockTimeString);
}
});
}//end of StopWatch constructor
public void launchStopWatch()
{
topPanel = new JPanel();
topPanel.setBackground(Color.orange);
bottomPanel = new JPanel();
bottomPanel.setBackground(Color.yellow);
topPanel.add(timeLbl);
bottomPanel.add(startBtn);
bottomPanel.add(stopBtn);
bottomPanel.add(resetBtn);
this.setLayout(new BorderLayout());
add(topPanel, BorderLayout.CENTER);
add(bottomPanel, BorderLayout.SOUTH);
setSize(300,200);
setBackground(Color.orange);
}//end of launchClock
public static void main(String[] args)
{
MyTestFrame myTestFrame1 = new MyTestFrame();
}
}
class MyTestFrame extends JFrame
{
StopWatch StopWatch1;
public MyTestFrame()
{
super("My Stop Watch");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container myPane = getContentPane();
StopWatch1 = new StopWatch();
StopWatch1.launchStopWatch();
myPane.add(StopWatch1);
pack();
setVisible(true);
}
}
Solution
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class StopWatch extends JPanel
{
private Timer myTimer1;
public static final int ONE_SEC = 1000; //time step in milliseconds
public static final int TENTH_SEC = 100;
private Font myClockFont;
private JButton startBtn, stopBtn, resetBtn;
private JLabel timeLbl;
private JPanel topPanel, bottomPanel;
private int clockTick; //number of clock ticks; tick can be 1.0 s or 0.1 s
private double clockTime; //time in seconds
private String clockTimeString;
public StopWatch()
{
clockTick = 0; //initial clock setting in clock ticks
clockTime = ((double)clockTick)/10.0;
clockTimeString = new Double(clockTime).toString();
myClockFont = new Font("Serif", Font.PLAIN, 50);
timeLbl = new JLabel();
timeLbl.setFont(myClockFont);
timeLbl.setText(clockTimeString);
startBtn = new JButton("Start");
stopBtn = new JButton("Stop");
resetBtn = new JButton("Reset");
myTimer1 = new Timer(TENTH_SEC, new ActionListener() {
public void actionPerformed(ActionEvent evt) {
clockTick++;
clockTime = ((double)clockTick)/10.0;
clockTimeString = new Double(clockTime).toString();
timeLbl.setText(clockTimeString);
//System.out.println(clockTime);
}
});
startBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
myTimer1.start();
}
});
stopBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
myTimer1.stop();
}
});
resetBtn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
clockTick = 0;
clockTime = ((double)clockTick)/10.0;
clockTimeString = new Double(clockTime).toString();
timeLbl.setText(clockTimeString);
}
});
}//end of StopWatch constructor
public void launchStopWatch()
{
topPanel = new JPanel();
topPanel.setBackground(Color.orange);
bottomPanel = new JPanel();
bottomPanel.setBackground(Color.yellow);
topPanel.add(timeLbl);
bottomPanel.add(startBtn);
bottomPanel.add(stopBtn);
bottomPanel.add(resetBtn);
this.setLayout(new BorderLayout());
add(topPanel, BorderLayout.CENTER);
add(bottomPanel, BorderLayout.SOUTH);
setSize(300,200);
setBackground(Color.orange);
}//end of launchClock
public static void main(String[] args)
{
MyTestFrame myTestFrame1 = new MyTestFrame();
}
}
class MyTestFrame extends JFrame
{
StopWatch StopWatch1;
public MyTestFrame()
{
super("My Stop Watch");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container myPane = getContentPane();
StopWatch1 = new StopWatch();
StopWatch1.launchStopWatch();
myPane.add(StopWatch1);
pack();
setVisible(true);
}
}

More Related Content

Similar to import java.awt.; import java.awt.event.; import javax.swing..pdf

Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsSumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Abhijit Borah
 
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdfpublic void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
isenbergwarne4100
 
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfimport java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
adhityalapcare
 
import java.applet.; import java.awt.; import java.awt.event.A.pdf
import java.applet.; import java.awt.; import java.awt.event.A.pdfimport java.applet.; import java.awt.; import java.awt.event.A.pdf
import java.applet.; import java.awt.; import java.awt.event.A.pdf
apnafreez
 

Similar to import java.awt.; import java.awt.event.; import javax.swing..pdf (20)

Android Architecture Component in Real Life
Android Architecture Component in Real LifeAndroid Architecture Component in Real Life
Android Architecture Component in Real Life
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Lab 1 izz
Lab 1 izzLab 1 izz
Lab 1 izz
 
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programsSumsem2014 15 cp0399-13-jun-2015_rm01_programs
Sumsem2014 15 cp0399-13-jun-2015_rm01_programs
 
Tdd iPhone For Dummies
Tdd iPhone For DummiesTdd iPhone For Dummies
Tdd iPhone For Dummies
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Android TDD
Android TDDAndroid TDD
Android TDD
 
The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202The Ring programming language version 1.8 book - Part 88 of 202
The Ring programming language version 1.8 book - Part 88 of 202
 
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdfpublic void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
public void turnRight(double degrees) {rotationInDegrees + - = deg.pdf
 
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho PolutaInfinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
Infinum iOS Talks #1 - Swift under the hood: Method Dispatching by Vlaho Poluta
 
CSharp for Unity Day2
CSharp for Unity Day2CSharp for Unity Day2
CSharp for Unity Day2
 
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...Psychtoolbox (PTB) practical course  by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
Psychtoolbox (PTB) practical course by Volodymyr B. Bogdanov, Lyon/Kyiv 2018...
 
Thread
ThreadThread
Thread
 
Android TDD & CI
Android TDD & CIAndroid TDD & CI
Android TDD & CI
 
Implementing STM in Java
Implementing STM in JavaImplementing STM in Java
Implementing STM in Java
 
Microkernel Development
Microkernel DevelopmentMicrokernel Development
Microkernel Development
 
Proyecto Poogame Tic Tac Toe
Proyecto Poogame Tic Tac ToeProyecto Poogame Tic Tac Toe
Proyecto Poogame Tic Tac Toe
 
662305 11
662305 11662305 11
662305 11
 
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfimport java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
 
import java.applet.; import java.awt.; import java.awt.event.A.pdf
import java.applet.; import java.awt.; import java.awt.event.A.pdfimport java.applet.; import java.awt.; import java.awt.event.A.pdf
import java.applet.; import java.awt.; import java.awt.event.A.pdf
 

More from aparnawatchcompany

Not all analytes re non-polar hydrophobic substan.pdf
                     Not all analytes re non-polar hydrophobic substan.pdf                     Not all analytes re non-polar hydrophobic substan.pdf
Not all analytes re non-polar hydrophobic substan.pdf
aparnawatchcompany
 
Off-balance sheet problems have recurred throughout history, with .pdf
    Off-balance sheet problems have recurred throughout history, with .pdf    Off-balance sheet problems have recurred throughout history, with .pdf
Off-balance sheet problems have recurred throughout history, with .pdf
aparnawatchcompany
 
Well the only difference between the two structur.pdf
                     Well the only difference between the two structur.pdf                     Well the only difference between the two structur.pdf
Well the only difference between the two structur.pdf
aparnawatchcompany
 
The short answer is no. SN2 reactions are governed by several factor.pdf
The short answer is no. SN2 reactions are governed by several factor.pdfThe short answer is no. SN2 reactions are governed by several factor.pdf
The short answer is no. SN2 reactions are governed by several factor.pdf
aparnawatchcompany
 
Technology has taking milestone forwarding steps and they are using .pdf
Technology has taking milestone forwarding steps and they are using .pdfTechnology has taking milestone forwarding steps and they are using .pdf
Technology has taking milestone forwarding steps and they are using .pdf
aparnawatchcompany
 
Plantaris muscleThe plantaris is one of the superficial muscles of.pdf
Plantaris muscleThe plantaris is one of the superficial muscles of.pdfPlantaris muscleThe plantaris is one of the superficial muscles of.pdf
Plantaris muscleThe plantaris is one of the superficial muscles of.pdf
aparnawatchcompany
 
Non-coded RNA are small RNA molecule that cannot be translated by ho.pdf
Non-coded RNA are small RNA molecule that cannot be translated by ho.pdfNon-coded RNA are small RNA molecule that cannot be translated by ho.pdf
Non-coded RNA are small RNA molecule that cannot be translated by ho.pdf
aparnawatchcompany
 

More from aparnawatchcompany (20)

I am sorry . image is too small. the expression is not clearly.pdf
 I am sorry . image is too small. the expression is not clearly.pdf I am sorry . image is too small. the expression is not clearly.pdf
I am sorry . image is too small. the expression is not clearly.pdf
 
the molar ratio of Na2S2O3 CL2 = 1 4 moles of.pdf
                     the molar ratio of Na2S2O3  CL2 = 1  4 moles of.pdf                     the molar ratio of Na2S2O3  CL2 = 1  4 moles of.pdf
the molar ratio of Na2S2O3 CL2 = 1 4 moles of.pdf
 
object persistence formats Sequential access optimized for operat.pdf
  object persistence formats   Sequential access  optimized for operat.pdf  object persistence formats   Sequential access  optimized for operat.pdf
object persistence formats Sequential access optimized for operat.pdf
 
The answer is b.) 4 Distribution coefficient = .pdf
                     The answer is b.) 4  Distribution coefficient = .pdf                     The answer is b.) 4  Distribution coefficient = .pdf
The answer is b.) 4 Distribution coefficient = .pdf
 
Not all analytes re non-polar hydrophobic substan.pdf
                     Not all analytes re non-polar hydrophobic substan.pdf                     Not all analytes re non-polar hydrophobic substan.pdf
Not all analytes re non-polar hydrophobic substan.pdf
 
Off-balance sheet problems have recurred throughout history, with .pdf
    Off-balance sheet problems have recurred throughout history, with .pdf    Off-balance sheet problems have recurred throughout history, with .pdf
Off-balance sheet problems have recurred throughout history, with .pdf
 
Well the only difference between the two structur.pdf
                     Well the only difference between the two structur.pdf                     Well the only difference between the two structur.pdf
Well the only difference between the two structur.pdf
 
Compunds composed of hydrogen and either fluorine.pdf
                     Compunds composed of hydrogen and either fluorine.pdf                     Compunds composed of hydrogen and either fluorine.pdf
Compunds composed of hydrogen and either fluorine.pdf
 
The Seliwanoffs Test is a test for ketoses. Of .pdf
                     The Seliwanoffs Test is a test for ketoses. Of .pdf                     The Seliwanoffs Test is a test for ketoses. Of .pdf
The Seliwanoffs Test is a test for ketoses. Of .pdf
 
The short answer is no. SN2 reactions are governed by several factor.pdf
The short answer is no. SN2 reactions are governed by several factor.pdfThe short answer is no. SN2 reactions are governed by several factor.pdf
The short answer is no. SN2 reactions are governed by several factor.pdf
 
Technology has taking milestone forwarding steps and they are using .pdf
Technology has taking milestone forwarding steps and they are using .pdfTechnology has taking milestone forwarding steps and they are using .pdf
Technology has taking milestone forwarding steps and they are using .pdf
 
Solution(a)Basic DefLet R be a binary relation on a set A.R i.pdf
Solution(a)Basic DefLet R be a binary relation on a set A.R i.pdfSolution(a)Basic DefLet R be a binary relation on a set A.R i.pdf
Solution(a)Basic DefLet R be a binary relation on a set A.R i.pdf
 
Section 4 we describe how theSolutionSection 4 we describe how.pdf
Section 4 we describe how theSolutionSection 4 we describe how.pdfSection 4 we describe how theSolutionSection 4 we describe how.pdf
Section 4 we describe how theSolutionSection 4 we describe how.pdf
 
probability= 10100=0.1Simple.Solutionprobability= 10100=0..pdf
probability= 10100=0.1Simple.Solutionprobability= 10100=0..pdfprobability= 10100=0.1Simple.Solutionprobability= 10100=0..pdf
probability= 10100=0.1Simple.Solutionprobability= 10100=0..pdf
 
Plantaris muscleThe plantaris is one of the superficial muscles of.pdf
Plantaris muscleThe plantaris is one of the superficial muscles of.pdfPlantaris muscleThe plantaris is one of the superficial muscles of.pdf
Plantaris muscleThe plantaris is one of the superficial muscles of.pdf
 
I think... Highest energy = most polarized = h.pdf
                     I think...  Highest energy = most polarized = h.pdf                     I think...  Highest energy = most polarized = h.pdf
I think... Highest energy = most polarized = h.pdf
 
P( 0 Z 1.5 )= P(Z1.5) - P(Z0)= 0.9332 - 0.5 (from table)= .pdf
P( 0 Z 1.5 )= P(Z1.5) - P(Z0)= 0.9332 - 0.5 (from table)= .pdfP( 0 Z 1.5 )= P(Z1.5) - P(Z0)= 0.9332 - 0.5 (from table)= .pdf
P( 0 Z 1.5 )= P(Z1.5) - P(Z0)= 0.9332 - 0.5 (from table)= .pdf
 
Non-coded RNA are small RNA molecule that cannot be translated by ho.pdf
Non-coded RNA are small RNA molecule that cannot be translated by ho.pdfNon-coded RNA are small RNA molecule that cannot be translated by ho.pdf
Non-coded RNA are small RNA molecule that cannot be translated by ho.pdf
 
Option b is Settlement risk The Nonschedule L off-balance-sheet ri.pdf
Option b is Settlement risk The Nonschedule L off-balance-sheet ri.pdfOption b is Settlement risk The Nonschedule L off-balance-sheet ri.pdf
Option b is Settlement risk The Nonschedule L off-balance-sheet ri.pdf
 
mSolutionm.pdf
mSolutionm.pdfmSolutionm.pdf
mSolutionm.pdf
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 

import java.awt.; import java.awt.event.; import javax.swing..pdf

  • 1. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class StopWatch extends JPanel { private Timer myTimer1; public static final int ONE_SEC = 1000; //time step in milliseconds public static final int TENTH_SEC = 100; private Font myClockFont; private JButton startBtn, stopBtn, resetBtn; private JLabel timeLbl; private JPanel topPanel, bottomPanel; private int clockTick; //number of clock ticks; tick can be 1.0 s or 0.1 s private double clockTime; //time in seconds private String clockTimeString; public StopWatch() { clockTick = 0; //initial clock setting in clock ticks clockTime = ((double)clockTick)/10.0; clockTimeString = new Double(clockTime).toString(); myClockFont = new Font("Serif", Font.PLAIN, 50); timeLbl = new JLabel(); timeLbl.setFont(myClockFont); timeLbl.setText(clockTimeString); startBtn = new JButton("Start"); stopBtn = new JButton("Stop"); resetBtn = new JButton("Reset"); myTimer1 = new Timer(TENTH_SEC, new ActionListener() { public void actionPerformed(ActionEvent evt) { clockTick++; clockTime = ((double)clockTick)/10.0; clockTimeString = new Double(clockTime).toString(); timeLbl.setText(clockTimeString);
  • 2. //System.out.println(clockTime); } }); startBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ myTimer1.start(); } }); stopBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ myTimer1.stop(); } }); resetBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ clockTick = 0; clockTime = ((double)clockTick)/10.0; clockTimeString = new Double(clockTime).toString(); timeLbl.setText(clockTimeString); } }); }//end of StopWatch constructor public void launchStopWatch() { topPanel = new JPanel(); topPanel.setBackground(Color.orange); bottomPanel = new JPanel(); bottomPanel.setBackground(Color.yellow); topPanel.add(timeLbl); bottomPanel.add(startBtn); bottomPanel.add(stopBtn); bottomPanel.add(resetBtn); this.setLayout(new BorderLayout()); add(topPanel, BorderLayout.CENTER); add(bottomPanel, BorderLayout.SOUTH);
  • 3. setSize(300,200); setBackground(Color.orange); }//end of launchClock public static void main(String[] args) { MyTestFrame myTestFrame1 = new MyTestFrame(); } } class MyTestFrame extends JFrame { StopWatch StopWatch1; public MyTestFrame() { super("My Stop Watch"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container myPane = getContentPane(); StopWatch1 = new StopWatch(); StopWatch1.launchStopWatch(); myPane.add(StopWatch1); pack(); setVisible(true); } } Solution import java.awt.*; import java.awt.event.*; import javax.swing.*; public class StopWatch extends JPanel { private Timer myTimer1; public static final int ONE_SEC = 1000; //time step in milliseconds public static final int TENTH_SEC = 100; private Font myClockFont;
  • 4. private JButton startBtn, stopBtn, resetBtn; private JLabel timeLbl; private JPanel topPanel, bottomPanel; private int clockTick; //number of clock ticks; tick can be 1.0 s or 0.1 s private double clockTime; //time in seconds private String clockTimeString; public StopWatch() { clockTick = 0; //initial clock setting in clock ticks clockTime = ((double)clockTick)/10.0; clockTimeString = new Double(clockTime).toString(); myClockFont = new Font("Serif", Font.PLAIN, 50); timeLbl = new JLabel(); timeLbl.setFont(myClockFont); timeLbl.setText(clockTimeString); startBtn = new JButton("Start"); stopBtn = new JButton("Stop"); resetBtn = new JButton("Reset"); myTimer1 = new Timer(TENTH_SEC, new ActionListener() { public void actionPerformed(ActionEvent evt) { clockTick++; clockTime = ((double)clockTick)/10.0; clockTimeString = new Double(clockTime).toString(); timeLbl.setText(clockTimeString); //System.out.println(clockTime); } }); startBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ myTimer1.start(); } }); stopBtn.addActionListener(new ActionListener(){
  • 5. public void actionPerformed(ActionEvent evt){ myTimer1.stop(); } }); resetBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent evt){ clockTick = 0; clockTime = ((double)clockTick)/10.0; clockTimeString = new Double(clockTime).toString(); timeLbl.setText(clockTimeString); } }); }//end of StopWatch constructor public void launchStopWatch() { topPanel = new JPanel(); topPanel.setBackground(Color.orange); bottomPanel = new JPanel(); bottomPanel.setBackground(Color.yellow); topPanel.add(timeLbl); bottomPanel.add(startBtn); bottomPanel.add(stopBtn); bottomPanel.add(resetBtn); this.setLayout(new BorderLayout()); add(topPanel, BorderLayout.CENTER); add(bottomPanel, BorderLayout.SOUTH); setSize(300,200); setBackground(Color.orange); }//end of launchClock public static void main(String[] args) { MyTestFrame myTestFrame1 = new MyTestFrame(); } } class MyTestFrame extends JFrame
  • 6. { StopWatch StopWatch1; public MyTestFrame() { super("My Stop Watch"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container myPane = getContentPane(); StopWatch1 = new StopWatch(); StopWatch1.launchStopWatch(); myPane.add(StopWatch1); pack(); setVisible(true); } }