Download Smile.java source file
// <APPLET CODE="Smile" WIDTH="330" HEIGHT="410"> // <PARAM NAME="IMAGE" VALUE="Mona.gif"> // </APPLET> // Smile.java - A Java swing applet that displays a GIF graphic. // The extra JPanels are needed to get the correct border effect. // // Written 2003 by Wayne Pollock, Tampa FL USA. import java.awt.*; import java.net.URL; import javax.swing.*; import javax.swing.border.*; public class Smile extends JApplet { public void init () { Container c = getContentPane(); String imageName = getParameter( "IMAGE" ); JLabel picLbl = null; if ( imageName != null ) { URL picURL = getClass().getResource( imageName ); ImageIcon picIcon = new ImageIcon( picURL ); picLbl = new JLabel( picIcon ); } else picLbl = new JLabel( "Image not avialable!" ); // Set the background color to cyan (same as HTML page): JPanel p1 = new JPanel(); p1.setBackground( Color.CYAN ); p1.setOpaque( true ); // Add a 4 pixel red border around the image: JPanel p2 = new JPanel( new FlowLayout( FlowLayout.CENTER, 0, 0 ) ); p2.setBorder( new LineBorder( Color.RED, 4 ) ); p1.add( p2 ); p2.add( picLbl ); c.add( p1 ); } }
Send comments and questions to
pollock@acm.org. |