Oop Project Reports
Oop Project Reports
OOP
PROJECT REPORT
Participants:
Hamza Nazir
(NUML-S22-27839)
Zeeshan Abbas
(NUML-S22-37638)
Subhan Saeed
(NUML-S22-41887)
Hassan Shakeel
(NUML-S22-13874)
Submitted to:
Sir bilal
DATE:05/01/2023
Description
How to login or set up your account:
In this project we created 3 frame of separate classes. The 1 st frame is set to be login frame
named as login_game user enter username and password if you don,t have an account simply
click sign up and it will route you to sign up frame (2 nd frame) named as set_up_login and
create account by entering your information and press sign up. And your account will be set
up. Then you will be routed to 1 st frame where you have to enter your information and tap on
log in. 2nd frame has an additional button as well that will route on 1 st frame if you already an
account and if you tap on sign up by mistake.
Game description:
3rd frame is game frame named as game_project.It is simple rock paper scissor game. It has
three buttons, named as rock paper scissor. It is two person game.But in our it is one person
and other is computer.It has a set of rules that are Rock crushes scissors, scissors cut paper,
and paper covers rock. It will have five rounds the one who has scored more will be winner.
And a dialog box will pop up which will show you result and it has two option at the bottom
through which you can restart the game by pressing “ ok ” or you can simply close the game
by pressing “cancel”.
First Frame(login_game):
import javax.swing.*;
import java.awt.event.*;
String username;
String password;
JFrame f;
JTextField ttf1;
JPasswordField ttf2;
JLabel l1, l2, l3;
JButton B1, B2;
// login_game(){
f = new JFrame("login");
JLabel lab=new JLabel("If you have already account fill these
instruction ");
JLabel lab1=new JLabel("click login If you don't have account click
sign up ");
lab1.setBounds(05,15,300,30);
lab.setBounds(05,0,300,30);
B1 = new JButton("login");
B1.setBounds(50, 210, 95, 50);
B2 = new JButton("sign up");
B2.setBounds(50, 275, 95, 50);
l1 = new JLabel("user name");
l1.setBounds(50, 70, 150, 25);// l1.setEditable(false);
ttf1 = new JTextField();
ttf1.setBounds(50, 95, 150, 25);
l2 = new JLabel("password");
l2.setBounds(50, 130, 150, 25);// l1.setEditable(false);
l3 = new JLabel();
l3.setBounds(50, 180, 400, 25);// l1.setEditable(false);
ttf2 = new JPasswordField();
ttf2.setBounds(50, 155, 150, 25);
f.add(lab);f.add(lab1);
f.add(l3);
f.add(B1);
f.add(l1);
f.add(l2);
f.add(ttf2);
f.add(ttf1);
//f.add(B);
f.add(B2);
f.setSize(310, 400);
f.setLayout(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
B1.addActionListener(this);
B2.addActionListener(this);
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == B1) {
{
new game_project();
f.dispose();
} else if (usertf1 != username)
{
l3.setText("your username is incorrect pleae try gain");
} else {
l3.setText("your password is incorrect pleae try gain");
}
}
if (e.getSource() == B2) {
new set_up_login();
f.dispose();
}
}
}
Output:
Second Frame(set_up_login):
import javax.swing.*;
import java.awt.event.*;
JTextField tf1,tf2,tf3;
JLabel l1,l2,l3;
JButton B1, B2;
set_up_login()
{
f=new JFrame("sign Up");
JLabel lab=new JLabel("If you have already account click login If you
");
JLabel lab1=new JLabel("crate account fill these instruction click sign
up ");
lab1.setBounds(05,15,300,30);
lab.setBounds(05,0,300,30);
B1=new JButton("Sign up"); B1.setBounds(50, 245, 95, 50);
B2=new JButton("login"); B2.setBounds(50, 305, 95, 50);
l1=new JLabel("Complete Name"); l1.setBounds(50,70,150,25);//
l1.setEditable(false);
tf1=new JTextField();tf1.setBounds(50,95,150,25);
l2=new JLabel("Username");l2.setBounds(50,130,150,25);//
l1.setEditable(false);
tf2=new JTextField();tf2.setBounds(50,155,150,25);
l3=new JLabel("Password");l3.setBounds(50,180,150,25);//
l1.setEditable(false);
tf3=new
JTextField();tf3.setBounds(50,205,150,25);tf3.setEditable(true);
f.add(B1);f.add(B2);f.add(l1);f.add(l2);f.add(l3);f.add(tf2);f.add(tf1);f.add(t
f3);f.add(lab);f.add(lab1);
f.setSize(310,500);
f.setLayout(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
B1.addActionListener(this);
B2.addActionListener(this);
@Override
public void actionPerformed(ActionEvent e) {
//String box1 = tf1.getText();
String box2 = tf2.getText();
String box3 = tf3.getText();
if (e.getSource() == B1) {
new login_game(box2,box3);
f.dispose();
}
}
Output:
Third frame(game_project):
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
int round=0;
game_project()
{
f=new JFrame("Rock Paper Scissors Game");
JLabel lab=new JLabel("This game have 5 rounds");
// JLabel lab1=new JLabel("Rock crushes scissors, scissors cut paper,
and paper covers rock");
// lab1.setBounds(05,15,400,30);
lab.setBounds(05,0,400,30); f.add(lab);//f.add(lab1);
show_result =new JTextField();
show_result.setBounds(7,280,420,30);
show_result.setEditable(false);
// Image Icon = Toolkit.getDefaultToolkit().getImage("hamza1");
// f.setIconImage(Icon);
rockButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
round ++;
game_start(0);
}
});
paperButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
round ++;
game_start(1);
}
});
scissorsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
round ++;
game_start(2);
}
});
f.add(show_result);
f.add(rockButton);
f.add(paperButton);
f.add( scissorsButton);
f.add(tf_for_your_scour);
f.add(label_for_your_scour);
f.add(label_for_cop_scour);
f.add(tf_for_cop_scour);
f.add(label_for_tie);
f.add(tf_for_tie);
f.setSize( 450,400);
f.setLayout(null);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
int n1 = abc;
int n2 = rc.nextInt(0, 2);
++ties;
String a = String.valueOf(ties);
tf_for_tie.setText(a);
show_result.setText("This round is tie");
++user;
String user1 = String.valueOf(user);
tf_for_your_scour.setText(user1);
show_result.setText(" you win this round ");
}
if ((n2 == 1 && n1 == 0 || n2 == 0 && n1 == 2) || (n2 == 2 && n1 == 1))
{
++com;
String com1 = String.valueOf(com);
tf_for_cop_scour.setText(com1);
show_result.setText("oops! you lose this round");
if (round == 5) {
show_result.setText("Game over! ");
rockButton.setEnabled(false);
paperButton.setEnabled(false);
scissorsButton.setEnabled(false);
JFrame f1 = new JFrame();
if (com > user) {
int a = JOptionPane.showConfirmDialog(f, "oops! you loss the
innings");
if (a == JOptionPane.YES_OPTION) {
f.dispose();
new game_project();
} else {
f.dispose();
}
} else if (user > com) {
int a = JOptionPane.showConfirmDialog(f, "congratulations you
win the innings");
if (a == JOptionPane.YES_OPTION) {
f.dispose();
new game_project();
} else {
f.dispose();
}
} else {
int a = JOptionPane.showConfirmDialog(f, "innings is tie");
if (a == JOptionPane.YES_OPTION) {
f.dispose();
new game_project();
} else {
f.dispose();
}
}
}
}
}
Output:
Result