Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. //Pizza Order Application
  2. import javax.swing.*;
  3. import java.aw.event.*;
  4. import java.swing.border*;
  5.  
  6. public class Pizza extends JFrame
  7. {
  8. public static void main(String [ ] args)
  9. {
  10. new Pizza();
  11. }
  12.  
  13. private JButton buttonOk;
  14. private JRadioButton small, medium, large;
  15. private JCheckBox pepporoni, mushrooms, anchovies;
  16.  
  17. public Pizza()
  18. {
  19. this.setSize(320,200);
  20. this.setTitle("Order Your Pizza);
  21. set.DefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  22. ButtonListener b1 = new ButtonListener();
  23. JPanel mainPanel = new Panel();
  24. JPanel sizePanel = new JPanel();
  25. Border b1 = BorderFactory.createTitledBorder("Size");
  26. sizePanel.setBorder(b1);
  27. ButtonGroup sizeGroup = new ButtonGroup();
  28. small = new JRadioButton("Small");
  29. small.setSelected(true);
  30. sizePanel.add(small);
  31. sizeGroup.add(small);
  32. medium = new JRadioButton("Medium");
  33. sizePanel.add(medium);
  34. sizeGroup.add(large);
  35. mainPanel.add(sizePanel);
  36. JPanel topPanel = new JPanel();
  37. Border b2 = BorderFactory.createTitleBorder("toppings*);
  38. topPanel.setBorder(b2);
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. mushrooms = new JCheckBox("Mushrooms");
  46. topPanel.add(mushrooms);
  47.  
  48.  
  49. anchovies = new JCheckBox("Anchovies");
  50. topPanel.add(anchovies);
  51.  
  52. pepperoni = new JCheckBox("Pepperoni");
  53. topPanel.add(pepperoni);
  54.  
  55. mainPanel.add(topPanel);
  56.  
  57. buttonOk = new JButton("OK");
  58. buttonOK.addActionListener(b1);
  59. mainPanel.add(buttonOK);
  60.  
  61. this.add(mainPanel);
  62. this.setVisible(true);
  63. }
  64.  
  65. private class ButtonListener implements ActionListener
  66. {
  67. public void actionPerformed(ActionEvent e)
  68. if (e.getSource() == buttonOK)
  69. {
  70. String tops = "";
  71. if (pepporoni.isSelected())
  72. tops += "Pepperoni \n";
  73. if (mushrooms.isSelected())
  74. tops += "Mushrooms \n";
  75. if(anchovies.isSelected())
  76. tops +="Anchovies \n";
  77.  
  78. String msg = "You ordered a ";
  79. if (small.isSelected())
  80. msg += "small pizza with";
  81. if(medium.isSelected())
  82. msg+= "medium pizza with";
  83. if(large.isSelected())
  84. msg+="small pizza with";
  85.  
  86. if(tops.equals(""))
  87. msg += "no toppings.";
  88. else
  89. msg += "the following toppings: \n" + tops;
  90.  
  91.  
  92.  
  93. JOptionPane.showMessageDialog(buttonOk, msg, "Your Order", JOptionsPane.INFORMATION_MESSAGE);
  94.  
  95. pepperoni.setSelected(false);
  96. mushrooms.setSelected(false);
  97. anchovies.setSelected(false);
  98. small.setSelected(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement