/* * Gary Cornell and Cay S. Horstmann, Core Java (Book/CD-ROM) * Published By SunSoft Press/Prentice-Hall * Copyright (C) 1996 Sun Microsystems Inc. * All Rights Reserved. ISBN 0-13-565755-5 * * Permission to use, copy, modify, and distribute this * software and its documentation for NON-COMMERCIAL purposes * and without fee is hereby granted provided that this * copyright notice appears in all copies. * * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */ /** * @version 1.00 07 Feb 1996 * @author Cay Horstmann */ import java.awt.*; public class FontDialog extends Frame { private void add(Component c, GridBagLayout gbl, GridBagConstraints gbc, int x, int y, int w, int h) { gbc.gridx = x; gbc.gridy = y; gbc.gridwidth = w; gbc.gridheight = h; gbl.setConstraints(c, gbc); add(c); } public FontDialog() { setTitle("FontDialog"); GridBagLayout gbl = new GridBagLayout(); setLayout(gbl); style = new List(4, false); style.addItem("Times Roman"); style.addItem("Helvetica"); style.addItem("Courier"); style.addItem("Zapf Dingbats"); style.addItem("Dialog"); style.addItem("DialogInput"); Checkbox bold = new Checkbox("Bold"); Checkbox italic = new Checkbox("Italic"); Label label = new Label("Size: "); TextField size = new TextField(); TextField sample = new TextField(); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 20; gbc.weighty = 100; add(style, gbl, gbc, 0, 0, 1, 3); gbc.weightx = 100; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.CENTER; add(bold, gbl, gbc, 1, 0, 2, 1); add(italic, gbl, gbc, 1, 1, 2, 1); add(label, gbl, gbc, 1, 2, 1, 1); gbc.fill = GridBagConstraints.HORIZONTAL; add(size, gbl, gbc, 2, 2, 1, 1); gbc.anchor = GridBagConstraints.SOUTH; gbc.weighty = 0; add(sample, gbl, gbc, 0, 3, 4, 1); } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY) System.exit(0); return super.handleEvent(evt); } public boolean action(Event evt, Object arg) { if (evt.target.equals(bold) || evt.target.equals(italic)) { int m = (bold.getState() ? Font.BOLD : 0) + (italic.getState() ? Font.ITALIC : 0); } else return super.action(evt, arg); return true; } public static void main(String[] args) { Frame f = new FontDialog(); f.resize(250, 150); f.show(); } private List style; private Checkbox bold; private Checkbox italic; private TextField size; private TextField sample; }