Graphics class allows us to draw strings on the frame with its method drawString(). Following is the signature. void drawString(String str1, int x, int y): x and y are the coordinates where the string str1 is to be drawn on the frame. Following program illustrates.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.awt.*; public class StringsDrawing extends Frame { public StringsDrawing() { setTitle("Practicing Strings"); setSize(300, 350); setVisible(true); } ublic void paint(Graphics g) { g.drawString("Hello World", 60, 80); g.drawString("How do you do?", 60, 100); g.drawString("Please accept greetings", 60, 120); } public static void main(String args[]) { new StringsDrawing(); } } |
setSize(300, 350); To draw…