/* * Gets the user choice for font, style and size and redraws the text * accordingly. */ public void setSampleFont() { // Get the font name from the JComboBox fontName = (String) facenameCombo.getSelectedItem(); sampleField.setText(textField.getText()); // Get the font style from the JCheckBoxes fontStyle = 0; if (italicCheckBox.isSelected()) fontStyle += Font.ITALIC; if (boldCheckBox.isSelected()) fontStyle += Font.BOLD; // Get the font size fontSize = 0; fontSize = Integer.parseInt((String) sizeCombo.getSelectedItem()); // THE FOLLOWING IS NO LONGER NEEDED // if(smallButton.isSelected()) // fontSize=SMALL; // else if(mediumButton.isSelected()) // fontSize=MEDIUM; // else if(largeButton.isSelected()) // fontSize=LARGE; // Set the font of the text field sampleField.setFont(new Font(fontName, fontStyle, fontSize)); sampleField.setForeground(fontColor); sampleField.repaint(); pack(); } // end setSampleFont method
/* * The following method resets the window to its original status. */ public void init() { sampleField.setText(new String("Big Java")); textField.setText(new String("Big Java")); facenameCombo.setSelectedIndex(0); sizeCombo.setSelectedIndex(2); italicCheckBox.setSelected(false); boldCheckBox.setSelected(false); // largeButton.setSelected(true); fontColor = Color.BLACK; setSampleFont(); } // end init method
/* * The following method creates the combo box with font size choices * postcondition: returns the panel containing the size combo box. */ public JPanel createSizeComboBox() { sizeCombo = new JComboBox(); sizeCombo.addItem(SMALLEST); sizeCombo.addItem(SMALL); sizeCombo.addItem(SMALL_MEDIUM); sizeCombo.addItem(MEDIUM); sizeCombo.addItem(MEDIUM_LARGE); sizeCombo.addItem(LARGE); sizeCombo.addItem(LARGEST); sizeCombo.addItem(HUGE); sizeCombo.addItem(WOW); sizeCombo.setEditable(true); // facenameCombo.addActionListener(this); sizeCombo.setSelectedIndex(2); JPanel panel = new JPanel(); panel.add(sizeCombo); panel.setBorder(new TitledBorder(new EtchedBorder(), "Font Name")); return panel; } // end createComboBox method
/* * The following method creates the combo box with font style choices * postcondition: returns the panel containing the combo box. */ public JPanel createFacenameComboBox() { // YOU MUST ALTER THESE BASED ON YOUR SYSTEM. facenameCombo = new JComboBox(); facenameCombo.addItem(new String("Times")); facenameCombo.addItem(new String("Agent Orange")); facenameCombo.addItem(new String("Aldo's Nova")); facenameCombo.addItem(new String("American Typewriter")); facenameCombo.addItem(new String("American Typewriter Condensed")); facenameCombo.addItem(new String("American Typewriter Light")); facenameCombo.addItem(new String("Andale Mono")); facenameCombo.addItem(new String("AntsyPants")); facenameCombo.addItem(new String("Apple Chancery")); facenameCombo.addItem(new String("Arial")); facenameCombo.addItem(new String("Arial Black")); facenameCombo.addItem(new String("Arial Narrow")); facenameCombo.addItem(new String("Aristocrat LET")); facenameCombo.addItem(new String("AstigamaTizm")); facenameCombo.addItem(new String("BASEHEAD")); facenameCombo.addItem(new String("Baskerville")); facenameCombo.addItem(new String("BellBottom")); facenameCombo.addItem(new String("Bertram LET")); facenameCombo.addItem(new String("BiauKai")); facenameCombo.addItem(new String("Bickley Script LET")); facenameCombo.addItem(new String("Bite me")); facenameCombo.addItem(new String("Bizarro")); facenameCombo.addItem(new String("Bodoni Ornaments ITC TT")); facenameCombo.addItem(new String("Calaveras")); facenameCombo.addItem(new String("Capitals")); facenameCombo.addItem(new String("Century Gothic")); facenameCombo.addItem(new String("Chalkboard")); facenameCombo.addItem(new String("Charcoal")); facenameCombo.addItem(new String("Chicago")); facenameCombo.addItem(new String("Cochin")); facenameCombo.addItem(new String("Comic Sans MS")); facenameCombo.addItem(new String("Copperplate")); facenameCombo.addItem(new String("Courier")); facenameCombo.addItem(new String("Courier New")); facenameCombo.addItem(new String("Curlz MT")); facenameCombo.addItem(new String("Didot")); facenameCombo.addItem(new String("Edwardian Script ITC")); facenameCombo.addItem(new String("Fang Song")); facenameCombo.addItem(new String("Fortuna Dot")); facenameCombo.addItem(new String("Futura")); facenameCombo.addItem(new String("Gadget")); facenameCombo.addItem(new String("Geeza Pro")); facenameCombo.addItem(new String("Geneva")); facenameCombo.addItem(new String("Georgia")); facenameCombo.addItem(new String("Gill Sans")); facenameCombo.addItem(new String("Gringo Nights")); facenameCombo.addItem(new String("Hei")); facenameCombo.addItem(new String("Helvetica")); facenameCombo.addItem(new String("Herculanum")); facenameCombo.addItem(new String("Hypmotizin")); facenameCombo.addItem(new String("Impact")); facenameCombo.addItem(new String("Jokerman LET")); facenameCombo.addItem(new String("MadisonSquare")); facenameCombo.addItem(new String("MammaGamma")); facenameCombo.addItem(new String("Mathmos Original")); facenameCombo.addItem(new String("MammaGamma")); facenameCombo.addItem(new String("Marker Felt")); facenameCombo.addItem(new String("MassiveHeadache3")); facenameCombo.addItem(new String("Parry Hotter")); facenameCombo.setEditable(true); // facenameCombo.addActionListener(this); JPanel panel = new JPanel(); panel.add(facenameCombo); panel.setBorder(new TitledBorder(new EtchedBorder(), "Font Name")); return panel; } // end createComboBox method