Java Applet Programs
Q.1. Design an applet to demonstrate the use of radio button and checkbox.
Below is the Java program demonstrating radio buttons and checkboxes:
import [Link].*;
public class SmallDemo {
public static void main(String[] args) {
JFrame frame = new JFrame("Demo");
JCheckBox cb1 = new JCheckBox("Option 1");
JCheckBox cb2 = new JCheckBox("Option 2");
JRadioButton rb1 = new JRadioButton("Radio 1");
JRadioButton rb2 = new JRadioButton("Radio 2");
ButtonGroup bg = new ButtonGroup();
[Link](rb1); [Link](rb2);
JLabel label = new JLabel("Select options");
[Link](e -> [Link]([Link]() ? "Option 1" : "Unchecked"));
[Link](e -> [Link]([Link]() ? "Radio 1" : "Radio 2"));
[Link](cb1); [Link](cb2); [Link](rb1); [Link](rb2); [Link](label);
[Link](new [Link]());
[Link](200, 150);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}
Q.2. Design an applet to create form using Text field, Text area, Button, and Label.
Below is a simple Java applet for creating a form:
import [Link];
import [Link].*;
import [Link].*;
public class SmallFormApplet extends Applet implements ActionListener {
TextField nameField;
Button submitButton;
Label output;
public void init() {
add(new Label("Name:"));
nameField = new TextField(15);
add(nameField);
submitButton = new Button("Submit");
add(submitButton);
output = new Label("");
add(output);
[Link](this);
public void actionPerformed(ActionEvent e) {
[Link]("Hello, " + [Link]());
/*
<applet code="SmallFormApplet" width=300 height=150>
</applet>
*/