SlideShare a Scribd company logo
1 of 4
I have problems with running this code to get the output please help
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSlider;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class Program {
public static void main(String[] args) {
JFrame frame = new JFrame("Data Entry");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
// create the timer panel
JPanel timerPanel = new JPanel();
timerPanel.setBackground(Color.WHITE);
JLabel timerLabel = new JLabel("Timer: 00:00", SwingConstants.CENTER);
timerLabel.setFont(new Font("Courier", Font.PLAIN, 20));
Timer timer = new Timer(1000, e -> {
int time = Integer.parseInt(timerLabel.getText().substring(7)) + 1;
timerLabel.setText("Timer: " + String.format("%02d", time / 60) + ":" + String.format("%02d",
time % 60));
});
timer.start();
timerPanel.add(timerLabel);
// create the name panel
JPanel namePanel = new JPanel();
namePanel.setBackground(Color.WHITE);
JTextField nameField = new JTextField(20);
nameField.setFont(new Font("Courier", Font.PLAIN, 20));
nameField.addFocusListener(new FocusListener() {
@Override
public void focusGained(FocusEvent e) {
nameField.setForeground(Color.BLUE);
}
@Override
public void focusLost(FocusEvent e) {}
});
JButton submitButton = new JButton("SUBMIT");
submitButton.setFont(new Font("Courier", Font.PLAIN, 20));
JTextArea textArea = new JTextArea(10, 40);
textArea.setFont(new Font("Courier", Font.PLAIN, 20));
textArea.setEditable(false);
textArea.setBorder(BorderFactory.createLineBorder(Color.BLACK));
submitButton.addActionListener(e -> {
String name = nameField.getText();
if (!name.equals("")) {
textArea.append(name + "n");
nameField.setText("");
}
});
namePanel.add(nameField);
namePanel.add(submitButton);
// create the font size panel
JPanel fontSizePanel = new JPanel();
fontSizePanel.setBackground(Color.WHITE);
JSlider fontSizeSlider = new JSlider(JSlider.HORIZONTAL, 10, 40, 20);
fontSizeSlider.setMajorTickSpacing(10);
fontSizeSlider.setMinorTickSpacing(5);
fontSizeSlider.setPaintTicks(true);
fontSizeSlider.setPaintLabels(true);
fontSizeSlider.setFont(new Font("Courier", Font.PLAIN, 20));
fontSizeSlider.addChangeListener(e -> {
int fontSize = fontSizeSlider.getValue();
Font font = new Font("Courier", Font.PLAIN, fontSize);
textArea.setFont(font);
});
fontSizePanel.add(fontSizeSlider);
// create the animation panel
JPanel animationPanel = new JPanel();
animationPanel.setBackground(Color.WHITE);
JLabel imageLabel = new JLabel();
ImageIcon horseIcon = new ImageIcon("horse.jpg");
ImageIcon birdIcon = new ImageIcon("bird.jpg");
ImageIcon aeroplanIcon = new ImageIcon("aeroplan.jpg");
imageLabel.setIcon(horseIcon);
JRadioButton horseButton = new JRadioButton("Horse", true);
horseButton.setFont(new Font("Courier", Font.PLAIN, 20));
JRadioButton birdButton = new JRadioButton("Bird"); birdButton.setFont(new Font("Courier",
Font.PLAIN, 20));
JRadioButton aeroplanButton = new JRadioButton("Aeroplan");
aeroplanButton.setFont(new Font("Courier", Font.PLAIN, 20));
horseButton.addActionListener(e -> imageLabel.setIcon(horseIcon));
birdButton.addActionListener(e -> imageLabel.setIcon(birdIcon));
aeroplanButton.addActionListener(e -> imageLabel.setIcon(aeroplanIcon));
animationPanel.add(horseButton);
animationPanel.add(birdButton);
animationPanel.add(aeroplanButton);
animationPanel.add(imageLabel);
// create the start and stop buttons
JPanel buttonPanel = new JPanel();
buttonPanel.setBackground(Color.WHITE);
JButton startButton = new JButton("Start");
startButton.setFont(new Font("Courier", Font.PLAIN, 20));
JButton stopButton = new JButton("Stop");
stopButton.setFont(new Font("Courier", Font.PLAIN, 20));
startButton.addActionListener(e -> {
Thread animationThread = new Thread(() -> {
while (true) {
ImageIcon currentIcon = (ImageIcon) imageLabel.getIcon();
if (currentIcon.equals(horseIcon)) {
imageLabel.setIcon(birdIcon);
} else if (currentIcon.equals(birdIcon)) {
imageLabel.setIcon(aeroplanIcon);
} else {
imageLabel.setIcon(horseIcon);
}
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
break;
}
}
});
animationThread.start();
});
stopButton.addActionListener(e -> {
for (Thread thread : Thread.getAllStackTraces().keySet()) {
if (thread.getName().startsWith("Thread-")) {
thread.interrupt();
}
}
});
buttonPanel.add(startButton);
buttonPanel.add(stopButton);
// create the main panel
JPanel mainPanel = new JPanel(new BorderLayout());
mainPanel.add(timerPanel, BorderLayout.NORTH);
mainPanel.add(namePanel, BorderLayout.CENTER);
mainPanel.add(fontSizePanel, BorderLayout.SOUTH);
// add the sub-panels to the main panel
mainPanel.add(animationPanel, BorderLayout.EAST);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
// add the main panel to the frame and show the frame
frame.add(mainPanel);
frame.setVisible(true);
// add a window listener to the frame to show a message when the program exits
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
timer.stop();
String time = timerLabel.getText().substring(7);
JOptionPane.showMessageDialog(frame, "Thank you for using my program for " + time + "
time.");
}
});
}
}

