/* * 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"); Font plainfont; Font boldfont; Font italfont; Font bolditalfont; JRadioButton plainRB; JRadioButton boldRB; JRadioButton italRB; JRadioButton bolditalRB; ButtonGroup rbGroup; 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); plainRB = new JRadioButton("Plain",true); boldRB = new JRadioButton("Bold",false); italRB = new JRadioButton("Italic",false); bolditalRB = new JRadioButton("Bold & Italic",false); personPanel1.add(plainRB); personPanel1.add(boldRB); personPanel1.add(italRB); personPanel1.add(bolditalRB); rbGroup = new ButtonGroup(); rbGroup.add(plainRB); rbGroup.add(boldRB); rbGroup.add(italRB); rbGroup.add(bolditalRB); bolditalfont = new Font("Serif", Font.BOLD + Font.ITALIC, 14); boldfont = new Font("Serif", Font.BOLD, 14); italfont = new Font("Serif", Font.ITALIC, 14); plainfont = new Font("Serif", Font.PLAIN, 14); // personPanel1.add(pC1); // personPanel1.add(pC2); pB1.addActionListener(pT1hand); pT1.addActionListener(pT1hand); pB2.addActionListener(pT1hand); // pC1.addItemListener(pChand); // pC2.addItemListener(pChand); plainRB.addItemListener(new RadioButtonHandler(plainfont)); boldRB.addItemListener(new RadioButtonHandler(boldfont)); italRB.addItemListener(new RadioButtonHandler(italfont)); bolditalRB.addItemListener(new RadioButtonHandler(bolditalfont)); pT1.setFont( plainfont); 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 RadioButtonHandler implements ItemListener { private Font font; public RadioButtonHandler( Font f) { font = f; } @Override public void itemStateChanged(ItemEvent ie) { pT1.setFont(font); } } /** 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); } } */ }