Back to Applets page
Click in the boxes below, select all and copy to grab the applet
HTML listing:
<HTML> <HEAD> <TITLE>Listing 9.9</TITLE> </HEAD> <BODY BGCOLOR=WHITE> <APPLET CODEBASE="classes" CODE="Applet9.class" WIDTH=400 HEIGHT=150> </APPLET> </BODY> </HTML>
Applet listing:
import java.awt.*; import java.applet.*; public class Applet9 extends Applet { GridBagLayout thisLayout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); public void init() { setBackground(Color.white); this.setLayout(thisLayout); c.fill = GridBagConstraints.BOTH; c.insets = new Insets(5,5,5,5); c.gridx = 0; c.gridy = 0; c.gridwidth = 4; c.gridheight = 4; c.weightx = 1.0; c.weighty = 1.0; makeButton(1); c.gridx = 4; c.gridwidth = 1; c.gridheight = 1; c.weightx = 0.0; c.weighty = 0.0; makeButton(2); c.gridy = 1; c.gridheight = 3; makeButton(3); c.gridy = 4; c.gridheight = 1; makeButton(4); c.gridx = 0; makeButton(5); c.gridx = 1; c.weightx = 1.0; makeButton(6); } protected void makeButton(int buttonNo) { Button newButton = new Button("Button #" + buttonNo); thisLayout.setConstraints(newButton,c); add(newButton); } }