Draw String Demo
From Java Example Source Code
Contents |
[edit] Overview - Draw String Demo
This Java example program shows how to draw string.
[edit] Java Source Code
- Package: example.encode
- File: DrawStringDemo.java
package example.encode; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; public class DrawStringDemo extends JFrame { String message = "David says, \"\u05E9\u05DC\u05D5\u05DD \u05E2\u05D5\u05DC\u05DD\""; public DrawStringDemo() { super("DrawStringDemo"); } public void paint(Graphics g) { Graphics2D graphics2D = (Graphics2D) g; GraphicsEnvironment.getLocalGraphicsEnvironment(); Font font = new Font("LucidaSans", Font.PLAIN, 40); graphics2D.setFont(font); graphics2D.drawString(message, 50, 75); } public static void main(String[] args) { JFrame frame = new DrawStringDemo(); frame.pack(); frame.setVisible(true); } }
[edit] What Result You Can Get
Run the program, you will get:
[edit] Required External Libraries and/or Files for this Java Example
Need nothing.
[edit] How to Run this Java Example Program
We recommend running this Java example program with Eclipse.
For assistance in working with Eclipse, please see How to Run Java Program with Eclipse.
It's fairly easy.
[edit] Question & Answer
Any question?
Click edit and post your question or answer here.

