/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package theaterpeople; import java.awt.event.*; import java.awt.Font; //import java.awt.event.ActionListener; import java.awt.FlowLayout; import javax.swing.*; /** * * @author jcmt */ public class PersonWindow extends JFrame { private Actor MR = null; private String mRString; private String mRFirstName; private String mRLastName; private JLabel label1; JPanel personPanel1 = new JPanel(); JButton pB1 = new JButton("Save Name"); JButton pB2 = new JButton("Whoo-hoo!"); JLabel pL1 = new JLabel("Enter First Name"); JCheckBox pC1 = new JCheckBox("Italic"); JCheckBox pC2 = new JCheckBox("Bold"); JTextField pT1 = new JTextField("Watch!"); JPasswordField pP1 = new JPasswordField(); public PersonWindow() // has a constructer { super("Testing PersonWIndow - checkbox"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setTitle("Person"); setSize(550,250); //setLayout(new FlowLayout()); pL1.setToolTipText("Enter the person's name"); //Icon pic = new ImageIcon(getClass().getResource("ipic.jpg")); pT1Handler pT1hand = new pT1Handler(); pCBHandler pChand = new pCBHandler(); personPanel1.add(pL1); personPanel1.add(pT1); personPanel1.add(pB1); personPanel1.add(pB2); personPanel1.add(pC1); personPanel1.add(pC2); pB1.addActionListener(pT1hand); pT1.addActionListener(pT1hand); pB2.addActionListener(pT1hand); pC1.addItemListener(pChand); pC2.addItemListener(pChand); pT1.setFont( new Font( "serif", Font.PLAIN, 14)); pB2.setRolloverIcon(null); add(personPanel1); //return MR; } public void showPersonWindow() { this.setVisible(true); } public String getMRString() { return mRString; } private class pT1Handler implements ActionListener { @Override public void actionPerformed(ActionEvent ae) { String string = ""; if (ae.getSource() == pT1) { mRString = ae.getActionCommand(); string = String.format("From the text field we get: %s", mRString); JOptionPane.showMessageDialog(null, string); } else if ((ae.getSource() == pB1) || (ae.getSource() == pB2)) { string = String.format("From the button field we get: %s", ae.getActionCommand()); JOptionPane.showMessageDialog(null, string); } } } private class pCBHandler implements ItemListener { @Override public void itemStateChanged(ItemEvent ie) { Font font = null; if (pC1.isSelected() && pC2.isSelected()) { font = new Font("Serif", Font.BOLD + Font.ITALIC, 14); } else if (pC2.isSelected()) { font = new Font("Serif", Font.BOLD, 14); } else if (pC1.isSelected()) { font = new Font("Serif", Font.ITALIC, 14); } else { font = new Font("Serif", Font.PLAIN, 14); } pT1.setFont(font); } } }