Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.FlowLayout;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JRadioButton;
- import javax.swing.JButton;
- /*
- * Should I store all Player information
- * in a HTML document with jsoup?
- *
- * Use a txt file and read buttom up?
- *
- */
- public class PlayerGUI extends JFrame {
- private JLabel lblName;
- private JLabel lblEmail;
- private JLabel lblSchool;
- private JTextField tfName;
- private JTextField tfEmail;
- private JTextField tfSchool;
- private JRadioButton rbDriver;
- private JButton bConfirm;
- public String strName;
- public String strEmail;
- public String strSchool;
- public boolean boolDriver;
- public PlayerGUI() {
- super("New Player"); // title bar
- setLayout(new FlowLayout());
- // visual components
- lblName = new JLabel("First and Last Name:");
- add(lblName);
- tfName = new JTextField("", 20);
- add(tfName);
- lblEmail = new JLabel("Email address:");
- add(lblEmail);
- tfEmail = new JTextField("", 20);
- add(tfEmail);
- lblSchool = new JLabel("School:");
- add(lblSchool);
- tfSchool = new JTextField("", 20);
- add(tfSchool);
- rbDriver = new JRadioButton("Licensed");
- add(rbDriver);
- bConfirm = new JButton("Confirm Information");
- add(bConfirm);
- // event handler
- EventHandler hand = new EventHandler();
- tfName.addActionListener(hand);
- tfEmail.addActionListener(hand);
- tfSchool.addActionListener(hand);
- rbDriver.addActionListener(hand);
- bConfirm.addActionListener(hand);
- }
- /*
- * Returns a player using GUI information
- */
- public Player createPlayer() {
- Player resultPlayer = new Player(strName, strSchool, strEmail, boolDriver);
- return resultPlayer;
- }
- // --------------------------------------------------------------
- // Handles events
- // --------------------------------------------------------------
- private class EventHandler implements ActionListener {
- /*
- * Updates player information WITHIN CLASS
- */
- public void actionPerformed(ActionEvent event) {
- if (event.getSource() == bConfirm) {
- String tempName = "";
- String tempEmail = "";
- String tempSchool = "";
- boolean tempDriver = false;
- tempName = tfName.getText();
- tempEmail = tfEmail.getText();
- tempSchool = tfSchool.getText();
- tempDriver = rbDriver.isSelected();
- strName = tempName;
- strEmail = tempEmail;
- strSchool = tempSchool;
- boolDriver = tempDriver;
- System.out.println(createPlayer());
- }
- }
- } // end EventHandler
- }// end PlayerGUI
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement