Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //HomeScreen.java
- //Class #5
- package deskcentermain;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- public class HomeScreen extends JFrame{
- private JPanel panel;
- private JPanel panel2;
- private JPanel panel3;
- private JPanel panel4;
- private JPanel panel5;
- private JPanel panel6;
- private JLabel label;
- private JLabel titleLabel;
- private JLabel subTitle;
- private JButton button1;
- private JButton button2;
- private JButton button3;
- private JButton button4;
- private JButton button5;
- private JButton button6;
- private JButton button7;
- private JButton button8;
- private JButton button9;
- private JButton button10;
- private JButton button11;
- private JButton button12;
- private JButton button13;
- private JButton exitButton;
- private final int WIDTH = 420;
- private final int LENGTH = 150;
- public HomeScreen() {
- super("Shapes Calculator v1.0.1");
- this.titleLabel = new JLabel("Shapes Calculator", SwingConstants.LEFT);
- this.subTitle = new JLabel("\nv1.0.1", SwingConstants.LEFT);
- this.titleLabel.setVerticalAlignment(SwingConstants.TOP);
- this.titleLabel.setFont(new Font("Arial", Font.BOLD, 14));
- this.subTitle.setVerticalAlignment(SwingConstants.TOP);
- this.subTitle.setFont(new Font("Arial", Font.ITALIC, 8));
- this.setLayout(new FlowLayout());
- this.setSize(WIDTH, LENGTH);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- buildHomeScreenPanel();
- add(panel);
- setVisible(true);
- }
- private void buildHomeScreenPanel(){
- panel = new JPanel();
- this.label = new JLabel("Please choose an option.", SwingConstants.CENTER);
- this.label.setVerticalAlignment(SwingConstants.BOTTOM);
- this.label.setFont(new Font("Arial", Font.PLAIN, 16));
- this.button1 = new JButton("Circle");
- this.button2 = new JButton("Parallelogram");
- this.button3 = new JButton("Pyramid");
- this.button4 = new JButton("Rectangle");
- this.button5 = new JButton("Solid Rectangle");
- this.button6 = new JButton("Sphere");
- this.button7 = new JButton("Square");
- this.button8 = new JButton("Triangle");
- this.button9 = new JButton("Cube");
- this.button10 = new JButton("Trapezoid");
- this.button11 = new JButton("Prism");
- this.button12 = new JButton("Cylinder");
- this.button13 = new JButton("Cone");
- panel.add(titleLabel);
- panel.add(subTitle);
- panel.add(this.label);
- panel.add(this.label);
- panel.add(this.button1);
- panel.add(this.button2);
- panel.add(this.button3);
- panel.add(this.button4);
- panel.add(this.button5);
- panel.add(this.button6);
- panel.add(this.button7);
- panel.add(this.button8);
- panel.add(this.button9);
- panel.add(this.button10);
- panel.add(this.button11);
- panel.add(this.button12);
- panel.add(this.button13);
- /*this.add(panel);
- panel2 = new JPanel();
- this.button = new JButton("Trapezoid");
- panel2.add(this.button);
- this.add(panel2);
- panel3 = new JPanel();
- this.button2 = new JButton("Square");
- panel3.add(this.button2);
- this.add(panel3);
- panel4 = new JPanel();
- this.button3 = new JButton("Parallelogram");
- panel4.add(this.button3);
- this.add(panel4);
- this.setVisible(true);
- panel5 = new JPanel();
- this.button4 = new JButton("Rectangle");
- panel5.add(this.button4);
- this.add(panel5);
- panel6 = new JPanel();
- this.exitButton = new JButton("<< Exit");
- panel6.add(this.exitButton);
- this.add(panel6);
- */
- //add actionListners to the buttons within the program
- //so when there clicked, they'll actually do something
- button1.addActionListener(new ShapeButtonListener());
- button2.addActionListener(new ShapeButtonListener());
- button3.addActionListener(new ShapeButtonListener());
- button4.addActionListener(new ShapeButtonListener());
- button5.addActionListener(new ShapeButtonListener());
- button6.addActionListener(new ShapeButtonListener());
- button7.addActionListener(new ShapeButtonListener());
- button8.addActionListener(new ShapeButtonListener());
- button9.addActionListener(new ShapeButtonListener());
- button10.addActionListener(new ShapeButtonListener());
- button11.addActionListener(new ShapeButtonListener());
- button12.addActionListener(new ShapeButtonListener());
- button13.addActionListener(new ShapeButtonListener());
- exitButton.addActionListener(new ShapeButtonListener());
- }
- private class ShapeButtonListener implements ActionListener {
- public void actionPerformed (ActionEvent e){
- if (e.getSource() == button1) {
- //Circle *Should call a method or create a new instance of a trapezoid class.
- Circle circle = new Circle();
- }else if (e.getSource() == button2){
- //Parallelogram *Same with the rest of the shapes and so on.
- Parallelogram parallelogram = new Parallelogram();
- }else if (e.getSource() == button3){
- //Pyramid
- Pyramid pyramid = new Pyramid();
- }else if (e.getSource() == button4){
- Rectangle rectangle = new Rectangle();
- }else if (e.getSource() == button5){
- //Solid Rectangle *Same with the rest of the shapes and so on.
- RectangleSolid rectanglesolid = new RectangleSolid();
- }else if (e.getSource() == button6){
- //Sphere *Same with the rest of the shapes and so on.
- Sphere sphere = new Sphere();
- }else if (e.getSource() == button7){
- //Square *Same with the rest of the shapes and so on.
- Square square = new Square();
- }else if (e.getSource() == button8){
- //Triangle *Same with the rest of the shapes and so on.
- Triangle triangle = new Triangle();
- }else if (e.getSource() == button9){
- //Cube *Same with the rest of the shapes and so on.
- Cube cube = new Cube();
- }else if (e.getSource() == button10){
- //Trapezoid *Same with the rest of the shapes and so on.
- Trapezoid trapezoid = new Trapezoid();
- }else if (e.getSource() == button11){
- //Prism *Same with the rest of the shapes and so on.
- Prism prism = new Prism();
- }else if (e.getSource() == button12){
- //Cylinder *Same with the rest of the shapes and so on.
- Cylinder cylinder = new Cylinder();
- }else if (e.getSource() == button13){
- //Cone *Same with the rest of the shapes and so on.
- Cones cones = new Cones();
- }else if (e.getSource() == exitButton){
- try{
- DeskLogin login = new DeskLogin();
- setVisible(false);
- dispose();
- } catch (IOException ed){
- JOptionPane.showMessageDialog(null, "An error occurred.");
- }
- }
- }
- } //end of private class
- }
- /* Whoever has the class names for the shapes can fill in ShapeButtonListener. This is an easier
- * way to write what to do if a certain button is clicked (beats the shit out of writing 4 classes)
- * and keeps the code very clean and effective.
- * Feel free to add what you like or need.
- *
- * -Graham S.
- */
Advertisement
Add Comment
Please, Sign In to add comment