File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ This is a simple example that shows how to use the Graphics object to draw text on a JPanel.
You can’t perform that action at this time.
0 commit comments