/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package guitest; import java.awt.LayoutManager; import javax.swing.*; import java.awt.event.*; /** * * @author jcmtiernan */ public class GUIone extends JPanel { private JTextField firstName; private JTextField lastName; private JTextField birthMonth; private JTextField birthDate; private JLabel fName; private JLabel lName; private JLabel bMonth; private JLabel bDate; private JButton done; private JLabel fOut; private JLabel lOut; private JLabel bDOut; private JLabel allOut; private String firstNm = new String(); private String lastNm; private Integer birthMo; private Integer birthD; private TextHandler textData; private PersonInfo personGUI; public GUIone(PersonInfo person1) { personGUI = person1; fName = new JLabel("Please enter your first name: "); this.add(fName); firstName = new JTextField(20); this.add(firstName); lName = new JLabel("Please enter your last name: "); this.add(lName); lastName = new JTextField(20); this.add(lastName); bMonth = new JLabel("Please enter the date of your month: "); this.add(bMonth); birthMonth = new JTextField(20); this.add(birthMonth); done = new JButton("Done"); this.add(done); fOut = new JLabel(); lOut = new JLabel(); bDOut = new JLabel(); allOut = new JLabel(); textData = new TextHandler(); done.addActionListener(textData); //firstName.addActionListener(textData); //lastName.addActionListener(textData); //birthMonth.addActionListener(textData); this.add(fOut); this.add(lOut); this.add(bDOut); //allOut.setText(String.format(" Name: "+firstNm)); this.add(allOut); } public GUIone(LayoutManager layout) { super(layout); } private class TextHandler implements ActionListener { @Override public void actionPerformed(ActionEvent event) { String entered; //if (event.getSource() == firstName) { personGUI.setFirstNm(new String(firstName.getText())); //entered.concat(firstNm); //fOut.setText(firstNm); System.out.println("In handler firstNm = "+personGUI.getFirstNm()); } //if (event.getSource() == lastName) { personGUI.setLastNm(new String(lastName.getText())); //entered = lastNm; //lOut.setText(lastNm); System.out.println("In handler lastNm = "+personGUI.getLastNm()); } //if (event.getSource() == birthMonth) { personGUI.setBirthMo(Integer.parseInt(birthMonth.getText())); //entered = birthMo.toString(); //bDOut.setText(birthMo.toString()); System.out.println("In handler birthMo = "+personGUI.getBirthMo()); } //JOptionPane.showMessageDialog(null,"You entered "+entered); } } public PersonInfo getPersonGUI() { return personGUI; } public void setPersonGUI(PersonInfo personGUI) { this.personGUI = personGUI; } /* public String getFirstNm() { return firstNm; } public void setFirstNm(String firstNm) { this.firstNm = firstNm; } public String getLastNm() { return lastNm; } public void setLastNm(String lastNm) { this.lastNm = lastNm; } public Integer getBirthMo() { return birthMo; } public void setBirthMo(Integer birthMo) { this.birthMo = birthMo; } public Integer getBirthD() { return birthD; } public void setBirthD(Integer birthD) { this.birthD = birthD; } */ }