sicotic87

HomeScreenGUIAdditions

Dec 12th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.59 KB | None | 0 0
  1. //HomeScreen.java
  2. //Class #5
  3.  
  4.  
  5. package deskcentermain;
  6.  
  7. import javax.swing.*;
  8.  
  9. import java.awt.*;
  10. import java.awt.event.*;
  11. import java.io.*;
  12.  
  13.  
  14. public class HomeScreen extends JFrame{
  15.                
  16.     private JPanel panel;
  17.     private JPanel panel2;
  18.     private JPanel panel3;
  19.     private JPanel panel4;
  20.     private JPanel panel5;
  21.     private JPanel panel6;
  22.     private JLabel label;
  23.     private JLabel titleLabel;
  24.     private JLabel subTitle;
  25.     private JButton button1;
  26.     private JButton button2;
  27.     private JButton button3;
  28.     private JButton button4;
  29.     private JButton button5;
  30.     private JButton button6;
  31.     private JButton button7;
  32.     private JButton button8;
  33.     private JButton button9;
  34.     private JButton button10;
  35.     private JButton button11;
  36.     private JButton button12;
  37.     private JButton button13;
  38.     private JButton exitButton;
  39.                
  40.     private final int WIDTH = 420;
  41.     private final int LENGTH = 150;
  42.            
  43.     public HomeScreen() {
  44.        
  45.         super("Shapes Calculator v1.0.1");
  46.        
  47.         this.titleLabel = new JLabel("Shapes Calculator", SwingConstants.LEFT);
  48.         this.subTitle = new JLabel("\nv1.0.1", SwingConstants.LEFT);
  49.         this.titleLabel.setVerticalAlignment(SwingConstants.TOP);
  50.         this.titleLabel.setFont(new Font("Arial", Font.BOLD, 14));
  51.         this.subTitle.setVerticalAlignment(SwingConstants.TOP);
  52.         this.subTitle.setFont(new Font("Arial", Font.ITALIC, 8));
  53.                        
  54.         this.setLayout(new FlowLayout());
  55.                    
  56.         this.setSize(WIDTH, LENGTH);
  57.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58.         this.setLocationRelativeTo(null);
  59.         buildHomeScreenPanel();
  60.         add(panel);
  61.         setVisible(true);        
  62.     }
  63.    
  64.     private void buildHomeScreenPanel(){
  65.        
  66.         panel = new JPanel();
  67.      
  68.         this.label = new JLabel("Please choose an option.", SwingConstants.CENTER);
  69.         this.label.setVerticalAlignment(SwingConstants.BOTTOM);
  70.         this.label.setFont(new Font("Arial", Font.PLAIN, 16));
  71.         this.button1 = new JButton("Circle");
  72.         this.button2 = new JButton("Parallelogram");
  73.         this.button3 = new JButton("Pyramid");
  74.         this.button4 = new JButton("Rectangle");
  75.         this.button5 = new JButton("Solid Rectangle");
  76.         this.button6 = new JButton("Sphere");
  77.         this.button7 = new JButton("Square");
  78.         this.button8 = new JButton("Triangle");
  79.         this.button9 = new JButton("Cube");
  80.         this.button10 = new JButton("Trapezoid");
  81.         this.button11 = new JButton("Prism");
  82.         this.button12 = new JButton("Cylinder");
  83.         this.button13 = new JButton("Cone");
  84.        
  85.         panel.add(titleLabel);
  86.         panel.add(subTitle);
  87.         panel.add(this.label);
  88.         panel.add(this.label);
  89.         panel.add(this.button1);
  90.         panel.add(this.button2);
  91.         panel.add(this.button3);
  92.         panel.add(this.button4);
  93.         panel.add(this.button5);
  94.         panel.add(this.button6);
  95.         panel.add(this.button7);
  96.         panel.add(this.button8);
  97.         panel.add(this.button9);
  98.         panel.add(this.button10);
  99.         panel.add(this.button11);
  100.         panel.add(this.button12);
  101.         panel.add(this.button13);
  102.                
  103.         /*this.add(panel);
  104.                
  105.         panel2 = new JPanel();
  106.                
  107.         this.button = new JButton("Trapezoid");
  108.                
  109.         panel2.add(this.button);
  110.        
  111.                
  112.         this.add(panel2);
  113.                
  114.         panel3 = new JPanel();
  115.                
  116.         this.button2 = new JButton("Square");
  117.                
  118.         panel3.add(this.button2);
  119.        
  120.                
  121.         this.add(panel3);
  122.                
  123.         panel4 = new JPanel();
  124.                
  125.         this.button3 = new JButton("Parallelogram");
  126.                
  127.         panel4.add(this.button3);
  128.        
  129.                
  130.         this.add(panel4);
  131.                
  132.         this.setVisible(true);
  133.                
  134.         panel5 = new JPanel();
  135.            
  136.         this.button4 = new JButton("Rectangle");
  137.                
  138.         panel5.add(this.button4);
  139.        
  140.         this.add(panel5);
  141.        
  142.        
  143.         panel6 = new JPanel();
  144.        
  145.         this.exitButton = new JButton("<< Exit");
  146.        
  147.         panel6.add(this.exitButton);
  148.        
  149.         this.add(panel6);
  150.        
  151.        */
  152.         //add actionListners to the buttons within the program
  153.         //so when there clicked, they'll actually do something
  154.         button1.addActionListener(new ShapeButtonListener());
  155.         button2.addActionListener(new ShapeButtonListener());
  156.         button3.addActionListener(new ShapeButtonListener());
  157.         button4.addActionListener(new ShapeButtonListener());
  158.         button5.addActionListener(new ShapeButtonListener());
  159.         button6.addActionListener(new ShapeButtonListener());
  160.         button7.addActionListener(new ShapeButtonListener());
  161.         button8.addActionListener(new ShapeButtonListener());
  162.         button9.addActionListener(new ShapeButtonListener());
  163.         button10.addActionListener(new ShapeButtonListener());
  164.         button11.addActionListener(new ShapeButtonListener());
  165.         button12.addActionListener(new ShapeButtonListener());
  166.         button13.addActionListener(new ShapeButtonListener());
  167.         exitButton.addActionListener(new ShapeButtonListener());
  168.     }
  169.                
  170.    
  171. private class ShapeButtonListener implements ActionListener {
  172.    
  173.     public void actionPerformed (ActionEvent e){
  174.         if (e.getSource() == button1) {
  175.             //Circle                                   *Should call a method or create a new instance of a trapezoid class.
  176.             Circle circle = new Circle();
  177.         }else if (e.getSource() == button2){
  178.             //Parallelogram                                    *Same with the rest of the shapes and so on.
  179.             Parallelogram parallelogram = new Parallelogram();
  180.         }else if (e.getSource() == button3){
  181.             //Pyramid
  182.             Pyramid pyramid = new Pyramid();
  183.         }else if (e.getSource() == button4){
  184.             Rectangle rectangle = new Rectangle();
  185.         }else if (e.getSource() == button5){
  186.             //Solid Rectangle                                 *Same with the rest of the shapes and so on.
  187.             RectangleSolid rectanglesolid = new RectangleSolid();
  188.         }else if (e.getSource() == button6){
  189.             //Sphere                                    *Same with the rest of the shapes and so on.
  190.             Sphere sphere = new Sphere();
  191.         }else if (e.getSource() == button7){
  192.             //Square                                    *Same with the rest of the shapes and so on.
  193.             Square square = new Square();
  194.         }else if (e.getSource() == button8){
  195.             //Triangle                                    *Same with the rest of the shapes and so on.
  196.             Triangle triangle = new Triangle();
  197.         }else if (e.getSource() == button9){
  198.             //Cube                                  *Same with the rest of the shapes and so on.
  199.             Cube cube = new Cube();
  200.         }else if (e.getSource() == button10){
  201.             //Trapezoid                                    *Same with the rest of the shapes and so on.
  202.             Trapezoid trapezoid = new Trapezoid();
  203.         }else if (e.getSource() == button11){
  204.             //Prism                                 *Same with the rest of the shapes and so on.
  205.             Prism prism = new Prism();
  206.         }else if (e.getSource() == button12){
  207.             //Cylinder                                    *Same with the rest of the shapes and so on.
  208.             Cylinder cylinder = new Cylinder();
  209.         }else if (e.getSource() == button13){
  210.             //Cone                                    *Same with the rest of the shapes and so on.
  211.             Cones cones = new Cones();
  212.         }else if (e.getSource() == exitButton){
  213.             try{
  214.                 DeskLogin login = new DeskLogin();
  215.                 setVisible(false);
  216.                 dispose();
  217.             } catch (IOException ed){
  218.                 JOptionPane.showMessageDialog(null, "An error occurred.");
  219.             }
  220.            
  221.            
  222.         }
  223.     }
  224. } //end of private class
  225.                
  226.        
  227. }
  228.  
  229.  
  230. /* Whoever has the class names for the shapes can fill in ShapeButtonListener. This is an easier
  231.  * way to write what to do if a certain button is clicked (beats the shit out of writing 4 classes)
  232.  * and keeps the code very clean and effective.
  233.  * Feel free to add what you like or need.
  234.  *
  235.  * -Graham S.
  236.  */
Advertisement
Add Comment
Please, Sign In to add comment