List of usage examples for java.awt Graphics setFont
public abstract void setFont(Font font);
From source file:Main.java
public void paint(Graphics g) { int fontSize = 20; g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); String s = "www.java2s.com"; g.setColor(Color.black);/*from w w w .j a v a2s . co m*/ g.drawString(s, 30, 30); }
From source file:Main.java
public void paint(Graphics g) { int fontSize = 20; g.setFont(new Font("TimesRoman", Font.BOLD, fontSize)); String s = "www.java2s.com"; g.setColor(Color.black);/* w ww .j a v a2s .c om*/ g.drawString(s, 30, 30); }
From source file:BasicDraw.java
public void paint(Graphics g) { Font font = new Font("Serif", Font.PLAIN, 12); g.setFont(font); g.drawString("a String", 10, 10); FontMetrics fontMetrics = g.getFontMetrics(); g.drawString("aString", 10, 10 + fontMetrics.getAscent()); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setFont(new Font("arial", Font.PLAIN, 24)); g.drawString("java2s.com", 200, 200); }
From source file:MainClass.java
public void paint(Graphics g) { Font f = new Font("Serif", Font.PLAIN, 12); g.setFont(f); g.drawString("Serif - PLAIN - 12", 10, 30); f = new Font("Sanserif", Font.ITALIC, 10); g.setFont(f);//from w w w . ja va 2 s . c o m g.drawString("Sanserif - ITALIC - 10", 10, 60); f = new Font("Monospaced", Font.BOLD | Font.ITALIC, 14); g.setFont(f); g.drawString("Monospaced - BOLD and ITALIC - 14", 10, 90); f = new Font("Dialog", Font.PLAIN, 12); g.setFont(f); g.drawString("Dialog - PLAIN - 12", 10, 120); f = new Font("DialogInput", Font.BOLD + Font.ITALIC, 10); g.setFont(f); g.drawString("DialogInput - BOLD and ITALIC - 10", 10, 150); }
From source file:Main.java
public void paintComponent(Graphics g) { super.paintComponent(g); drawString(g, "hello\nworld", 20, 20); g.setFont(g.getFont().deriveFont(20f)); drawString(g, "part1\npart2", 120, 120); }
From source file:MainClass.java
public void paint(Graphics g) { Dimension d = this.getPreferredSize(); int fontSize = 20; g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); g.setColor(Color.red);//w w w .j a v a 2 s . c om g.drawString("www.java2s.com", 10, 20); }
From source file:Main.java
public void paint(Graphics g) { int fontSize = 20; g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); FontMetrics fm = g.getFontMetrics(); String s = "www.java2s.com"; int stringWidth = fm.stringWidth(s); int w = 200;/*from w ww .j a v a 2 s .c o m*/ int h = 200; int x = (w - stringWidth) / 2; int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2; int ascent = fm.getMaxAscent(); int descent = fm.getMaxDecent(); int fontHeight = fm.getMaxAscent() + fm.getMaxDecent(); g.setColor(Color.white); g.fillRect(x, baseline - ascent, stringWidth, fontHeight); g.setColor(Color.gray); g.drawLine(x, baseline, x + stringWidth, baseline); g.setColor(Color.red); g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent); g.setColor(Color.blue); g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent); g.setColor(Color.black); g.drawString(s, x, baseline); }
From source file:MainClass.java
public void paint(Graphics g) { int fontSize = 20; g.setFont(new Font("TimesRoman", Font.PLAIN, fontSize)); FontMetrics fm = g.getFontMetrics(); String s = "www.java2s.com"; int stringWidth = fm.stringWidth(s); int w = 200;/*from w ww . j ava 2 s. c o m*/ int h = 200; int x = (w - stringWidth) / 2; int baseline = fm.getMaxAscent() + (h - (fm.getAscent() + fm.getMaxDecent())) / 2; int ascent = fm.getMaxAscent(); int descent = fm.getMaxDecent(); int fontHeight = fm.getMaxAscent() + fm.getMaxDecent(); g.setColor(Color.white); g.fillRect(x, baseline - ascent, stringWidth, fontHeight); g.setColor(Color.gray); g.drawLine(x, baseline, x + stringWidth, baseline); g.setColor(Color.red); g.drawLine(x, baseline + descent, x + stringWidth, baseline + descent); g.setColor(Color.blue); g.drawLine(x, baseline - ascent, x + stringWidth, baseline - ascent); g.setColor(Color.black); g.drawString(s, x, baseline); }
From source file:Clock.java
private void drawStructure(Graphics g) { g.setFont(new Font("TimesRoman", Font.PLAIN, 14)); g.setColor(Color.blue);/*from w w w. jav a2s . c o m*/ g.drawOval(xcenter - 50, ycenter - 50, 100, 100); g.setColor(Color.darkGray); g.drawString("9", xcenter - 45, ycenter + 3); g.drawString("3", xcenter + 40, ycenter + 3); g.drawString("12", xcenter - 5, ycenter - 37); g.drawString("6", xcenter - 3, ycenter + 45); }