SlideShare a Scribd company logo
1 of 3
Download to read offline
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.docxPaulntmMilleri
 
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.pdfanoopkhandelwal30
 
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 UniversityNiraj Bharambe
 
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.pdfannaindustries
 
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.pdfanwarfoot
 
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.pdfarihantmobileselepun
 
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.pdfanikkothari1
 
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.pdfShaiAlmog1
 
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.pdfShaiAlmog1
 
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.pdffashionfolionr
 
codigomenu-1 (1).docx
codigomenu-1 (1).docxcodigomenu-1 (1).docx
codigomenu-1 (1).docxAnaLpez275
 
codigomenu-1.docx
codigomenu-1.docxcodigomenu-1.docx
codigomenu-1.docxAnaLpez275
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx WorkshopDierk 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.pdfarccreation001
 
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
 
Registro de venta
Registro de ventaRegistro de venta
Registro de ventalupe 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) .pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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..pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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,.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
infrared spectroscopy .pdf
                     infrared spectroscopy                            .pdf                     infrared spectroscopy                            .pdf
infrared spectroscopy .pdfnikhilpopli11
 
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) + .pdfnikhilpopli11
 
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 .pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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 .pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
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.pdfnikhilpopli11
 
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdfStores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdf
Stores Ledger Account(FIFO)DateReceiptsIssuesBalanceUnits.pdfnikhilpopli11
 

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

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Recently uploaded (20)

Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

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); } }