TextPanel - Font f = new Font"SansSerif" Font.BOLD...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/************************************************************* * @file: TextPanel.java * @source: adapted from Horstmann and Cornell, Core Java * @history: Visualization Course, Spring 2003, Chee Yap *************************************************************/ import java.awt.*; import java.awt.event.*; import javax.swing.*; /************************************************************* * TextPanel Class (with main method) *************************************************************/ class TextPanel extends JPanel { // override the paintComponent method // THE MAIN DEMO OF THIS EXAMPLE: public void paintComponent(Graphics g) { super.paintComponent(g);
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Font f = new Font("SansSerif", Font.BOLD, 14); Font fi = new Font("SansSerif", Font.BOLD + Font.ITALIC, 14); FontMetrics fm = g.getFontMetrics(f); FontMetrics fim = g.getFontMetrics(fi); int cx = 75; int cy = 100; g.setFont(f); g.drawString("Hello, ", cx, cy); cx += fm.stringWidth("Hello, "); g.setFont(fi); g.drawString("World!", cx, cy); } //paintComponent //============================================= ///////////// main //////////////////////////// public static void main(String args) { JFrame f = new MyFrame("My Hello World Frame"); f.show(); } //main } //class TextPanel...
View Full Document

This note was uploaded on 11/22/2010 for the course BSE 71920 taught by Professor Nakurmura during the Spring '10 term at ASU.

Ask a homework question - tutors are online