Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.*;
- import java.awt.*;
- public class SkateboardDesign extends JFrame {
- /**
- * @ConnorSiebens
- * #6 Skateboard Designer p.913
- */
- private JPanel deckPanel;
- private final String[] decks = {"The master thrasher","The dictator","The street king"};
- private JComboBox<String> deckList;
- private JPanel truckPanel;
- private final String[] trucks = {"7.75 inch axle","8 inch axle","8.5 inch axle"};
- private JComboBox<String> truckList;
- private JPanel wheelPanel;
- private final String[] wheels = {"51 mm","55 mm","58 mm","61 mm"};
- private JComboBox<String> wheelList;
- private double total=0;
- private int deckTotal=0;
- private int truckTotal=0;
- private int wheelTotal=0;
- public SkateboardDesign() {
- setTitle("Joe's Automotive");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setLayout(new BorderLayout() );
- buildDeckPanel();
- buildTruckPanel();
- buildWheelPanel();
- add(deckPanel, BorderLayout.EAST);
- add(truckPanel, BorderLayout.NORTH);
- add(wheelPanel, BorderLayout.WEST);
- pack();
- setVisible(true);
- }
- private void buildDeckPanel() {
- deckPanel = new JPanel();
- deckList = new JComboBox<String>(decks);
- deckList.addActionListener(new deckListener());
- deckPanel.add(deckList);
- }
- private void buildTruckPanel() {
- truckPanel = new JPanel();
- truckList = new JComboBox<String>(trucks);
- truckList.addActionListener(new truckListener());
- truckPanel.add(truckList);
- }
- private void buildWheelPanel() {
- wheelPanel = new JPanel();
- wheelList = new JComboBox<String>(wheels);
- wheelList.addActionListener(new wheelListener());
- wheelPanel.add(wheelList);
- }
- private class deckListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- String selection = (String) deckList.getSelectedItem();
- if(selection.equals("The master thrasher")) {
- deckTotal=60;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else if(selection.equals("The dictator")) {
- deckTotal=45;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else {
- deckTotal=50;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }
- }
- }
- private class truckListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- String selection = (String) truckList.getSelectedItem();
- if(selection.equals("7.75 inch axle")) {
- truckTotal=35;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else if(selection.equals("8 inch axle")) {
- truckTotal=40;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else {
- truckTotal=45;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }
- }
- }
- private class wheelListener implements ActionListener {
- public void actionPerformed(ActionEvent e) {
- String selection = (String) wheelList.getSelectedItem();
- if(selection.equals("51 mm")) {
- wheelTotal=20;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else if(selection.equals("55 mm")) {
- wheelTotal=22;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else if(selection.equals("58 mm")){
- wheelTotal=24;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }else {
- wheelTotal=61;
- total=deckTotal+truckTotal+wheelTotal;
- System.out.println(total);
- }
- }
- }
- public static void main(String[] args) {
- new SkateboardDesign();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement