SlideShare a Scribd company logo
import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import
javax.swing.JLabel; import javax.swing.JButton; import javax.swing.SwingConstants;
import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import
java.awt.FlowLayout; import java.awt.GridLayout; public class RockPaperScissorsGUI
extends JFrame { private JPanel contentPane; private JPanel humanDisplay = new
JPanel(); private JPanel computerDisplay = new JPanel(); private JLabel
winnerAnnouncement = new JLabel("Winner Shown Here"); private JPanel choicePanel =
new JPanel(); private RPSChoice rock = RPSChoice.ROCK; private RPSChoice paper
= RPSChoice.PAPER; private RPSChoice scissors = RPSChoice.SCISSORS; private
RPSChoice randChoice; private final JPanel humOrCompPanel = new JPanel();
private final JLabel lblHuman = new JLabel("Human"); private final JLabel lblComputer
= new JLabel("Computer"); private JButton btnScissors = new JButton("Scissors");
private JButton btnPaper = new JButton("Paper"); private JButton btnRock = new
JButton("Rock"); /** * Launch the application. */ public static void
main(String[] args) { EventQueue.invokeLater(new Runnable() { public void
run() { try { RockPaperScissorsGUI frame = new
RockPaperScissorsGUI(); frame.setVisible(true); } catch (Exception
e) { e.printStackTrace(); } } }); } /**
* Create the frame. */ public RockPaperScissorsGUI() { setTitle("Rock,
Paper, Scissors"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 544, 366); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new
BorderLayout(0, 0)); setContentPane(contentPane); JPanel choicePanel =
addPanels(); addButtons(choicePanel, rock, btnRock); addButtons(choicePanel,
paper, btnPaper); addButtons(choicePanel, scissors, btnScissors); } private
JPanel addPanels() { contentPane.add(humanDisplay, BorderLayout.WEST);
humanDisplay.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
contentPane.add(computerDisplay, BorderLayout.EAST);
winnerAnnouncement.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(winnerAnnouncement, BorderLayout.CENTER);
contentPane.add(choicePanel, BorderLayout.NORTH);
contentPane.add(humOrCompPanel, BorderLayout.SOUTH);
humOrCompPanel.setLayout(new GridLayout(1, 0, 0, 0));
lblHuman.setHorizontalAlignment(SwingConstants.CENTER);
humOrCompPanel.add(lblHuman);
lblComputer.setHorizontalAlignment(SwingConstants.CENTER);
humOrCompPanel.add(lblComputer); return choicePanel; } private void
addButtons(JPanel choicePanel, RPSChoice choice, JButton button ){
button.addActionListener(new ActionListener() { public void
actionPerformed(ActionEvent arg0) { humanDisplay.removeAll();
humanDisplay.add(new JLabel(choice.getImageIcon()));
computerDisplay.removeAll(); randChoice = RPSChoice.randomChoice();
computerDisplay.add(new JLabel(randChoice.getImageIcon()));
choicePanel.repaint(); choicePanel.revalidate(); } });
choicePanel.add(button); } }
Solution
import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import
javax.swing.JLabel; import javax.swing.JButton; import javax.swing.SwingConstants;
import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import
java.awt.FlowLayout; import java.awt.GridLayout; public class RockPaperScissorsGUI
extends JFrame { private JPanel contentPane; private JPanel humanDisplay = new
JPanel(); private JPanel computerDisplay = new JPanel(); private JLabel
winnerAnnouncement = new JLabel("Winner Shown Here"); private JPanel choicePanel =
new JPanel(); private RPSChoice rock = RPSChoice.ROCK; private RPSChoice paper
= RPSChoice.PAPER; private RPSChoice scissors = RPSChoice.SCISSORS; private
RPSChoice randChoice; private final JPanel humOrCompPanel = new JPanel();
private final JLabel lblHuman = new JLabel("Human"); private final JLabel lblComputer
= new JLabel("Computer"); private JButton btnScissors = new JButton("Scissors");
private JButton btnPaper = new JButton("Paper"); private JButton btnRock = new
JButton("Rock"); /** * Launch the application. */ public static void
main(String[] args) { EventQueue.invokeLater(new Runnable() { public void
run() { try { RockPaperScissorsGUI frame = new
RockPaperScissorsGUI(); frame.setVisible(true); } catch (Exception
e) { e.printStackTrace(); } } }); } /**
* Create the frame. */ public RockPaperScissorsGUI() { setTitle("Rock,
Paper, Scissors"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 544, 366); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new
BorderLayout(0, 0)); setContentPane(contentPane); JPanel choicePanel =
addPanels(); addButtons(choicePanel, rock, btnRock); addButtons(choicePanel,
paper, btnPaper); addButtons(choicePanel, scissors, btnScissors); } private
JPanel addPanels() { contentPane.add(humanDisplay, BorderLayout.WEST);
humanDisplay.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
contentPane.add(computerDisplay, BorderLayout.EAST);
winnerAnnouncement.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(winnerAnnouncement, BorderLayout.CENTER);
contentPane.add(choicePanel, BorderLayout.NORTH);
contentPane.add(humOrCompPanel, BorderLayout.SOUTH);
humOrCompPanel.setLayout(new GridLayout(1, 0, 0, 0));
lblHuman.setHorizontalAlignment(SwingConstants.CENTER);
humOrCompPanel.add(lblHuman);
lblComputer.setHorizontalAlignment(SwingConstants.CENTER);
humOrCompPanel.add(lblComputer); return choicePanel; } private void
addButtons(JPanel choicePanel, RPSChoice choice, JButton button ){
button.addActionListener(new ActionListener() { public void
actionPerformed(ActionEvent arg0) { humanDisplay.removeAll();
humanDisplay.add(new JLabel(choice.getImageIcon()));
computerDisplay.removeAll(); randChoice = RPSChoice.randomChoice();
computerDisplay.add(new JLabel(randChoice.getImageIcon()));
choicePanel.repaint(); choicePanel.revalidate(); } });
choicePanel.add(button); } }

More Related Content

Similar to import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf

i need a output screen shot for this code import java-awt-BorderLayou.docx
i need a output  screen shot for this code import java-awt-BorderLayou.docxi need a output  screen shot for this code import java-awt-BorderLayou.docx
i need a output screen shot for this code import java-awt-BorderLayou.docx
PaulntmMilleri
 
JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf
 JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf
JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf
anoopkhandelwal30
 
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityT.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
Niraj Bharambe
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
Yuichi Sakuraba
 
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdfViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
annaindustries
 
import java.awt.BorderLayout; import java.awt.Color; import java.pdf
import java.awt.BorderLayout; import java.awt.Color; import java.pdfimport java.awt.BorderLayout; import java.awt.Color; import java.pdf
import java.awt.BorderLayout; import java.awt.Color; import java.pdf
anwarfoot
 
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdfJAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
arihantmobileselepun
 
mport javafx.application.Application;import javafx.scene.Node;im.pdf
mport javafx.application.Application;import javafx.scene.Node;im.pdfmport javafx.application.Application;import javafx.scene.Node;im.pdf
mport javafx.application.Application;import javafx.scene.Node;im.pdf
anikkothari1
 
Hacking the Codename One Source Code - Part III.pdf
Hacking the Codename One Source Code - Part III.pdfHacking the Codename One Source Code - Part III.pdf
Hacking the Codename One Source Code - Part III.pdf
ShaiAlmog1
 
Hacking the Codename One Source Code - Part III - Transcript.pdf
Hacking the Codename One Source Code - Part III - Transcript.pdfHacking the Codename One Source Code - Part III - Transcript.pdf
Hacking the Codename One Source Code - Part III - Transcript.pdf
ShaiAlmog1
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
fashionfolionr
 
codigomenu-1 (1).docx
codigomenu-1 (1).docxcodigomenu-1 (1).docx
codigomenu-1 (1).docx
AnaLpez275
 
codigomenu-1.docx
codigomenu-1.docxcodigomenu-1.docx
codigomenu-1.docx
AnaLpez275
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx Workshop
Dierk König
 
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
arccreation001
 
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
AliHaiderCheema2
 
Registro de venta
Registro de ventaRegistro de venta
Registro de venta
lupe ga
 

Similar to import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf (20)

TextSearch
TextSearchTextSearch
TextSearch
 
i need a output screen shot for this code import java-awt-BorderLayou.docx
i need a output  screen shot for this code import java-awt-BorderLayou.docxi need a output  screen shot for this code import java-awt-BorderLayou.docx
i need a output screen shot for this code import java-awt-BorderLayou.docx
 
JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf
 JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf
JPasswordA.javaimport javax.swing.; import java.awt.; imp.pdf
 
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai UniversityT.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
T.Y.B.S.CS Advance Java Practicals Sem 5 Mumbai University
 
From Swing to JavaFX
From Swing to JavaFXFrom Swing to JavaFX
From Swing to JavaFX
 
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdfViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
ViewerFrame.java import javax.swing.JFrame;public class Viewer.pdf
 
import java.awt.BorderLayout; import java.awt.Color; import java.pdf
import java.awt.BorderLayout; import java.awt.Color; import java.pdfimport java.awt.BorderLayout; import java.awt.Color; import java.pdf
import java.awt.BorderLayout; import java.awt.Color; import java.pdf
 
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdfJAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
JAVA (JFrames)Dispay the color and RGB value of the background whe.pdf
 
mport javafx.application.Application;import javafx.scene.Node;im.pdf
mport javafx.application.Application;import javafx.scene.Node;im.pdfmport javafx.application.Application;import javafx.scene.Node;im.pdf
mport javafx.application.Application;import javafx.scene.Node;im.pdf
 
Hacking the Codename One Source Code - Part III.pdf
Hacking the Codename One Source Code - Part III.pdfHacking the Codename One Source Code - Part III.pdf
Hacking the Codename One Source Code - Part III.pdf
 
Hacking the Codename One Source Code - Part III - Transcript.pdf
Hacking the Codename One Source Code - Part III - Transcript.pdfHacking the Codename One Source Code - Part III - Transcript.pdf
Hacking the Codename One Source Code - Part III - Transcript.pdf
 
Test
TestTest
Test
 
I am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdfI am getting a syntax error. I cant seem to find whats causing t.pdf
I am getting a syntax error. I cant seem to find whats causing t.pdf
 
codigomenu-1 (1).docx
codigomenu-1 (1).docxcodigomenu-1 (1).docx
codigomenu-1 (1).docx
 
codigomenu-1.docx
codigomenu-1.docxcodigomenu-1.docx
codigomenu-1.docx
 
Easy Button
Easy ButtonEasy Button
Easy Button
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx Workshop
 
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
 
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
 
Registro de venta
Registro de ventaRegistro de venta
Registro de venta
 

More from nikhilpopli11

Cr (s) Solution Cr (s) .pdf
  Cr (s)                                      Solution  Cr (s)    .pdf  Cr (s)                                      Solution  Cr (s)    .pdf
Cr (s) Solution Cr (s) .pdf
nikhilpopli11
 
Purchase of treasury stock is included in the cash flows from fina.pdf
    Purchase of treasury stock is included in the cash flows from fina.pdf    Purchase of treasury stock is included in the cash flows from fina.pdf
Purchase of treasury stock is included in the cash flows from fina.pdf
nikhilpopli11
 
Tl2O and InCl3 Thalium oxide and Indium chloride..pdf
                     Tl2O and InCl3 Thalium oxide and Indium chloride..pdf                     Tl2O and InCl3 Thalium oxide and Indium chloride..pdf
Tl2O and InCl3 Thalium oxide and Indium chloride..pdf
nikhilpopli11
 
sublime means going from solid to gases without g.pdf
                     sublime means going from solid to gases without g.pdf                     sublime means going from solid to gases without g.pdf
sublime means going from solid to gases without g.pdf
nikhilpopli11
 
Scurvy is a disease resulting from a deficiency o.pdf
                     Scurvy is a disease resulting from a deficiency o.pdf                     Scurvy is a disease resulting from a deficiency o.pdf
Scurvy is a disease resulting from a deficiency o.pdf
nikhilpopli11
 
ns2np4 corresponds to group 16 elements O, S, Se,.pdf
                     ns2np4 corresponds to group 16 elements O, S, Se,.pdf                     ns2np4 corresponds to group 16 elements O, S, Se,.pdf
ns2np4 corresponds to group 16 elements O, S, Se,.pdf
nikhilpopli11
 
no reaction note Benedicts solution cannot ox.pdf
                     no reaction  note Benedicts solution cannot ox.pdf                     no reaction  note Benedicts solution cannot ox.pdf
no reaction note Benedicts solution cannot ox.pdf
nikhilpopli11
 
Mole fraction of a comonent = Moles of component.pdf
                     Mole fraction of a comonent =  Moles of component.pdf                     Mole fraction of a comonent =  Moles of component.pdf
Mole fraction of a comonent = Moles of component.pdf
nikhilpopli11
 
Its because the difference in solubility causes.pdf
                     Its because the difference in solubility causes.pdf                     Its because the difference in solubility causes.pdf
Its because the difference in solubility causes.pdf
nikhilpopli11
 
infrared spectroscopy .pdf
                     infrared spectroscopy                            .pdf                     infrared spectroscopy                            .pdf
infrared spectroscopy .pdf
nikhilpopli11
 
Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf
                     Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf                     Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf
Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf
nikhilpopli11
 
D. 3.2 x 10^-4M .pdf
                     D. 3.2 x 10^-4M                                  .pdf                     D. 3.2 x 10^-4M                                  .pdf
D. 3.2 x 10^-4M .pdf
nikhilpopli11
 
formal parameter part empty parameter delimiter + formal pa.pdf
formal parameter part empty  parameter delimiter + formal pa.pdfformal parameter part empty  parameter delimiter + formal pa.pdf
formal parameter part empty parameter delimiter + formal pa.pdf
nikhilpopli11
 
benzene Its quite obvious from the structures .pdf
                     benzene  Its quite obvious from the structures .pdf                     benzene  Its quite obvious from the structures .pdf
benzene Its quite obvious from the structures .pdf
nikhilpopli11
 
This polynomial is primeSolutionThis polynomial is prime.pdf
This polynomial is primeSolutionThis polynomial is prime.pdfThis polynomial is primeSolutionThis polynomial is prime.pdf
This polynomial is primeSolutionThis polynomial is prime.pdf
nikhilpopli11
 
There is no question !! .. reuplode it againSolutionThere is n.pdf
There is no question !! .. reuplode it againSolutionThere is n.pdfThere is no question !! .. reuplode it againSolutionThere is n.pdf
There is no question !! .. reuplode it againSolutionThere is n.pdf
nikhilpopli11
 
The Pythagorean theorem can be used only if the two vectors to be ad.pdf
The Pythagorean theorem can be used only if the two vectors to be ad.pdfThe Pythagorean theorem can be used only if the two vectors to be ad.pdf
The Pythagorean theorem can be used only if the two vectors to be ad.pdf
nikhilpopli11
 
The portrayal of Jesus in Lukes Gospel is different from the portr.pdf
The portrayal of Jesus in Lukes Gospel is different from the portr.pdfThe portrayal of Jesus in Lukes Gospel is different from the portr.pdf
The portrayal of Jesus in Lukes Gospel is different from the portr.pdf
nikhilpopli11
 
The answer is dihydrogen phosphateDihydrogen phosphate has formul.pdf
The answer is dihydrogen phosphateDihydrogen phosphate has formul.pdfThe answer is dihydrogen phosphateDihydrogen phosphate has formul.pdf
The answer is dihydrogen phosphateDihydrogen phosphate has formul.pdf
nikhilpopli11
 
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdfStores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
nikhilpopli11
 

More from nikhilpopli11 (20)

Cr (s) Solution Cr (s) .pdf
  Cr (s)                                      Solution  Cr (s)    .pdf  Cr (s)                                      Solution  Cr (s)    .pdf
Cr (s) Solution Cr (s) .pdf
 
Purchase of treasury stock is included in the cash flows from fina.pdf
    Purchase of treasury stock is included in the cash flows from fina.pdf    Purchase of treasury stock is included in the cash flows from fina.pdf
Purchase of treasury stock is included in the cash flows from fina.pdf
 
Tl2O and InCl3 Thalium oxide and Indium chloride..pdf
                     Tl2O and InCl3 Thalium oxide and Indium chloride..pdf                     Tl2O and InCl3 Thalium oxide and Indium chloride..pdf
Tl2O and InCl3 Thalium oxide and Indium chloride..pdf
 
sublime means going from solid to gases without g.pdf
                     sublime means going from solid to gases without g.pdf                     sublime means going from solid to gases without g.pdf
sublime means going from solid to gases without g.pdf
 
Scurvy is a disease resulting from a deficiency o.pdf
                     Scurvy is a disease resulting from a deficiency o.pdf                     Scurvy is a disease resulting from a deficiency o.pdf
Scurvy is a disease resulting from a deficiency o.pdf
 
ns2np4 corresponds to group 16 elements O, S, Se,.pdf
                     ns2np4 corresponds to group 16 elements O, S, Se,.pdf                     ns2np4 corresponds to group 16 elements O, S, Se,.pdf
ns2np4 corresponds to group 16 elements O, S, Se,.pdf
 
no reaction note Benedicts solution cannot ox.pdf
                     no reaction  note Benedicts solution cannot ox.pdf                     no reaction  note Benedicts solution cannot ox.pdf
no reaction note Benedicts solution cannot ox.pdf
 
Mole fraction of a comonent = Moles of component.pdf
                     Mole fraction of a comonent =  Moles of component.pdf                     Mole fraction of a comonent =  Moles of component.pdf
Mole fraction of a comonent = Moles of component.pdf
 
Its because the difference in solubility causes.pdf
                     Its because the difference in solubility causes.pdf                     Its because the difference in solubility causes.pdf
Its because the difference in solubility causes.pdf
 
infrared spectroscopy .pdf
                     infrared spectroscopy                            .pdf                     infrared spectroscopy                            .pdf
infrared spectroscopy .pdf
 
Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf
                     Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf                     Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf
Ecell = Eoxidation +Ereduction Ecell = (0.771) + .pdf
 
D. 3.2 x 10^-4M .pdf
                     D. 3.2 x 10^-4M                                  .pdf                     D. 3.2 x 10^-4M                                  .pdf
D. 3.2 x 10^-4M .pdf
 
formal parameter part empty parameter delimiter + formal pa.pdf
formal parameter part empty  parameter delimiter + formal pa.pdfformal parameter part empty  parameter delimiter + formal pa.pdf
formal parameter part empty parameter delimiter + formal pa.pdf
 
benzene Its quite obvious from the structures .pdf
                     benzene  Its quite obvious from the structures .pdf                     benzene  Its quite obvious from the structures .pdf
benzene Its quite obvious from the structures .pdf
 
This polynomial is primeSolutionThis polynomial is prime.pdf
This polynomial is primeSolutionThis polynomial is prime.pdfThis polynomial is primeSolutionThis polynomial is prime.pdf
This polynomial is primeSolutionThis polynomial is prime.pdf
 
There is no question !! .. reuplode it againSolutionThere is n.pdf
There is no question !! .. reuplode it againSolutionThere is n.pdfThere is no question !! .. reuplode it againSolutionThere is n.pdf
There is no question !! .. reuplode it againSolutionThere is n.pdf
 
The Pythagorean theorem can be used only if the two vectors to be ad.pdf
The Pythagorean theorem can be used only if the two vectors to be ad.pdfThe Pythagorean theorem can be used only if the two vectors to be ad.pdf
The Pythagorean theorem can be used only if the two vectors to be ad.pdf
 
The portrayal of Jesus in Lukes Gospel is different from the portr.pdf
The portrayal of Jesus in Lukes Gospel is different from the portr.pdfThe portrayal of Jesus in Lukes Gospel is different from the portr.pdf
The portrayal of Jesus in Lukes Gospel is different from the portr.pdf
 
The answer is dihydrogen phosphateDihydrogen phosphate has formul.pdf
The answer is dihydrogen phosphateDihydrogen phosphate has formul.pdfThe answer is dihydrogen phosphateDihydrogen phosphate has formul.pdf
The answer is dihydrogen phosphateDihydrogen phosphate has formul.pdf
 
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdfStores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
 

Recently uploaded

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 

Recently uploaded (20)

CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

