An Applet With Layout


The applet's real estate is the area within the border

Source

AnAppletWithLayout.java:
import java.applet.*;
import java.awt.*;

public class AnAppletWithLayout extends Applet {
	public void init() {
		setLayout(new BorderLayout());

		Button topButton = new Button("Top");
		add(topButton, BorderLayout.NORTH);

		Button bottomButton = new Button("Bottom");
		add(bottomButton, BorderLayout.SOUTH);

		Button rightButton = new Button("Right");
		add(rightButton, BorderLayout.EAST);

		Button leftButton = new Button("Left");
		add(leftButton, BorderLayout.WEST);

		Button middleButton = new Button("Middle");
		add(middleButton, BorderLayout.CENTER);
	}
}

Description and Objective

An applet that uses an explicitly specified layout manager.

Notes

Layout BorderLayout

This Applet's Behavior

The init Method

Things to Do

API work Playing With the Applet Place the following three applets on the same page:
  1. Wire up the buttons to send messages to the console
  2. Modify AnAppletWithLayoutChange to use FlowLayout
  3. Code an applet with 10 buttons positioned like a phone keypad (using GridLayout) -- wire them up so that when pressed they display the proper value (0-9 *, #) on the console. (Optional- add logic to simulate dialing a phone with the following behavior:
    • Pressing '#' two times in a row indicates a number is about to be dialed
    • Dialed numbers must be 10 digitis preceded by a '1'
    • After the 10 digit number has been dialed, a message such as 'Phone number (718) 951-5000 has been dialed."
    • Once a number has been dialed pressing * twice terminates the call (i.e., displays a message "End of call").
    • During a call, entering anything but '*' results in a a warning message such as "please don't touch keypad during call" is displayed. )