Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Working Applet
Help and Hints
Source Code
Table of Contents
Online Training
shadowSearchFAQFeedback

RatioLayout Help

Help is available for each task, or you can go straight to the RatioLayout source code to see a solution.

The course code for RatioLayout is also useful to examine.

Task 1

Create an Applet managed by a RatioLayout.

import java.awt.*;
public class RatioLayoutTest extends java.applet.Applet {
    public void init() {
        setLayout(new RatioLayout());
        ...
    }
}

Task 2

Create a Label ("A RatioLayout Test Applet") and center it 10% down from the top of the applet.

In the method init, add the following code after the setLayout call.

add("c,.1", new Label("A RatioLayout Test Applet"));

Task 3

Create a Button ("Button") and center it in both x and y using its preferred size.

In the method init, add the following code after the setLayout call.

add("c,c",  new Button("Button"));

Task 4

Create a TextArea against the left edge 70% down from the top of the applet. Set the size to be 50% of the width and make it span down to the bottom of the applet (%30 of the height).

In the method init, add the following code after the setLayout call.

add("0,.7;.5,.3", new TextArea());

Task 5

Create a Button ("OK") 70% across and 70% down using the preferred size.

In the method init, add the following code after the setLayout call.

add(".7,.7", new Button("OK"));

Task 6

Create a Button ("BYE") 70% across and 85% down using the preferred size.

In the method init, add the following code after the setLayout call.

add(".7,.85", new Button("BYE"));