Case Study Fall 2017
The answers to the Case Study Fall 2017 is given below:
package personal.assignment;
import javax.swing.*;
import java.awt.event.*;
public class thridQuestion {
public static void main(String[] args) {
JFrame frame = new JFrame(“Design Preview”);
frame.setSize(300,400);
JPanel panel = new JPanel();
frame.add(panel);
panel.setLayout(null);
JLabel id = new JLabel(“Patient ID:”);
id.setBounds(20, 30, 100, 20);
panel.add(id);
JTextField idT = new JTextField();
idT.setBounds(100, 30, 130, 20);
panel.add(idT);
JLabel fname = new JLabel(“Full Name:”);
fname.setBounds(20, 70, 100, 20);
panel.add(fname);
JTextField fnameT = new JTextField();
fnameT.setBounds(100, 70, 130, 20);
panel.add(fnameT);
JLabel gender = new JLabel(“Gender:”);
gender.setBounds(20, 100, 100, 20);
panel.add(gender);
JRadioButton b1 = new JRadioButton(“Male”);
b1.setBounds(100, 100, 60, 20);
panel.add(b1);
JRadioButton b2 = new JRadioButton(“Female”);
b2.setBounds(160, 100, 70, 20);
panel.add(b2);
ButtonGroup bg = new ButtonGroup();
bg.add(b1);
bg.add(b2);
JLabel address = new JLabel(“Address:”);
address.setBounds(20, 140, 100, 20);
panel.add(address);
JTextField addressT = new JTextField();
addressT.setBounds(100, 140, 130, 20);
panel.add(addressT);
JLabel contact = new JLabel(“Contact:”);
contact.setBounds(20, 180, 100, 20);
panel.add(contact);
JTextField contactT = new JTextField();
contactT.setBounds(100, 180, 130, 20);
panel.add(contactT);
JLabel email = new JLabel(“Email ID:”);
email.setBounds(20, 220, 100, 20);
panel.add(email);
JTextField emailT = new JTextField();
emailT.setBounds(100, 220, 130, 20);
panel.add(emailT);
JButton addB = new JButton(“Add”);
addB.setBounds(30, 260, 100, 30);
panel.add(addB);
addB.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JDialog dialog = new JDialog(frame,”Details”);
dialog.setSize(100, 200);
JPanel panel1 = new JPanel();
JLabel texts = new JLabel();
JLabel text1 = new JLabel();
JLabel text2 = new JLabel();
JLabel text3 = new JLabel();
JLabel text4 = new JLabel();
texts.setText(idT.getText().toString());
text1.setText(fnameT.getText().toString());
text2.setText(addressT.getText().toString());
text3.setText(contactT.getText().toString());
text4.setText(emailT.getText().toString());
panel1.add(texts);
panel1.add(text1);
panel1.add(text2);
panel1.add(text3);
panel1.add(text4);
dialog.add(panel1);
dialog.setVisible(true);
JOptionPane.showConfirmDialog(frame,”Do you want to continue?”);
}
});
JButton cancelB = new JButton(“Cancel”);
cancelB.setBounds(140, 260, 100, 30);
panel.add(cancelB);
frame.setVisible(true);
}
}
You may also likeĀ Pokhara University || Fall 2017 || Object Oriented Programming
Leave a Reply