Case Study Spring 2017
The answer to the Case Study Spring 2017 are given below:
package personal.assignment;
import javax.swing.*;
public class fourthQuestionA {
public static void main(String[] args) {
JFrame frame = new JFrame(“Please Login”);
frame.setSize(350, 150);
JPanel panel = new JPanel();
frame.add(panel);
panel.setLayout(null);
JLabel login = new JLabel(“Username: “);
login.setBounds(20, 10, 100, 20);
panel.add(login);
JTextField loginT = new JTextField();
loginT.setBounds(90, 10, 220, 20);
panel.add(loginT);
JLabel password = new JLabel(“Password: “);
password.setBounds(20, 40, 100, 20);
panel.add(password);
JTextField passwordT = new JTextField();
passwordT.setBounds(90, 40, 220, 20);
panel.add(passwordT);
JButton loginB = new JButton(“Login”);
loginB.setBounds(20, 70, 70, 20);
panel.add(loginB);
JButton regB = new JButton(“Register User”);
regB.setBounds(100, 70, 130, 20);
panel.add(regB);
JButton closeB = new JButton(“Close”);
closeB.setBounds(240, 70, 70, 20);
panel.add(closeB);
frame.setVisible(true);
}
}
package personal.assignment;
import javax.swing.*;
import java.awt.event.*;
public class fourthQuestionB {
public static void main(String[] args) {
JFrame frame = new JFrame(“Register User”);
frame.setSize(400, 260);
JPanel panel = new JPanel();
frame.add(panel);
panel.setLayout(null);
JLabel id = new JLabel(“ID:”);
id.setBounds(20, 20, 100, 20);
panel.add(id);
JTextField idT = new JTextField();
idT.setBounds(120, 20, 230, 20);
panel.add(idT);
JLabel fname = new JLabel(“First Name:”);
fname.setBounds(20, 50, 100, 20);
panel.add(fname);
JTextField fnameT = new JTextField();
fnameT.setBounds(120, 50, 230, 20);
panel.add(fnameT);
JLabel lname = new JLabel(“Last Name:”);
lname.setBounds(20, 80, 100, 20);
panel.add(lname);
JTextField lnameT = new JTextField();
lnameT.setBounds(120, 80, 230, 20);
panel.add(lnameT);
JLabel uname = new JLabel(“Username:”);
uname.setBounds(20, 110, 100, 20);
panel.add(uname);
JTextField unameT = new JTextField();
unameT.setBounds(120, 110, 230, 20);
panel.add(unameT);
JLabel password = new JLabel(“Password:”);
password.setBounds(20, 140, 100, 20);
panel.add(password);
JTextField passwordT = new JTextField();
passwordT.setBounds(120, 140, 230, 20);
panel.add(passwordT);
JButton addB = new JButton(“Add”);
addB.setBounds(40, 170, 90, 20);
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 text1 = new JLabel();
JLabel text2 = new JLabel();
JLabel text3 = new JLabel();
JLabel text4 = new JLabel();
JLabel text5 = new JLabel();
text1.setText(idT.getText().toString());
text2.setText(fnameT.getText().toString());
text3.setText(lnameT.getText().toString());
text4.setText(unameT.getText().toString());
text5.setText(passwordT.getText().toString());
panel1.add(text1);
panel1.add(text2);
panel1.add(text3);
panel1.add(text4);
panel1.add(text5);
dialog.add(panel1);
JOptionPane.showConfirmDialog(frame,”Do you want to continue?”);
dialog.setVisible(true);
}
});
JButton resetB = new JButton(“Reset”);
resetB.setBounds(150, 170, 90, 20);
panel.add(resetB);
JButton closeB = new JButton(“Close”);
closeB.setBounds(260, 170, 90, 20);
panel.add(closeB);
frame.setVisible(true);
}
}
You may also like Pokhara University || Spring 2017 || Object Oriented Programming
Leave a Reply