0% found this document useful (0 votes)
3 views3 pages

Java Code

The document contains Java code for a graphical user interface (GUI) that collects student information, including name, roll number, and gender. It features buttons for submitting and clearing the form, along with event handling to display the collected data. The GUI is built using Swing components and is designed to ensure all fields are filled before submission.

Uploaded by

aishwaryaxg1007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Java Code

The document contains Java code for a graphical user interface (GUI) that collects student information, including name, roll number, and gender. It features buttons for submitting and clearing the form, along with event handling to display the collected data. The GUI is built using Swing components and is designed to ensure all fields are filled before submission.

Uploaded by

aishwaryaxg1007
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

NAME: AISHWARYA GADHAVE

ROLL NO: 22016


BATCH: A1
SUBJECT: SKILL ENHANCEMENT LAB
ASSIGNMENT NO: 11

CODE:

import [Link].*;
import [Link].*;
import [Link].*;

public class StudentInfoGUI implements ActionListener, ItemListener {

JFrame frame;
JLabel titleLabel, nameLabel, rollLabel, genderLabel, resultLabel;
JTextField nameField, rollField;
JRadioButton male, female;
JButton submit, clear;
ButtonGroup group;

String gender = "";

public StudentInfoGUI() {

// Frame
frame = new JFrame("Student Information Form");
[Link](400, 350);
[Link](new GridLayout(6, 2, 10, 10));

// Title
titleLabel = new JLabel("Student Form", [Link]);
[Link](new Font("Arial", [Link], 16));

// Labels
nameLabel = new JLabel("Name:");
rollLabel = new JLabel("Roll No:");
genderLabel = new JLabel("Gender:");
resultLabel = new JLabel("");

// Text Fields
nameField = new JTextField();
rollField = new JTextField();
// Radio Buttons
male = new JRadioButton("Male");
female = new JRadioButton("Female");

// Grouping Radio Buttons


group = new ButtonGroup();
[Link](male);
[Link](female);

// Buttons
submit = new JButton("Submit");
clear = new JButton("Clear");
// Event Handling
[Link](this);
[Link](this);
[Link](this);
[Link](this);

// Add Components
[Link](titleLabel);
[Link](new JLabel("")); // empty space

[Link](nameLabel);
[Link](nameField);

[Link](rollLabel);
[Link](rollField);

[Link](genderLabel);

JPanel genderPanel = new JPanel();


[Link](male);
[Link](female);
[Link](genderPanel);

[Link](submit);
[Link](clear);

[Link](new JLabel("Output:"));
[Link](resultLabel);

// Frame Settings
[Link](JFrame.EXIT_ON_CLOSE);
[Link](true);
}

// Button Events
public void actionPerformed(ActionEvent e) {
if ([Link]() == submit) {
String name = [Link]();
String roll = [Link]();

if ([Link]() || [Link]() || [Link]("")) {


[Link](frame, "Please fill all fields!");
} else {
[Link]("Name: " + name + ", Roll: " + roll + ", Gender: " + gender);
}
}

if ([Link]() == clear) {
[Link]("");
[Link]("");
[Link]();
gender = "";
[Link]("");
}
}

// Radio Button Events


public void itemStateChanged(ItemEvent e) {
if ([Link]()) {
gender = "Male";
} else if ([Link]()) {
gender = "Female";
}
}

public static void main(String[] args) {


new StudentInfoGUI();
}
}

You might also like