Advertisement
ConnorSiebens

SkateboardDesign

Mar 11th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.event.*;
  3. import java.awt.*;
  4.  
  5. public class SkateboardDesign extends JFrame {
  6.     /**
  7.      * @ConnorSiebens
  8.      * #6 Skateboard Designer p.913
  9.      */
  10.     private JPanel deckPanel;
  11.     private final String[] decks = {"The master thrasher","The dictator","The street king"};
  12.     private JComboBox<String> deckList;
  13.     private JPanel truckPanel;
  14.     private final String[] trucks = {"7.75 inch axle","8 inch axle","8.5 inch axle"};
  15.     private JComboBox<String> truckList;
  16.     private JPanel wheelPanel;
  17.     private final String[] wheels = {"51 mm","55 mm","58 mm","61 mm"};
  18.     private JComboBox<String> wheelList;
  19.     private double total=0;
  20.     private int deckTotal=0;
  21.     private int truckTotal=0;
  22.     private int wheelTotal=0;
  23.    
  24.     public SkateboardDesign() {
  25.         setTitle("Joe's Automotive");
  26.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  27.         setLayout(new BorderLayout() );
  28.    
  29.         buildDeckPanel();
  30.         buildTruckPanel();
  31.         buildWheelPanel();
  32.        
  33.         add(deckPanel, BorderLayout.EAST);
  34.         add(truckPanel, BorderLayout.NORTH);
  35.         add(wheelPanel, BorderLayout.WEST);
  36.        
  37.         pack();
  38.         setVisible(true);
  39.     }
  40.     private void buildDeckPanel() {
  41.           deckPanel = new JPanel();
  42.           deckList = new JComboBox<String>(decks);
  43.           deckList.addActionListener(new deckListener());
  44.           deckPanel.add(deckList);
  45.      }
  46.     private void buildTruckPanel() {
  47.           truckPanel = new JPanel();
  48.           truckList = new JComboBox<String>(trucks);
  49.           truckList.addActionListener(new truckListener());
  50.           truckPanel.add(truckList);
  51.     }
  52.     private void buildWheelPanel() {
  53.           wheelPanel = new JPanel();
  54.           wheelList = new JComboBox<String>(wheels);
  55.           wheelList.addActionListener(new wheelListener());
  56.           wheelPanel.add(wheelList);
  57.      }
  58.     private class deckListener implements ActionListener {
  59.          public void actionPerformed(ActionEvent e) {
  60.              String selection = (String) deckList.getSelectedItem();
  61.              if(selection.equals("The master thrasher")) {
  62.                  deckTotal=60;
  63.                  total=deckTotal+truckTotal+wheelTotal;
  64.                  System.out.println(total);
  65.              }else if(selection.equals("The dictator")) {
  66.                  deckTotal=45;
  67.                  total=deckTotal+truckTotal+wheelTotal;
  68.                  System.out.println(total);
  69.              }else {
  70.                  deckTotal=50;
  71.                  total=deckTotal+truckTotal+wheelTotal;
  72.                  System.out.println(total);
  73.              }
  74.         }
  75.     }    
  76.     private class truckListener implements ActionListener {
  77.          public void actionPerformed(ActionEvent e) {
  78.              String selection = (String) truckList.getSelectedItem();
  79.              if(selection.equals("7.75 inch axle")) {
  80.                  truckTotal=35;
  81.                  total=deckTotal+truckTotal+wheelTotal;
  82.                  System.out.println(total);
  83.              }else if(selection.equals("8 inch axle")) {
  84.                  truckTotal=40;
  85.                  total=deckTotal+truckTotal+wheelTotal;
  86.                  System.out.println(total);
  87.              }else {
  88.                  truckTotal=45;
  89.                  total=deckTotal+truckTotal+wheelTotal;
  90.                  System.out.println(total);
  91.              }
  92.         }
  93.     }
  94.     private class wheelListener implements ActionListener {
  95.          public void actionPerformed(ActionEvent e) {
  96.              String selection = (String) wheelList.getSelectedItem();
  97.              if(selection.equals("51 mm")) {
  98.                  wheelTotal=20;
  99.                  total=deckTotal+truckTotal+wheelTotal;
  100.                  System.out.println(total);
  101.              }else if(selection.equals("55 mm")) {
  102.                  wheelTotal=22;
  103.                  total=deckTotal+truckTotal+wheelTotal;
  104.                  System.out.println(total);
  105.              }else if(selection.equals("58 mm")){
  106.                  wheelTotal=24;
  107.                  total=deckTotal+truckTotal+wheelTotal;
  108.                  System.out.println(total);
  109.              }else {
  110.                  wheelTotal=61;
  111.                  total=deckTotal+truckTotal+wheelTotal;
  112.                  System.out.println(total);
  113.              }
  114.         }
  115.     }
  116.     public static void main(String[] args) {
  117.         new SkateboardDesign();
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement