0% found this document useful (0 votes)
4 views

Java_Applet_Programs

The document provides two Java applet programs: the first demonstrates the use of radio buttons and checkboxes, allowing users to select options with a visual label update, while the second creates a simple form with a text field, button, and label that greets the user upon submission. Both applets utilize Swing and AWT for their graphical user interfaces. The code snippets are included for implementation.

Uploaded by

mayankshinde0116
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Java_Applet_Programs

The document provides two Java applet programs: the first demonstrates the use of radio buttons and checkboxes, allowing users to select options with a visual label update, while the second creates a simple form with a text field, button, and label that greets the user upon submission. Both applets utilize Swing and AWT for their graphical user interfaces. The code snippets are included for implementation.

Uploaded by

mayankshinde0116
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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 javax.swing.*;

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();

bg.add(rb1); bg.add(rb2);

JLabel label = new JLabel("Select options");

cb1.addActionListener(e -> label.setText(cb1.isSelected() ? "Option 1" : "Unchecked"));

rb1.addActionListener(e -> label.setText(rb1.isSelected() ? "Radio 1" : "Radio 2"));

frame.add(cb1); frame.add(cb2); frame.add(rb1); frame.add(rb2); frame.add(label);

frame.setLayout(new java.awt.FlowLayout());

frame.setSize(200, 150);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(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 java.applet.Applet;

import java.awt.*;

import java.awt.event.*;

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);
submitButton.addActionListener(this);

public void actionPerformed(ActionEvent e) {

output.setText("Hello, " + nameField.getText());

/*

<applet code="SmallFormApplet" width=300 height=150>

</applet>

*/

You might also like