26.07.2013 Views

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

Java How to Program Fourth Edition - DCC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

764 Graphical User Interface Components: Part 2 Chapter 13<br />

54 // attach internal frame <strong>to</strong> desk<strong>to</strong>p and show it<br />

55 theDesk<strong>to</strong>p.add( frame );<br />

56 frame.setVisible( true );<br />

57 }<br />

58<br />

59 } // end anonymous inner class<br />

60<br />

61 ); // end call <strong>to</strong> addActionListener<br />

62<br />

63 setSize( 600, 440 );<br />

64 setVisible( true );<br />

65<br />

66 } // end construc<strong>to</strong>r<br />

67<br />

68 // execute application<br />

69 public static void main( String args[] )<br />

70 {<br />

71 Desk<strong>to</strong>pTest application = new Desk<strong>to</strong>pTest();<br />

72<br />

73 application.setDefaultCloseOperation(<br />

74 JFrame.EXIT_ON_CLOSE );<br />

75 }<br />

76<br />

77 } // end class Desk<strong>to</strong>pTest<br />

78<br />

79 // class <strong>to</strong> display an ImageIcon on a panel<br />

80 class MyJPanel extends JPanel {<br />

81 private ImageIcon imageIcon;<br />

82<br />

83 // load image<br />

84 public MyJPanel()<br />

85 {<br />

86 imageIcon = new ImageIcon( "jhtp4.png" );<br />

87 }<br />

88<br />

89 // display imageIcon on panel<br />

90 public void paintComponent( Graphics g )<br />

91 {<br />

92 // call superclass paintComponent method<br />

93 super.paintComponent( g );<br />

94<br />

95 // display icon<br />

96 imageIcon.paintIcon( this, g, 0, 0 );<br />

97 }<br />

98<br />

99 // return image dimensions<br />

100 public Dimension getPreferredSize()<br />

101 {<br />

102 return new Dimension( imageIcon.getIconWidth(),<br />

103 imageIcon.getIconHeight() );<br />

104 }<br />

105<br />

106 } // end class MyJPanel<br />

Fig. Fig. 13.13 13.13 Creating a multiple document interface (part 2 of 3).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!