Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.text.NumberFormat;
- import javax.swing.JOptionPane;
- import javax.swing.event.AncestorListener;
- public class Headclass extends JFrame
- {
- public Calculation calc;
- private Layout layout;
- public String currentPrinterName = "Printer";
- public int currentPrinterBooster = 1;
- Color bcColor = new Color(0x2fd51a);
- Color paneColor = new Color(0x00ff1a);
- public void startApplication()
- {
- layout = new Layout();
- layout.setVisible(true);
- setResizable(false);
- setVisible(true);
- setSize(720,340);
- setLocation(0,0);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setUpEventsForMenu();
- calc = new Calculation();
- layout.setPreferredSize(new Dimension(560,320));
- Container pane = this.getContentPane();
- pane.setLayout(new FlowLayout());
- pane.add(layout);
- this.pack();
- pane.setBackground(paneColor);
- layout.setBackground(bcColor);
- setTitle("Zarp Calculator");
- }
- private String getChoosenPrinter()
- {
- Object[] possibilities = {"Topaz Printer", "Amethyst Printer",
- "Emerald Printer", "Sapphire Printer" ,"Normal Printer" , "Ruby Printer" ,
- "Gold Printer" , "Nuclear Printer" , "All Shop Printers" , "Diamond Printer",
- "Black Diamond Printer" , "GenCorp Printer" , "Magik Printer" , "Iridium Printer",
- "Festive Printer" , "Golden Plated Printer", "Uranium Printer",};
- String s = (String)JOptionPane.showInputDialog(
- layout,
- "Choose a Printer","",
- JOptionPane.PLAIN_MESSAGE,
- null,
- possibilities,
- "1");
- return s;
- }
- private int getChoosenPrinterBooster()
- {
- Object[] possibilities = {"1", "2", "3", "4", "5"};
- String s = (String)JOptionPane.showInputDialog(
- layout,
- "Choose a Printer Booster","",
- JOptionPane.PLAIN_MESSAGE,
- null,
- possibilities,
- "1");
- int pb = Integer.parseInt(s);
- return pb;
- }
- private void setUpEventsForMenu()
- {
- layout.printerBtn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- String currentPrinterName = getChoosenPrinter();
- layout.printerBtn.setText(currentPrinterName);
- calc.printerName = currentPrinterName;
- }
- });
- layout.boosterBtn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- int currentPrinterBooster = getChoosenPrinterBooster();
- layout.boosterBtn.setText(currentPrinterBooster + "");
- calc.printerBooster = currentPrinterBooster;
- }
- });
- layout.addPrinterBtn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if(layout.printerBtn.getText() == "Printer")
- {
- ButtonMsg("Please choose a Printer!");
- }
- else
- {
- calc.calculatePrinters();
- layout.addRow(layout.jt, calc.printerName, calc.printerBooster, calc.currentTotalAmmount);
- }
- }
- });
- layout.delPrinterBtn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- if(calc.printerName.equals("Uranium Printer") && calc.uraniumAmount != 0)
- {
- calc.uraniumAmount -= calc.currentUraniumAmount;
- }
- else
- {
- int tal1 = layout.getLastAmmount();
- calc.subtractTal(tal1);
- }
- layout.removeLastRow(layout.jt);
- }
- });
- layout.calculateBtn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- String s = NumberFormat.getIntegerInstance().format(calc.overallTotalAmmount);
- String str = String.format("%,d", calc.overallTotalAmmount);
- ButtonMsg("You earn " + str + ""
- + " money per hour and "+ calc.uraniumAmount + " Units per hour");
- }
- });
- layout.exitBtn.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- System.exit(0);
- }
- });
- }
- public void ButtonMsg(String msg)
- {
- JOptionPane.showMessageDialog(this, msg);
- }
- public static void main(String[] args)
- {
- Headclass hc = new Headclass();
- hc.startApplication();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement