< prev index next >

src/demo/share/jfc/SwingSet2/ComboBoxDemo.java

Print this page

        

*** 55,71 **** public class ComboBoxDemo extends DemoModule implements ActionListener { Face face; JLabel faceLabel; ! JComboBox hairCB; ! JComboBox eyesCB; ! JComboBox mouthCB; ! JComboBox presetCB; ! Hashtable parts = new Hashtable(); /** * main method allows us to run as a standalone demo. */ public static void main(String[] args) { --- 55,71 ---- public class ComboBoxDemo extends DemoModule implements ActionListener { Face face; JLabel faceLabel; ! JComboBox<?> hairCB; ! JComboBox<?> eyesCB; ! JComboBox<?> mouthCB; ! JComboBox<?> presetCB; ! Hashtable<String, Object> parts = new Hashtable<>(); /** * main method allows us to run as a standalone demo. */ public static void main(String[] args) {
*** 109,140 **** comboBoxPanel.add(Box.createRigidArea(VGAP15)); JLabel l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.presets"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! presetCB = (JComboBox) comboBoxPanel.add(createPresetComboBox()); presetCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(presetCB); comboBoxPanel.add(Box.createRigidArea(VGAP30)); l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.hair_description"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! hairCB = (JComboBox) comboBoxPanel.add(createHairComboBox()); hairCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(hairCB); comboBoxPanel.add(Box.createRigidArea(VGAP15)); l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.eyes_description"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! eyesCB = (JComboBox) comboBoxPanel.add(createEyesComboBox()); eyesCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(eyesCB); comboBoxPanel.add(Box.createRigidArea(VGAP15)); l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.mouth_description"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! mouthCB = (JComboBox) comboBoxPanel.add(createMouthComboBox()); mouthCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(mouthCB); comboBoxPanel.add(Box.createRigidArea(VGAP15)); // Fill up the remaining space --- 109,143 ---- comboBoxPanel.add(Box.createRigidArea(VGAP15)); JLabel l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.presets"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! presetCB = createPresetComboBox(); presetCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(presetCB); + comboBoxPanel.add(presetCB); comboBoxPanel.add(Box.createRigidArea(VGAP30)); l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.hair_description"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! hairCB = createHairComboBox(); hairCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(hairCB); + comboBoxPanel.add(hairCB); comboBoxPanel.add(Box.createRigidArea(VGAP15)); l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.eyes_description"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! eyesCB = createEyesComboBox(); eyesCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(eyesCB); + comboBoxPanel.add(eyesCB); comboBoxPanel.add(Box.createRigidArea(VGAP15)); l = (JLabel) comboBoxPanel.add(new JLabel(getString("ComboBoxDemo.mouth_description"))); l.setAlignmentX(JLabel.LEFT_ALIGNMENT); ! mouthCB = (JComboBox<?>) comboBoxPanel.add(createMouthComboBox()); mouthCB.setAlignmentX(JComboBox.LEFT_ALIGNMENT); l.setLabelFor(mouthCB); comboBoxPanel.add(Box.createRigidArea(VGAP15)); // Fill up the remaining space
*** 215,254 **** Face getFace() { return face; } ! JComboBox createHairComboBox() { ! JComboBox cb = new JComboBox(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox createEyesComboBox() { ! JComboBox cb = new JComboBox(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox createNoseComboBox() { ! JComboBox cb = new JComboBox(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox createMouthComboBox() { ! JComboBox cb = new JComboBox(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox createPresetComboBox() { ! JComboBox cb = new JComboBox(); cb.addItem(getString("ComboBoxDemo.preset1")); cb.addItem(getString("ComboBoxDemo.preset2")); cb.addItem(getString("ComboBoxDemo.preset3")); cb.addItem(getString("ComboBoxDemo.preset4")); cb.addItem(getString("ComboBoxDemo.preset5")); --- 218,257 ---- Face getFace() { return face; } ! JComboBox<String> createHairComboBox() { ! JComboBox<String> cb = new JComboBox<>(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox<String> createEyesComboBox() { ! JComboBox<String> cb = new JComboBox<>(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox<String> createNoseComboBox() { ! JComboBox<String> cb = new JComboBox<>(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox<String> createMouthComboBox() { ! JComboBox<String> cb = new JComboBox<>(); fillComboBox(cb); cb.addActionListener(this); return cb; } ! JComboBox<String> createPresetComboBox() { ! JComboBox<String> cb = new JComboBox<>(); cb.addItem(getString("ComboBoxDemo.preset1")); cb.addItem(getString("ComboBoxDemo.preset2")); cb.addItem(getString("ComboBoxDemo.preset3")); cb.addItem(getString("ComboBoxDemo.preset4")); cb.addItem(getString("ComboBoxDemo.preset5"));
*** 259,269 **** cb.addItem(getString("ComboBoxDemo.preset10")); cb.addActionListener(this); return cb; } ! void fillComboBox(JComboBox cb) { cb.addItem(getString("ComboBoxDemo.brent")); cb.addItem(getString("ComboBoxDemo.georges")); cb.addItem(getString("ComboBoxDemo.hans")); cb.addItem(getString("ComboBoxDemo.howard")); cb.addItem(getString("ComboBoxDemo.james")); --- 262,272 ---- cb.addItem(getString("ComboBoxDemo.preset10")); cb.addActionListener(this); return cb; } ! void fillComboBox(JComboBox<String> cb) { cb.addItem(getString("ComboBoxDemo.brent")); cb.addItem(getString("ComboBoxDemo.georges")); cb.addItem(getString("ComboBoxDemo.hans")); cb.addItem(getString("ComboBoxDemo.howard")); cb.addItem(getString("ComboBoxDemo.james"));
*** 277,295 **** cb.addItem(getString("ComboBoxDemo.scott")); } public void actionPerformed(ActionEvent e) { if(e.getSource() == hairCB) { ! String name = (String) parts.get((String) hairCB.getSelectedItem()); face.setHair((ImageIcon) parts.get(name + "hair")); faceLabel.repaint(); } else if(e.getSource() == eyesCB) { ! String name = (String) parts.get((String) eyesCB.getSelectedItem()); face.setEyes((ImageIcon) parts.get(name + "eyes")); faceLabel.repaint(); } else if(e.getSource() == mouthCB) { ! String name = (String) parts.get((String) mouthCB.getSelectedItem()); face.setMouth((ImageIcon) parts.get(name + "mouth")); faceLabel.repaint(); } else if(e.getSource() == presetCB) { String hair = null; String eyes = null; --- 280,298 ---- cb.addItem(getString("ComboBoxDemo.scott")); } public void actionPerformed(ActionEvent e) { if(e.getSource() == hairCB) { ! String name = (String) parts.get(hairCB.getSelectedItem()); face.setHair((ImageIcon) parts.get(name + "hair")); faceLabel.repaint(); } else if(e.getSource() == eyesCB) { ! String name = (String) parts.get(eyesCB.getSelectedItem()); face.setEyes((ImageIcon) parts.get(name + "eyes")); faceLabel.repaint(); } else if(e.getSource() == mouthCB) { ! String name = (String) parts.get(mouthCB.getSelectedItem()); face.setMouth((ImageIcon) parts.get(name + "mouth")); faceLabel.repaint(); } else if(e.getSource() == presetCB) { String hair = null; String eyes = null;
< prev index next >