Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.07 KB | None | 0 0
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import java.text.NumberFormat;
  5.  
  6. import javax.swing.JOptionPane;
  7. import javax.swing.event.AncestorListener;
  8.  
  9. public class Headclass extends JFrame
  10. {
  11. public Calculation calc;
  12. private Layout layout;
  13. public String currentPrinterName = "Printer";
  14. public int currentPrinterBooster = 1;
  15. Color bcColor = new Color(0x2fd51a);
  16. Color paneColor = new Color(0x00ff1a);
  17.  
  18. public void startApplication()
  19. {
  20. layout = new Layout();
  21. layout.setVisible(true);
  22. setResizable(false);
  23. setVisible(true);
  24. setSize(720,340);
  25. setLocation(0,0);
  26. setDefaultCloseOperation(EXIT_ON_CLOSE);
  27.  
  28. setUpEventsForMenu();
  29.  
  30. calc = new Calculation();
  31. layout.setPreferredSize(new Dimension(560,320));
  32. Container pane = this.getContentPane();
  33. pane.setLayout(new FlowLayout());
  34. pane.add(layout);
  35. this.pack();
  36. pane.setBackground(paneColor);
  37. layout.setBackground(bcColor);
  38. setTitle("Zarp Calculator");
  39.  
  40. }
  41.  
  42. private String getChoosenPrinter()
  43. {
  44. Object[] possibilities = {"Topaz Printer", "Amethyst Printer",
  45. "Emerald Printer", "Sapphire Printer" ,"Normal Printer" , "Ruby Printer" ,
  46. "Gold Printer" , "Nuclear Printer" , "All Shop Printers" , "Diamond Printer",
  47. "Black Diamond Printer" , "GenCorp Printer" , "Magik Printer" , "Iridium Printer",
  48. "Festive Printer" , "Golden Plated Printer", "Uranium Printer",};
  49. String s = (String)JOptionPane.showInputDialog(
  50. layout,
  51. "Choose a Printer","",
  52. JOptionPane.PLAIN_MESSAGE,
  53. null,
  54. possibilities,
  55. "1");
  56. return s;
  57. }
  58.  
  59. private int getChoosenPrinterBooster()
  60. {
  61. Object[] possibilities = {"1", "2", "3", "4", "5"};
  62. String s = (String)JOptionPane.showInputDialog(
  63. layout,
  64. "Choose a Printer Booster","",
  65. JOptionPane.PLAIN_MESSAGE,
  66. null,
  67. possibilities,
  68. "1");
  69. int pb = Integer.parseInt(s);
  70. return pb;
  71. }
  72.  
  73.  
  74. private void setUpEventsForMenu()
  75. {
  76. layout.printerBtn.addActionListener(new ActionListener()
  77. {
  78. public void actionPerformed(ActionEvent e)
  79. {
  80. String currentPrinterName = getChoosenPrinter();
  81. layout.printerBtn.setText(currentPrinterName);
  82. calc.printerName = currentPrinterName;
  83. }
  84. });
  85.  
  86. layout.boosterBtn.addActionListener(new ActionListener()
  87. {
  88. public void actionPerformed(ActionEvent e)
  89. {
  90. int currentPrinterBooster = getChoosenPrinterBooster();
  91. layout.boosterBtn.setText(currentPrinterBooster + "");
  92. calc.printerBooster = currentPrinterBooster;
  93. }
  94. });
  95.  
  96. layout.addPrinterBtn.addActionListener(new ActionListener()
  97. {
  98. public void actionPerformed(ActionEvent e)
  99. {
  100. if(layout.printerBtn.getText() == "Printer")
  101. {
  102. ButtonMsg("Please choose a Printer!");
  103.  
  104. }
  105.  
  106. else
  107. {
  108. calc.calculatePrinters();
  109. layout.addRow(layout.jt, calc.printerName, calc.printerBooster, calc.currentTotalAmmount);
  110. }
  111. }
  112. });
  113.  
  114. layout.delPrinterBtn.addActionListener(new ActionListener()
  115. {
  116. public void actionPerformed(ActionEvent e)
  117. {
  118. if(calc.printerName.equals("Uranium Printer") && calc.uraniumAmount != 0)
  119. {
  120. calc.uraniumAmount -= calc.currentUraniumAmount;
  121. }
  122. else
  123. {
  124. int tal1 = layout.getLastAmmount();
  125. calc.subtractTal(tal1);
  126. }
  127. layout.removeLastRow(layout.jt);
  128. }
  129. });
  130.  
  131.  
  132. layout.calculateBtn.addActionListener(new ActionListener()
  133. {
  134. public void actionPerformed(ActionEvent e)
  135. {
  136. String s = NumberFormat.getIntegerInstance().format(calc.overallTotalAmmount);
  137. String str = String.format("%,d", calc.overallTotalAmmount);
  138. ButtonMsg("You earn " + str + ""
  139. + " money per hour and "+ calc.uraniumAmount + " Units per hour");
  140. }
  141. });
  142.  
  143. layout.exitBtn.addActionListener(new ActionListener()
  144. {
  145. public void actionPerformed(ActionEvent e)
  146. {
  147. System.exit(0);
  148. }
  149. });
  150. }
  151.  
  152. public void ButtonMsg(String msg)
  153. {
  154. JOptionPane.showMessageDialog(this, msg);
  155. }
  156.  
  157. public static void main(String[] args)
  158. {
  159. Headclass hc = new Headclass();
  160. hc.startApplication();
  161. }
  162. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement