Java AWT Font class

Description

Java AWT Font class

import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;

class DrawPanel extends JPanel {
   Font f = new Font("Dialog", Font.PLAIN, 12);
   String msg = "Dialog";

   public DrawPanel() {
      setFont(f);/*from ww  w  . j  ava  2s .  co m*/
   }

   public void paint(Graphics g) {
      f = new Font("Dialog", Font.PLAIN, 12);
      //f = new Font("DialogInput", Font.PLAIN, 12);
      //f = new Font("SansSerif", Font.PLAIN, 12);
      //f = new Font("Serif", Font.PLAIN, 12);
      //f = new Font("Monospaced", Font.PLAIN, 12);
      
      msg = "Dialog";
      g.drawString(msg, 4, 20);
   }
}
public class Main {
   public static void main(String[] args) {
      DrawPanel panel = new DrawPanel();

      JFrame application = new JFrame();

      application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      application.add(panel);
      application.setSize(250, 250);
      application.setVisible(true);
   }
}



PreviousNext

Related