Write a code that performs the following functions: Two buttons and two displays
ID: 3575429 • Letter: W
Question
Write a code that performs the following functions: Two buttons and two displays: (java) 1) start- when pressed it will start a counter from 1 to 100 Display the counter 2) Stop- stop the counter when "stop" button is pressed Display how many time the "stop" has been pressed Write a code that performs the following functions: Two buttons and two displays: (java) 1) start- when pressed it will start a counter from 1 to 100 Display the counter 2) Stop- stop the counter when "stop" button is pressed Display how many time the "stop" has been pressed Write a code that performs the following functions: Two buttons and two displays: (java) 1) start- when pressed it will start a counter from 1 to 100 Display the counter 2) Stop- stop the counter when "stop" button is pressed Display how many time the "stop" has been pressed Two buttons and two displays: (java) 1) start- when pressed it will start a counter from 1 to 100 Display the counter 2) Stop- stop the counter when "stop" button is pressed Display how many time the "stop" has been pressedExplanation / Answer
package startstop;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author bhuvan
*/
public class StartStop extends JFrame implements ActionListener{
/**
* @param args the command line arguments
*/
JTextArea ta;
JButton b1,b2;
StartStop(){
super("Word Character Counter - JavaTpoint");
ta=new JTextArea();
ta.setBounds(50,50,300,200);
b1=new JButton("Strat");
b1.setBounds(50,300,100,30);
b2=new JButton("Stop");
b2.setBounds(180,300,100,30);
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);add(b2);add(ta);
setSize(400,400);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
int count=0;
//String text=ta.getText();
if(e.getSource()==b1){
for(int i=0;i<100;i++){
JOptionPane.showMessageDialog(this,""+i);
}
}
if(e.getSource()==b2){
count+=1;
}
JOptionPane.showMessageDialog(this,"Count: "+count);
}
public static void main(String[] args) {
new StartStop();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.