0% found this document useful (0 votes)
52 views6 pages

Oop Lab - 11: University of Engineering and Technology, Taxila

The document describes code for a Java program that creates a GUI frame called "Information" using Swing components like labels, text fields, radio buttons, combo boxes, and buttons to collect user information. The code defines event handlers for buttons to submit the information or clear the fields. When submitted, the data is displayed in a text area on the frame.

Uploaded by

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

Oop Lab - 11: University of Engineering and Technology, Taxila

The document describes code for a Java program that creates a GUI frame called "Information" using Swing components like labels, text fields, radio buttons, combo boxes, and buttons to collect user information. The code defines event handlers for buttons to submit the information or clear the fields. When submitted, the data is displayed in a text area on the frame.

Uploaded by

Neha Asif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

University of Engineering and Technology, Taxila

Department of Software Engineering

OOP LAB_11

Submitted To:
Miss Sidra Shafi

Submitted By:
Neha Asif(19-SE-49)
Create the following Frame titled “Information” using Abstract Window Toolkit.

CODE:

package lab11;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.Scrollbar;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JTextPane;
import javax.swing.JScrollBar;
import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;
public class frame extends JFrame {
private JPanel contentPane;
private JRadioButton male;
private JRadioButton female;
JLabel display;
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JTextField fname;
private JTextField lname;
private JComboBox q1;
private JComboBox comboBox;
private JLabel label4;
private JButton cancel;
private JTextPane textPane;
private JScrollBar scrollBar;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
frame frame = new frame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 788, 601);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
display = new JLabel("");
display.setBounds(32, 436, 730, 102);
display.setVisible(false);
scrollBar = new JScrollBar();
scrollBar.addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
}
});
scrollBar.setBounds(183, 57, 17, 69);
contentPane.add(scrollBar);
textPane = new JTextPane();
textPane.setBounds(101, 57, 99, 69);
contentPane.add(textPane);
contentPane.add(display);
JLabel gender = new JLabel("Gender");
gender.setFont(new Font("Ariel", Font.BOLD, 12));
gender.setBounds(441, 1, 46, 43);
contentPane.add(gender);
male = new JRadioButton("male");
male.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(male.isSelected())
{
female.setSelected(false);
}
}
});
male.setBounds(493, 11, 75, 23);
contentPane.add(male);
female = new JRadioButton("female");
female.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(female.isSelected())
{
male.setSelected(false);
}
}
});
female.setBounds(570, 11, 83, 23);
contentPane.add(female);
JButton btnNewButton = new JButton("submit");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String selection = null;
if(male.isSelected())
selection ="Male";
if(female.isSelected())
selection ="Female";
String value= comboBox.getSelectedItem().toString();
String value1= q1.getSelectedItem().toString();
display.setText(label1.getText()+": "+fname.getText()+" "+label2.getText()+":
"+lname.getText()+" "+gender.getText()+": "+selection+" "+label3.getText()+":"+"
"+value+" "+value1+" "+label4.getText()+": "+textPane.getText());
display.setVisible(true);
}
});
btnNewButton.setBounds(127, 352, 89, 23);
contentPane.add(btnNewButton);
label1 = new JLabel("First Name ");
label1.setFont(new Font("Ariel", Font.BOLD, 12));
label1.setBounds(29, 11, 66, 23);
contentPane.add(label1);
label2 = new JLabel("Last Name");
label2.setFont(new Font("Ariel", Font.BOLD, 12));
label2.setBounds(221, 11, 66, 23);
contentPane.add(label2);
fname = new JTextField();
fname.setBounds(101, 12, 99, 20);
contentPane.add(fname);
fname.setColumns(10);
lname = new JTextField();
lname.setBounds(288, 12, 106, 20);
contentPane.add(lname);
lname.setColumns(10);
String [] items = { "Post Graduate", "Under-Graduate", "PHD" };
comboBox = new JComboBox(items);
comboBox.setBounds(112, 169, 127, 22);
contentPane.add(comboBox);
label3 = new JLabel("Qualification");
label3.setFont(new Font("Times New Roman", Font.BOLD, 12));
label3.setBounds(24, 169, 71, 22);
contentPane.add(label3);
String [] item = { "Software Engineer", "Civil Engineer", "Mechanical
Engineer","Electrical Engineer","Computer Engineer","Computer Science","Industrial
Engineer","Enviromental Engineer","Telecom Engineer" };
q1 = new JComboBox(item);
q1.setBounds(250, 169, 127, 22);
contentPane.add(q1);
label4 = new JLabel("Address");
label4.setFont(new Font("Ariel", Font.BOLD, 12));
label4.setBounds(32, 80, 63, 23);
contentPane.add(label4);
cancel = new JButton("Cancel");
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fname.setText("");
lname.setText("");
textPane.setText("");
}
});
cancel.setBounds(268, 352, 89, 23);
contentPane.add(cancel);
}
}
OUTPUT:

You might also like