(^666) | Applets
Label entryLabel; // Label for input field
Button add;
Button subtract;
Button clear;
result = 0.0;
// Instantiate labels and initialize input field
resultLabel = new Label("Result:");
register = new Label("0.0", Label.RIGHT);
entryLabel = new Label("Enter #:");
inputField = new TextField("", 10);
Notice that no Frame(or JFrame) items have been declared or instantiated. The applet
already has its own window.
// Instantiate button objects
add = new Button("+");
subtract = new Button("-");
clear = new Button("Clear");
// Register the button listener with the buttons
add.addActionListener(this);
subtract.addActionListener(this);
clear.addActionListener(this);
// Add interface elements to applet window
setLayout(new GridLayout(4,2)); // Set the layout manager
add(resultLabel);
add(register);
add(entryLabel);
add(inputField);
add(add);
add(subtract);
add(clear);
}
}
Here is how this applet appears on the screen.
やまだぃちぅ
(やまだぃちぅ)
#1