More Related Content

Similar to I have problems with running this code to get the output please help.docx

import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfvenkt12345
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfpackage buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfarjuntiwari586
 
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdfimport java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdfanupambedcovers
 
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docxAliHaiderCheema2
 
Revision c odesagain
Revision c odesagainRevision c odesagain
Revision c odesagainrex0721
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfbadshetoms
 
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdfPasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdfanjaniar7gallery
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfaakarcreations1
 
Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architectureAmol Gaikwad
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdffathimaoptical
 
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdfmohammedfootwear
 
Write a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfWrite a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfsales98
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfflashfashioncasualwe
 
How do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfHow do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfforwardcom41
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfarccreation001
 

Similar to I have problems with running this code to get the output please help.docx (20)

import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdfimport java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
import java.awt.Color;import java.awt.Insets;import java.awt.Con.pdf
 
DBTool
DBToolDBTool
DBTool
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfpackage buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdf
 
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdfimport java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
import java.awt.event.ActionEvent; import java.awt.event.ActionLis.pdf
 
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
20-Arid-850 Ali Haider Cheema BSSE(5A) Evening MPL Assignement 08.docx
 
Scrollable Demo App
Scrollable Demo AppScrollable Demo App
Scrollable Demo App
 
Revision c odesagain
Revision c odesagainRevision c odesagain
Revision c odesagain
 
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!How can I make the add but.pdf
 
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdfPasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdf
 
Unit-2 swing and mvc architecture
Unit-2 swing and mvc architectureUnit-2 swing and mvc architecture
Unit-2 swing and mvc architecture
 
