Advertisement
MinimalChampion

PlayerGUI

Nov 23rd, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.62 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.event.ActionListener;
  3. import java.awt.event.ActionEvent;
  4.  
  5. import javax.swing.JFrame;
  6. import javax.swing.JLabel;
  7. import javax.swing.JTextField;
  8. import javax.swing.JRadioButton;
  9. import javax.swing.JButton;
  10.  
  11. /*
  12.  * Should I store all Player information
  13.  * in a HTML document with jsoup?
  14.  *
  15.  * Use a txt file and read buttom up?
  16.  *
  17.  */
  18. public class PlayerGUI extends JFrame {
  19.  
  20.     private JLabel lblName;
  21.     private JLabel lblEmail;
  22.     private JLabel lblSchool;
  23.  
  24.     private JTextField tfName;
  25.     private JTextField tfEmail;
  26.     private JTextField tfSchool;
  27.     private JRadioButton rbDriver;
  28.     private JButton bConfirm;
  29.  
  30.     public String strName;
  31.     public String strEmail;
  32.     public String strSchool;
  33.     public boolean boolDriver;
  34.  
  35.     public PlayerGUI() {
  36.         super("New Player"); // title bar
  37.         setLayout(new FlowLayout());
  38.  
  39.         // visual components
  40.         lblName = new JLabel("First and Last Name:");
  41.         add(lblName);
  42.         tfName = new JTextField("", 20);
  43.         add(tfName);
  44.  
  45.         lblEmail = new JLabel("Email address:");
  46.         add(lblEmail);
  47.         tfEmail = new JTextField("", 20);
  48.         add(tfEmail);
  49.  
  50.         lblSchool = new JLabel("School:");
  51.         add(lblSchool);
  52.         tfSchool = new JTextField("", 20);
  53.         add(tfSchool);
  54.  
  55.         rbDriver = new JRadioButton("Licensed");
  56.         add(rbDriver);
  57.         bConfirm = new JButton("Confirm Information");
  58.         add(bConfirm);
  59.  
  60.         // event handler
  61.         EventHandler hand = new EventHandler();
  62.         tfName.addActionListener(hand);
  63.         tfEmail.addActionListener(hand);
  64.         tfSchool.addActionListener(hand);
  65.         rbDriver.addActionListener(hand);
  66.         bConfirm.addActionListener(hand);
  67.     }
  68.  
  69.     /*
  70.      * Returns a player using GUI information
  71.      */
  72.     public Player createPlayer() {
  73.         Player resultPlayer = new Player(strName, strSchool, strEmail, boolDriver);
  74.         return resultPlayer;
  75.     }
  76.  
  77.     // --------------------------------------------------------------
  78.     // Handles events
  79.     // --------------------------------------------------------------
  80.     private class EventHandler implements ActionListener {
  81.  
  82.         /*
  83.          * Updates player information WITHIN CLASS
  84.          */
  85.         public void actionPerformed(ActionEvent event) {
  86.  
  87.             if (event.getSource() == bConfirm) {
  88.                 String tempName = "";
  89.                 String tempEmail = "";
  90.                 String tempSchool = "";
  91.                 boolean tempDriver = false;
  92.  
  93.                 tempName = tfName.getText();
  94.                 tempEmail = tfEmail.getText();
  95.                 tempSchool = tfSchool.getText();
  96.                 tempDriver = rbDriver.isSelected();
  97.  
  98.                 strName = tempName;
  99.                 strEmail = tempEmail;
  100.                 strSchool = tempSchool;
  101.                 boolDriver = tempDriver;
  102.  
  103.                 System.out.println(createPlayer());
  104.             }
  105.  
  106.         }
  107.  
  108.     } // end EventHandler
  109.  
  110. }// end PlayerGUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement