/* */ // Swing Demo - A simple applet using Swing components and simple // graphics (no Java2D). Compare this program with AwtDemo. // This JApplet uses JButtons, a JLabel, and a JPanel instead of // a Canvas for the static inner class. (Note using a JComponent // instead would have no background, which always appears transparent.) // // This program adapted from Figure 5.3, p. 199, from Art Gittleman's // book "Internet Applications With the Java 2 Platform", (C) 2001 // Scott/Jones Inc. // // Written by Wayne Pollock, Tampa Florida USA, 2/2001. import javax.swing.*; import java.awt.*; public class SwingDemo extends JApplet { public void init () { Container c = getContentPane(); c.setLayout( new FlowLayout() ); // Has no default Layout Manager. c.add( new JButton( " One " ) ); c.add( new JLabel( " Two" ) ); MessagePane mp = new MessagePane(); c.add( mp ); mp.setBackground( Color.cyan ); mp.setPreferredSize( new Dimension(100, 100) ); setBackground( Color.gray ); } public static class MessagePane extends JPanel { public void paintComponent ( Graphics g ) { super.paintComponent( g ); // This paints background. g.drawString( "Swing Demo", 10, 56 ); } } }
Send comments and mail to the WebMaster. |