Write a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdfWrite a GUI application to simulate writing out a check. The value o.pdf
Write a GUI application to simulate writing out a check. The value o.pdf
 
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdfPLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
PLEASE HELP ME !!IT IS Due Tonight ;(!i have to submit it before.pdf
 
Write a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfWrite a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdf
 
In Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdfIn Java Write a GUI application to simulate writing out a check. The.pdf
In Java Write a GUI application to simulate writing out a check. The.pdf
 
TextSearch
TextSearchTextSearch
TextSearch
 
Tuto jtatoo
Tuto jtatooTuto jtatoo
Tuto jtatoo
 
How do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfHow do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdf
 
Test
TestTest
Test
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
 

More from JacobUasThomsoni

I can put it in a infographic or poster if you just help me with all t.docx
I can put it in a infographic or poster if you just help me with all t.docxI can put it in a infographic or poster if you just help me with all t.docx
I can put it in a infographic or poster if you just help me with all t.docxJacobUasThomsoni
 
Human Factors Assignment For your individual ( any medical product )pr.docx
Human Factors Assignment For your individual ( any medical product )pr.docxHuman Factors Assignment For your individual ( any medical product )pr.docx
Human Factors Assignment For your individual ( any medical product )pr.docxJacobUasThomsoni
 
I am working on an assignment that im builidng a game- I am wanting to.docx
I am working on an assignment that im builidng a game- I am wanting to.docxI am working on an assignment that im builidng a game- I am wanting to.docx
I am working on an assignment that im builidng a game- I am wanting to.docxJacobUasThomsoni
 
I a study of general incorporation laws in the Uniled States- Eric Hit.docx
I a study of general incorporation laws in the Uniled States- Eric Hit.docxI a study of general incorporation laws in the Uniled States- Eric Hit.docx
I a study of general incorporation laws in the Uniled States- Eric Hit.docxJacobUasThomsoni
 
Human computer interaction 1- Find five design issues with Codeblocks.docx
Human computer interaction 1- Find five design issues with Codeblocks.docxHuman computer interaction 1- Find five design issues with Codeblocks.docx
Human computer interaction 1- Find five design issues with Codeblocks.docxJacobUasThomsoni
 
Hypertension has been known to be called the -Silent Killer- due to wh.docx
Hypertension has been known to be called the -Silent Killer- due to wh.docxHypertension has been known to be called the -Silent Killer- due to wh.docx
Hypertension has been known to be called the -Silent Killer- due to wh.docxJacobUasThomsoni
 
how would i fix my code- any login doesnt work but it should retrieve.docx
how would i fix my code- any login doesnt work but it should retrieve.docxhow would i fix my code- any login doesnt work but it should retrieve.docx
how would i fix my code- any login doesnt work but it should retrieve.docxJacobUasThomsoni
 
I have to submit this assignment after one hour Scope Management Plan.docx
I have to submit this assignment after one hour  Scope Management Plan.docxI have to submit this assignment after one hour  Scope Management Plan.docx
I have to submit this assignment after one hour Scope Management Plan.docxJacobUasThomsoni
 
I have no idea what this means List all the kinds of eggs that can be.docx
I have no idea what this means List all the kinds of eggs that can be.docxI have no idea what this means List all the kinds of eggs that can be.docx
I have no idea what this means List all the kinds of eggs that can be.docxJacobUasThomsoni
 
If David Jones wants to save for his child's college tuition in 20 yea.docx
If David Jones wants to save for his child's college tuition in 20 yea.docxIf David Jones wants to save for his child's college tuition in 20 yea.docx
If David Jones wants to save for his child's college tuition in 20 yea.docxJacobUasThomsoni
 
If artificial intelligent systems that were designed to diagnose disea.docx
If artificial intelligent systems that were designed to diagnose disea.docxIf artificial intelligent systems that were designed to diagnose disea.docx
If artificial intelligent systems that were designed to diagnose disea.docxJacobUasThomsoni
 
If an investor requires a real return of 3- and the average inflation.docx
If an investor requires a real return of 3- and the average inflation.docxIf an investor requires a real return of 3- and the average inflation.docx
If an investor requires a real return of 3- and the average inflation.docxJacobUasThomsoni
 
If a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docx
If a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docxIf a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docx
If a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docxJacobUasThomsoni
 
If a Himalayan rabbit is crossed to an albino rabbit- could one of the.docx
If a Himalayan rabbit is crossed to an albino rabbit- could one of the.docxIf a Himalayan rabbit is crossed to an albino rabbit- could one of the.docx
If a Himalayan rabbit is crossed to an albino rabbit- could one of the.docxJacobUasThomsoni
 
If A and B are two independent events- then P(AB)-P(B) True False.docx
If A and B are two independent events- then P(AB)-P(B) True False.docxIf A and B are two independent events- then P(AB)-P(B) True False.docx
If A and B are two independent events- then P(AB)-P(B) True False.docxJacobUasThomsoni
 
If 2+3i3+2i-a+ib- than Proof a2+b2-1.docx
If 2+3i3+2i-a+ib- than Proof a2+b2-1.docxIf 2+3i3+2i-a+ib- than Proof a2+b2-1.docx
If 2+3i3+2i-a+ib- than Proof a2+b2-1.docxJacobUasThomsoni
 
Identifying the weaknesses of a company is a factor that should be ana.docx
Identifying the weaknesses of a company is a factor that should be ana.docxIdentifying the weaknesses of a company is a factor that should be ana.docx
Identifying the weaknesses of a company is a factor that should be ana.docxJacobUasThomsoni
 
Identify the specific social- political- and economic challenges that.docx
Identify the specific social- political- and economic challenges that.docxIdentify the specific social- political- and economic challenges that.docx
Identify the specific social- political- and economic challenges that.docxJacobUasThomsoni
 
Identify what is inaccurate in the author's diagram that shows- Figure.docx
Identify what is inaccurate in the author's diagram that shows- Figure.docxIdentify what is inaccurate in the author's diagram that shows- Figure.docx
Identify what is inaccurate in the author's diagram that shows- Figure.docxJacobUasThomsoni
 
Identify the equation used to prepare a budget- Multiple Choice Assets.docx
Identify the equation used to prepare a budget- Multiple Choice Assets.docxIdentify the equation used to prepare a budget- Multiple Choice Assets.docx
Identify the equation used to prepare a budget- Multiple Choice Assets.docxJacobUasThomsoni
 

More from JacobUasThomsoni (20)

I can put it in a infographic or poster if you just help me with all t.docx
I can put it in a infographic or poster if you just help me with all t.docxI can put it in a infographic or poster if you just help me with all t.docx
I can put it in a infographic or poster if you just help me with all t.docx
 
Human Factors Assignment For your individual ( any medical product )pr.docx
Human Factors Assignment For your individual ( any medical product )pr.docxHuman Factors Assignment For your individual ( any medical product )pr.docx
Human Factors Assignment For your individual ( any medical product )pr.docx
 
I am working on an assignment that im builidng a game- I am wanting to.docx
I am working on an assignment that im builidng a game- I am wanting to.docxI am working on an assignment that im builidng a game- I am wanting to.docx
I am working on an assignment that im builidng a game- I am wanting to.docx
 
I a study of general incorporation laws in the Uniled States- Eric Hit.docx
I a study of general incorporation laws in the Uniled States- Eric Hit.docxI a study of general incorporation laws in the Uniled States- Eric Hit.docx
I a study of general incorporation laws in the Uniled States- Eric Hit.docx
 
Human computer interaction 1- Find five design issues with Codeblocks.docx
Human computer interaction 1- Find five design issues with Codeblocks.docxHuman computer interaction 1- Find five design issues with Codeblocks.docx
Human computer interaction 1- Find five design issues with Codeblocks.docx
 
Hypertension has been known to be called the -Silent Killer- due to wh.docx
Hypertension has been known to be called the -Silent Killer- due to wh.docxHypertension has been known to be called the -Silent Killer- due to wh.docx
Hypertension has been known to be called the -Silent Killer- due to wh.docx
 
how would i fix my code- any login doesnt work but it should retrieve.docx
how would i fix my code- any login doesnt work but it should retrieve.docxhow would i fix my code- any login doesnt work but it should retrieve.docx
how would i fix my code- any login doesnt work but it should retrieve.docx
 
I have to submit this assignment after one hour Scope Management Plan.docx
I have to submit this assignment after one hour  Scope Management Plan.docxI have to submit this assignment after one hour  Scope Management Plan.docx
I have to submit this assignment after one hour Scope Management Plan.docx
 
I have no idea what this means List all the kinds of eggs that can be.docx
I have no idea what this means List all the kinds of eggs that can be.docxI have no idea what this means List all the kinds of eggs that can be.docx
I have no idea what this means List all the kinds of eggs that can be.docx
 
If David Jones wants to save for his child's college tuition in 20 yea.docx
If David Jones wants to save for his child's college tuition in 20 yea.docxIf David Jones wants to save for his child's college tuition in 20 yea.docx
If David Jones wants to save for his child's college tuition in 20 yea.docx
 
If artificial intelligent systems that were designed to diagnose disea.docx
If artificial intelligent systems that were designed to diagnose disea.docxIf artificial intelligent systems that were designed to diagnose disea.docx
If artificial intelligent systems that were designed to diagnose disea.docx
 
If an investor requires a real return of 3- and the average inflation.docx
If an investor requires a real return of 3- and the average inflation.docxIf an investor requires a real return of 3- and the average inflation.docx
If an investor requires a real return of 3- and the average inflation.docx
 
If a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docx
If a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docxIf a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docx
If a survey of 2001 adults in a fecont year- 701 made a Now Years teso.docx
 
If a Himalayan rabbit is crossed to an albino rabbit- could one of the.docx
If a Himalayan rabbit is crossed to an albino rabbit- could one of the.docxIf a Himalayan rabbit is crossed to an albino rabbit- could one of the.docx
If a Himalayan rabbit is crossed to an albino rabbit- could one of the.docx
 
If A and B are two independent events- then P(AB)-P(B) True False.docx
If A and B are two independent events- then P(AB)-P(B) True False.docxIf A and B are two independent events- then P(AB)-P(B) True False.docx
If A and B are two independent events- then P(AB)-P(B) True False.docx
 
If 2+3i3+2i-a+ib- than Proof a2+b2-1.docx
If 2+3i3+2i-a+ib- than Proof a2+b2-1.docxIf 2+3i3+2i-a+ib- than Proof a2+b2-1.docx
If 2+3i3+2i-a+ib- than Proof a2+b2-1.docx
 
Identifying the weaknesses of a company is a factor that should be ana.docx
Identifying the weaknesses of a company is a factor that should be ana.docxIdentifying the weaknesses of a company is a factor that should be ana.docx
Identifying the weaknesses of a company is a factor that should be ana.docx
 
Identify the specific social- political- and economic challenges that.docx
Identify the specific social- political- and economic challenges that.docxIdentify the specific social- political- and economic challenges that.docx
Identify the specific social- political- and economic challenges that.docx
 
Identify what is inaccurate in the author's diagram that shows- Figure.docx
Identify what is inaccurate in the author's diagram that shows- Figure.docxIdentify what is inaccurate in the author's diagram that shows- Figure.docx
Identify what is inaccurate in the author's diagram that shows- Figure.docx
 
Identify the equation used to prepare a budget- Multiple Choice Assets.docx
Identify the equation used to prepare a budget- Multiple Choice Assets.docxIdentify the equation used to prepare a budget- Multiple Choice Assets.docx
Identify the equation used to prepare a budget- Multiple Choice Assets.docx
 

Recently uploaded

Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 

Recently uploaded (20)

YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

I have problems with running this code to get the output please help.docx

  • 1. I have problems with running this code to get the output please help import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JSlider; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Program { public static void main(String[] args) { JFrame frame = new JFrame("Data Entry"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 400); frame.setLocationRelativeTo(null); // create the timer panel JPanel timerPanel = new JPanel(); timerPanel.setBackground(Color.WHITE); JLabel timerLabel = new JLabel("Timer: 00:00", SwingConstants.CENTER); timerLabel.setFont(new Font("Courier", Font.PLAIN, 20)); Timer timer = new Timer(1000, e -> { int time = Integer.parseInt(timerLabel.getText().substring(7)) + 1; timerLabel.setText("Timer: " + String.format("%02d", time / 60) + ":" + String.format("%02d", time % 60)); }); timer.start(); timerPanel.add(timerLabel); // create the name panel JPanel namePanel = new JPanel();
  • 2. namePanel.setBackground(Color.WHITE); JTextField nameField = new JTextField(20); nameField.setFont(new Font("Courier", Font.PLAIN, 20)); nameField.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { nameField.setForeground(Color.BLUE); } @Override public void focusLost(FocusEvent e) {} }); JButton submitButton = new JButton("SUBMIT"); submitButton.setFont(new Font("Courier", Font.PLAIN, 20)); JTextArea textArea = new JTextArea(10, 40); textArea.setFont(new Font("Courier", Font.PLAIN, 20)); textArea.setEditable(false); textArea.setBorder(BorderFactory.createLineBorder(Color.BLACK)); submitButton.addActionListener(e -> { String name = nameField.getText(); if (!name.equals("")) { textArea.append(name + "n"); nameField.setText(""); } }); namePanel.add(nameField); namePanel.add(submitButton); // create the font size panel JPanel fontSizePanel = new JPanel(); fontSizePanel.setBackground(Color.WHITE); JSlider fontSizeSlider = new JSlider(JSlider.HORIZONTAL, 10, 40, 20); fontSizeSlider.setMajorTickSpacing(10); fontSizeSlider.setMinorTickSpacing(5); fontSizeSlider.setPaintTicks(true); fontSizeSlider.setPaintLabels(true); fontSizeSlider.setFont(new Font("Courier", Font.PLAIN, 20)); fontSizeSlider.addChangeListener(e -> { int fontSize = fontSizeSlider.getValue(); Font font = new Font("Courier", Font.PLAIN, fontSize); textArea.setFont(font); }); fontSizePanel.add(fontSizeSlider); // create the animation panel JPanel animationPanel = new JPanel(); animationPanel.setBackground(Color.WHITE); JLabel imageLabel = new JLabel(); ImageIcon horseIcon = new ImageIcon("horse.jpg");
  • 3. ImageIcon birdIcon = new ImageIcon("bird.jpg"); ImageIcon aeroplanIcon = new ImageIcon("aeroplan.jpg"); imageLabel.setIcon(horseIcon); JRadioButton horseButton = new JRadioButton("Horse", true); horseButton.setFont(new Font("Courier", Font.PLAIN, 20)); JRadioButton birdButton = new JRadioButton("Bird"); birdButton.setFont(new Font("Courier", Font.PLAIN, 20)); JRadioButton aeroplanButton = new JRadioButton("Aeroplan"); aeroplanButton.setFont(new Font("Courier", Font.PLAIN, 20)); horseButton.addActionListener(e -> imageLabel.setIcon(horseIcon)); birdButton.addActionListener(e -> imageLabel.setIcon(birdIcon)); aeroplanButton.addActionListener(e -> imageLabel.setIcon(aeroplanIcon)); animationPanel.add(horseButton); animationPanel.add(birdButton); animationPanel.add(aeroplanButton); animationPanel.add(imageLabel); // create the start and stop buttons JPanel buttonPanel = new JPanel(); buttonPanel.setBackground(Color.WHITE); JButton startButton = new JButton("Start"); startButton.setFont(new Font("Courier", Font.PLAIN, 20)); JButton stopButton = new JButton("Stop"); stopButton.setFont(new Font("Courier", Font.PLAIN, 20)); startButton.addActionListener(e -> { Thread animationThread = new Thread(() -> { while (true) { ImageIcon currentIcon = (ImageIcon) imageLabel.getIcon(); if (currentIcon.equals(horseIcon)) { imageLabel.setIcon(birdIcon); } else if (currentIcon.equals(birdIcon)) { imageLabel.setIcon(aeroplanIcon); } else { imageLabel.setIcon(horseIcon); } try { Thread.sleep(500); } catch (InterruptedException ex) { break; } } }); animationThread.start(); }); stopButton.addActionListener(e -> { for (Thread thread : Thread.getAllStackTraces().keySet()) { if (thread.getName().startsWith("Thread-")) {
  • 4. thread.interrupt(); } } }); buttonPanel.add(startButton); buttonPanel.add(stopButton); // create the main panel JPanel mainPanel = new JPanel(new BorderLayout()); mainPanel.add(timerPanel, BorderLayout.NORTH); mainPanel.add(namePanel, BorderLayout.CENTER); mainPanel.add(fontSizePanel, BorderLayout.SOUTH); // add the sub-panels to the main panel mainPanel.add(animationPanel, BorderLayout.EAST); mainPanel.add(buttonPanel, BorderLayout.SOUTH); // add the main panel to the frame and show the frame frame.add(mainPanel); frame.setVisible(true); // add a window listener to the frame to show a message when the program exits frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { timer.stop(); String time = timerLabel.getText().substring(7); JOptionPane.showMessageDialog(frame, "Thank you for using my program for " + time + " time."); } }); } }