|
|
Web Configuration:
<applet code="CheckLabel.class"
codebase="applet" width=250 height=100>
</applet>
Source Code
/* CheckLabel.java
*
* This example creates a checkbox and a text field. Pressing
* Return in throwse textfield causes the ckeckbox label to
* be set to the contents of the text field. When the label
* changes, so does its minimum size. This example also shows
* how to cause the checkbox's parent to properly resize the
* checkbox.
*/
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class CheckLabel extends java.applet.Applet implements
ActionListener{
Checkbox cb = new Checkbox("Checkbox");
TextField tf = new TextField(40);
public void init () {
setLayout(new BorderLayout());
add(new Canvas(), BorderLayout.CENTER);
add(cb, BorderLayout.WEST);
add(tf, BorderLayout.SOUTH);
tf.setText(cb.getLabel());
tf.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
cb.setLabel(tf.getText());
// Invalidate this checkbox to resize checkbox
cb.invalidate();
// Validate parent to resize checkbox
cb.getParent().validate();
}
} |