import java.awt.BorderLayout; import java.awt.EventQueue; i.pdf

  • 1. import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.SwingConstants; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; import java.awt.GridLayout; public class RockPaperScissorsGUI extends JFrame { private JPanel contentPane; private JPanel humanDisplay = new JPanel(); private JPanel computerDisplay = new JPanel(); private JLabel winnerAnnouncement = new JLabel("Winner Shown Here"); private JPanel choicePanel = new JPanel(); private RPSChoice rock = RPSChoice.ROCK; private RPSChoice paper = RPSChoice.PAPER; private RPSChoice scissors = RPSChoice.SCISSORS; private RPSChoice randChoice; private final JPanel humOrCompPanel = new JPanel(); private final JLabel lblHuman = new JLabel("Human"); private final JLabel lblComputer = new JLabel("Computer"); private JButton btnScissors = new JButton("Scissors"); private JButton btnPaper = new JButton("Paper"); private JButton btnRock = new JButton("Rock"); /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { RockPaperScissorsGUI frame = new RockPaperScissorsGUI(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public RockPaperScissorsGUI() { setTitle("Rock, Paper, Scissors"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 544, 366); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel choicePanel = addPanels(); addButtons(choicePanel, rock, btnRock); addButtons(choicePanel, paper, btnPaper); addButtons(choicePanel, scissors, btnScissors); } private JPanel addPanels() { contentPane.add(humanDisplay, BorderLayout.WEST); humanDisplay.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); contentPane.add(computerDisplay, BorderLayout.EAST); winnerAnnouncement.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(winnerAnnouncement, BorderLayout.CENTER); contentPane.add(choicePanel, BorderLayout.NORTH); contentPane.add(humOrCompPanel, BorderLayout.SOUTH); humOrCompPanel.setLayout(new GridLayout(1, 0, 0, 0)); lblHuman.setHorizontalAlignment(SwingConstants.CENTER); humOrCompPanel.add(lblHuman);
  • 2. lblComputer.setHorizontalAlignment(SwingConstants.CENTER); humOrCompPanel.add(lblComputer); return choicePanel; } private void addButtons(JPanel choicePanel, RPSChoice choice, JButton button ){ button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { humanDisplay.removeAll(); humanDisplay.add(new JLabel(choice.getImageIcon())); computerDisplay.removeAll(); randChoice = RPSChoice.randomChoice(); computerDisplay.add(new JLabel(randChoice.getImageIcon())); choicePanel.repaint(); choicePanel.revalidate(); } }); choicePanel.add(button); } } Solution import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.SwingConstants; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.FlowLayout; import java.awt.GridLayout; public class RockPaperScissorsGUI extends JFrame { private JPanel contentPane; private JPanel humanDisplay = new JPanel(); private JPanel computerDisplay = new JPanel(); private JLabel winnerAnnouncement = new JLabel("Winner Shown Here"); private JPanel choicePanel = new JPanel(); private RPSChoice rock = RPSChoice.ROCK; private RPSChoice paper = RPSChoice.PAPER; private RPSChoice scissors = RPSChoice.SCISSORS; private RPSChoice randChoice; private final JPanel humOrCompPanel = new JPanel(); private final JLabel lblHuman = new JLabel("Human"); private final JLabel lblComputer = new JLabel("Computer"); private JButton btnScissors = new JButton("Scissors"); private JButton btnPaper = new JButton("Paper"); private JButton btnRock = new JButton("Rock"); /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { RockPaperScissorsGUI frame = new RockPaperScissorsGUI(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. */ public RockPaperScissorsGUI() { setTitle("Rock, Paper, Scissors"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 544, 366); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel choicePanel =
  • 3. addPanels(); addButtons(choicePanel, rock, btnRock); addButtons(choicePanel, paper, btnPaper); addButtons(choicePanel, scissors, btnScissors); } private JPanel addPanels() { contentPane.add(humanDisplay, BorderLayout.WEST); humanDisplay.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); contentPane.add(computerDisplay, BorderLayout.EAST); winnerAnnouncement.setHorizontalAlignment(SwingConstants.CENTER); contentPane.add(winnerAnnouncement, BorderLayout.CENTER); contentPane.add(choicePanel, BorderLayout.NORTH); contentPane.add(humOrCompPanel, BorderLayout.SOUTH); humOrCompPanel.setLayout(new GridLayout(1, 0, 0, 0)); lblHuman.setHorizontalAlignment(SwingConstants.CENTER); humOrCompPanel.add(lblHuman); lblComputer.setHorizontalAlignment(SwingConstants.CENTER); humOrCompPanel.add(lblComputer); return choicePanel; } private void addButtons(JPanel choicePanel, RPSChoice choice, JButton button ){ button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { humanDisplay.removeAll(); humanDisplay.add(new JLabel(choice.getImageIcon())); computerDisplay.removeAll(); randChoice = RPSChoice.randomChoice(); computerDisplay.add(new JLabel(randChoice.getImageIcon())); choicePanel.repaint(); choicePanel.revalidate(); } }); choicePanel.add(button); } }