Practical 14
Practical 14
Conclusion
In this practical, we wrote a program to design a form using AWT components. We used
components like buttons, text fields, and labels to create a basic user interface in Java.
Swi() {
setTitle("Radio Button & Checkbox Demo");
setSize(400, 300);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Radio Buttons
rb1 = new JRadioButton("Male");
rb2 = new JRadioButton("Female");
rb1.setBounds(50, 30, 100, 30);
rb2.setBounds(150, 30, 100, 30);
// Checkboxes
cb1 = new JCheckBox("Java");
cb2 = new JCheckBox("Python");
cb1.setBounds(50, 80, 100, 30);
cb2.setBounds(150, 80, 100, 30);
// Submit Button
submitButton = new JButton("Submit");
submitButton.setBounds(100, 130, 100, 30);
submitButton.addActionListener(this);
// Result Label
resultLabel = new JLabel("");
resultLabel.setBounds(50, 180, 300, 30);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String gender = rb1.isSelected() ? "Male" : rb2.isSelected() ? "Female" : "Not Selected";
String skills = "";
if (cb1.isSelected()) skills += "Java ";
if (cb2.isSelected()) skills += "Python";
if (skills.isEmpty()) skills = "No skills selected";
resultLabel.setText("Gender: " + gender + ", Skills: " + skills);
}
Jamia Polytechnic Akkalkuwa Page No:2 Prepared by: Sayyed Waliullah
Java Programming Practical:14 Lab Manual (Solved)
import javax.swing.*;
import java.awt.event.*;
FormApp() {
setTitle("Simple Form");
setSize(300, 300);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
ButtonApp() {
setTitle("Button Example");
setSize(300, 200);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
okButton.addActionListener(this);
resetButton.addActionListener(this);
cancelButton.addActionListener(this);
setVisible(true);
}
add(scrollPane);
setVisible(true);
}
public static void main(String[] args) {
new CityListApp();
}
}
Jamia Polytechnic Akkalkuwa Page No:5 Prepared by: Sayyed Waliullah
Java Programming Practical:14 Lab Manual (Solved)
newspaperList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTIO
N);
JScrollPane scrollPane = new JScrollPane(newspaperList);
scrollPane.setBounds(30, 30, 180, 120);
add(scrollPane);
setVisible(true);
}