// HelloPanelApplication.java (c) Kari Laitinen // http://www.naturalprogramming.com/ // 2012-11-22 File created. // 2012-11-22 Latest modification. // This is a JPanel-based Java application // that draws two lines of text to its window. // The window that is shown by this application is // almost identical to the window opened by HelloApplication.java. import java.awt.* ; import javax.swing.* ; class HelloPanel extends JPanel { public void paintComponent( Graphics graphics ) { // The superclass version of paintComponent() clears the // component area and does other necessary things. super.paintComponent( graphics ) ; graphics.drawString( "Hello. I am JPanel-based application.", 80, 100 ) ; graphics.drawString( "The coordinates of this line are (80,150).", 80, 150 ) ; } } class HelloPanelFrame extends JFrame { static final int FRAME_WIDTH = 400 ; static final int FRAME_HEIGHT = 280 ; public HelloPanelFrame() { setTitle( "A SIMPLE JPanel-BASED APPLICATION" ) ; setSize( FRAME_WIDTH, FRAME_HEIGHT ) ; HelloPanel hello_panel = new HelloPanel() ; Container content_pane = getContentPane() ; content_pane.add( hello_panel ) ; setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ) ; } } public class HelloPanelApplication { public static void main( String[] not_in_use ) { HelloPanelFrame hello_panel_frame = new HelloPanelFrame() ; hello_panel_frame.setVisible( true ) ; } }