source: trunk/yao/share/antlr-2.7.7/examples/java/unicode.IDENTs/ShowString.java @ 1

Last change on this file since 1 was 1, checked in by lnalod, 15 years ago

Initial import of YAO sources

File size: 1.6 KB
Line 
1
2/*
3 * Copyright (c) 1995-1998 Sun Microsystems, Inc. All Rights Reserved.
4 *
5 * Permission to use, copy, modify, and distribute this software
6 * and its documentation for NON-COMMERCIAL purposes and without
7 * fee is hereby granted provided that this copyright notice
8 * appears in all copies. Please refer to the file "copyright.html"
9 * for further important copyright and licensing information.
10 *
11 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
12 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
15 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
16 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
17 */
18
19import java.awt.*;
20
21class ShowString extends Frame {
22
23    FontMetrics fontM;
24    String outString;
25   
26    ShowString (String target, String title) {
27
28        setTitle(title);
29        outString = target;
30
31        Font font = new Font("Monospaced", Font.PLAIN, 36);
32        fontM = getFontMetrics(font);
33        setFont(font);
34
35        int size = 0;
36        for (int i = 0; i < outString.length(); i++) {
37           size += fontM.charWidth(outString.charAt(i));
38        }
39        size += 24;
40
41        setSize(size, fontM.getHeight() + 60);
42        setLocation(getSize().width/2, getSize().height/2);
43        show();
44    }
45
46    public void paint(Graphics g) {
47        Insets insets = getInsets();
48        int x = insets.left; 
49        int y = insets.top;
50        g.drawString(outString, x + 6, y + fontM.getAscent() + 14);
51    }
52}
Note: See TracBrowser for help on using the repository browser.