/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package theaterpeople; import java.awt.Color; import java.awt.event.*; import java.awt.Font; //import java.awt.event.ActionListener; import java.awt.FlowLayout; import javax.swing.*; import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; /** * * @author jcmt */ public class PersonWindow2 extends JFrame { private Actor MR = null; private String mRString; private String mRFirstName; private String mRLastName; private JLabel label1; JPanel personPanel1 = new JPanel(); JList colorJList; JList copyJList; JButton copyJButton; private static final String[] colorNames = {"Black", "Red", "Blue", "Yellow","White"}; private static final Color[] colors = {Color.BLACK, Color.RED, Color.BLUE, Color.YELLOW, Color.WHITE}; JComboBox fontChoice; 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 bolditalfont = new Font("Serif", Font.BOLD + Font.ITALIC, 14); Font boldfont = new Font("Serif", Font.BOLD, 14); Font italfont = new Font("Serif", Font.ITALIC, 14); Font plainfont = new Font("Serif", Font.PLAIN, 14); Font[] fonts2 = {plainfont, boldfont, italfont, bolditalfont}; static final String[] fontnms = {"plain","bold","italic","bold & italic"}; /* JRadioButton plainRB; JRadioButton boldRB; JRadioButton italRB; JRadioButton bolditalRB; ButtonGroup rbGroup; */ JTextField pT1 = new JTextField("Watch!"); JPasswordField pP1 = new JPasswordField(); public PersonWindow2() // has a constructer { super("Testing PersonWIndow - List w multiple selections"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //setTitle("Person"); setSize(250,550); //setLayout(new FlowLayout()); //pL1.setToolTipText("Enter the person's name"); //Icon pic = new ImageIcon(getClass().getResource("ipic.jpg")); colorJList = new JList(colorNames); colorJList.setVisibleRowCount(5); // colorJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); colorJList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); /* PersonWindow2.pT1Handler pT1hand = new PersonWindow2.pT1Handler(); //pCBHandler pChand = new pCBHandler(); personPanel1.add(pL1); personPanel1.add(pT1); personPanel1.add(pB1); personPanel1.add(pB2); *//* fontChoice = new JComboBox(fontnms); fontChoice.setMaximumRowCount(3); fontChoice.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent ie) { if (ie.getStateChange() == ItemEvent.SELECTED) { System.out.printf("Combo box selection made %d", fontChoice.getSelectedIndex()); pT1.setFont(fonts2[fontChoice.getSelectedIndex()]); } } } ); * */ /* personPanel1.add(fontChoice); */ // colorListHandler cLhand = new colorListHandler(); personPanel1.add(new JScrollPane(colorJList)); copyJButton = new JButton("Copy>>"); copyJButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { copyJList.setListData( colorJList.getSelectedValues() ); } // end of actionPerformed method } // end of anonymous ActionListener ); //end of Action Listener registration personPanel1.add(copyJButton); copyJList = new JList(); copyJList.setVisibleRowCount(5); copyJList.setFixedCellWidth(100); copyJList.setFixedCellHeight(15); copyJList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); personPanel1.add( new JScrollPane(copyJList)); /* colorJList.addListSelectionListener( new colorListHandler()); * */ // colorJList.addListSelectionListener( // new colorListHandler()); /* 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 PersonWindow2.RadioButtonHandler(plainfont)); boldRB.addItemListener(new PersonWindow2.RadioButtonHandler(boldfont)); italRB.addItemListener(new PersonWindow2.RadioButtonHandler(italfont)); bolditalRB.addItemListener(new PersonWindow2.RadioButtonHandler(bolditalfont)); */ /* pT1.setFont( plainfont); pB2.setRolloverIcon(null); */ add(personPanel1); //return MR; } public void showPersonWindow2() { this.setVisible(true); } public String getMRString() { return mRString; } private class colorListHandler implements ListSelectionListener { @Override public void valueChanged(ListSelectionEvent lse) { personPanel1.setBackground( colors[colorJList.getSelectedIndex()]); } } 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); } } */ }