Skip to content

Commit c609f1c

Browse files
committed
PanelGraphics
A simple program that uses the Graphics object to draw text on a JPanel
1 parent 7a1b580 commit c609f1c

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

PanelGraphics/PanelGraphics.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.awt.Color;
2+
import java.awt.Font;
3+
import java.awt.Graphics;
4+
import javax.swing.JFrame;
5+
import javax.swing.JPanel;
6+
7+
/**
8+
* Author: Edwin Torres
9+
* email: CoachEd@gmail.com
10+
*
11+
* Description: This program shows how to use the Graphics object
12+
* to write Hello World! in a JPanel.
13+
*/
14+
public class PanelGraphics extends JPanel {
15+
16+
private static final long serialVersionUID = 6615291965888806768L;
17+
18+
public void paintComponent(Graphics g) {
19+
20+
/** for example */
21+
g.setColor(Color.blue);
22+
Font font = new Font("Serif", Font.BOLD, 48);
23+
g.setFont(font);
24+
g.drawString("Hello World!", 20, 50);
25+
26+
}
27+
28+
public static void main(String args[]) {
29+
JFrame frame = new JFrame();
30+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
31+
frame.add(new PanelGraphics());
32+
frame.setSize(400, 250);
33+
frame.setVisible(true);
34+
}
35+
}

PanelGraphics/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a simple example that shows how to use the Graphics object to draw text on a JPanel.

PanelGraphics/screenshot.png

15.4 KB
Loading

0 commit comments

Comments
 (0)