├── Images
├── 01.jpg
└── java.jpg
├── Tic-Tac-Toe
├── logo.jpg
├── output.png
├── README.md
└── Game.java
├── Document Downloader
├── logo.jpg
└── URLMainGUI.java
├── ParkingSystem
├── Test
│ ├── home.png
│ ├── logo.png
│ ├── ParkingManagementDemo.java
│ └── ParkingManagementGUI.java
├── Service
│ ├── ParkingManagementSQL.java
│ ├── ResidentVehicle.java
│ ├── Vehicle.java
│ ├── VisitorVehicle.java
│ └── ParkingManagement.java
└── Exceptions
│ ├── VehicleNotFoundException.java
│ └── ParkingSlotNotAvailableException.java
└── README.md
/Images/01.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/Images/01.jpg
--------------------------------------------------------------------------------
/Images/java.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/Images/java.jpg
--------------------------------------------------------------------------------
/Tic-Tac-Toe/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/Tic-Tac-Toe/logo.jpg
--------------------------------------------------------------------------------
/Tic-Tac-Toe/output.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/Tic-Tac-Toe/output.png
--------------------------------------------------------------------------------
/Document Downloader/logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/Document Downloader/logo.jpg
--------------------------------------------------------------------------------
/ParkingSystem/Test/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/ParkingSystem/Test/home.png
--------------------------------------------------------------------------------
/ParkingSystem/Test/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/rohinth076/Java-Projects/HEAD/ParkingSystem/Test/logo.png
--------------------------------------------------------------------------------
/ParkingSystem/Service/ParkingManagementSQL.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Service;
2 |
3 |
4 |
5 | public class ParkingManagementSQL {
6 |
7 | public ParkingManagementSQL(){
8 |
9 | }
10 |
11 |
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/ParkingSystem/Exceptions/VehicleNotFoundException.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Exceptions;
2 |
3 | public class VehicleNotFoundException extends Throwable {
4 | public VehicleNotFoundException() {
5 | }
6 |
7 | public VehicleNotFoundException(String message) {
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/ParkingSystem/Exceptions/ParkingSlotNotAvailableException.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Exceptions;
2 |
3 | public class ParkingSlotNotAvailableException extends Throwable {
4 | public ParkingSlotNotAvailableException() {
5 | }
6 |
7 | public ParkingSlotNotAvailableException(String message) {
8 | super(message);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/Tic-Tac-Toe/README.md:
--------------------------------------------------------------------------------
1 | # 🕹 Tic-Tac-Toe
2 |
3 | ### This Project contains the game Tic-Tac-Toe(XO) .
4 |
5 | - All the rules are same .
6 |
7 | - Game Between the two users (Not computer) .
8 |
9 |
10 |
11 | ### 🌉 Use the following to run the code:
12 |
13 |
14 |
15 | ```
16 | In command prompt :
17 |
18 | For complie : javac Game.java
19 |
20 | For Run : java Game
21 |
22 | ```
23 |
24 |
25 | Output :
26 |
27 | 
--------------------------------------------------------------------------------
/ParkingSystem/Service/ResidentVehicle.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Service;
2 |
3 | public class ResidentVehicle extends Vehicle{
4 | private int flatNo;
5 | private boolean parkingStatus;
6 |
7 | public ResidentVehicle(String regNumber, String ownerName, long mobileNo, int flatNo, boolean parkingStatus) {
8 | super(regNumber, ownerName, mobileNo);
9 | this.flatNo = flatNo;
10 | this.parkingStatus = parkingStatus;
11 | }
12 |
13 | public int getFlatNo() {
14 | return flatNo;
15 | }
16 |
17 | public void setFlatNo(int flatNo) {
18 | this.flatNo = flatNo;
19 | }
20 |
21 | public boolean isParkingStatus() {
22 | return parkingStatus;
23 | }
24 |
25 | public void setParkingStatus(boolean parkingStatus) {
26 | this.parkingStatus = parkingStatus;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return super.toString()+
32 | "flatNo= " + flatNo +" "+
33 | ", parkingStatus= " + parkingStatus+"\n";
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/ParkingSystem/Service/Vehicle.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Service;
2 |
3 | public class Vehicle {
4 | private String regNumber;
5 | private String ownerName;
6 | private long mobileNo;
7 |
8 | public Vehicle(String regNumber, String ownerName, long mobileNo) {
9 | this.regNumber = regNumber;
10 | this.ownerName = ownerName;
11 | this.mobileNo = mobileNo;
12 | }
13 |
14 | public String getRegNumber() {
15 | return regNumber;
16 | }
17 |
18 | public void setRegNumber(String regNumber) {
19 | this.regNumber = regNumber;
20 | }
21 |
22 | public String getOwnerName() {
23 | return ownerName;
24 | }
25 |
26 | public void setOwnerName(String ownerName) {
27 | this.ownerName = ownerName;
28 | }
29 |
30 | public long getMobileNo() {
31 | return mobileNo;
32 | }
33 |
34 | public void setMobileNo(long mobileNo) {
35 | this.mobileNo = mobileNo;
36 | }
37 |
38 | @Override
39 | public String toString() {
40 | return "regNumber= " + regNumber + " "+
41 | ", ownerName= " + ownerName + " " +
42 | ", mobileNo=" + mobileNo+ " ";
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ParkingSystem/Service/VisitorVehicle.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Service;
2 |
3 | public class VisitorVehicle extends Vehicle{
4 | private int visitingFlatNumber;
5 | private String inTime;
6 | private String outTime;
7 |
8 | public VisitorVehicle(String regNumber, String ownerName, long mobileNo, int visitingFlatNumber, String inTime) {
9 | super(regNumber, ownerName, mobileNo);
10 | this.visitingFlatNumber = visitingFlatNumber;
11 | this.inTime = inTime;
12 | this.outTime = null;
13 | }
14 |
15 | public int getVisitingFlatNumber() {
16 | return visitingFlatNumber;
17 | }
18 |
19 | public void setVisitingFlatNumber(int visitingFlatNumber) {
20 | this.visitingFlatNumber = visitingFlatNumber;
21 | }
22 |
23 | public String getInTime() {
24 | return inTime;
25 | }
26 |
27 | public void setInTime(String inTime) {
28 | this.inTime = inTime;
29 | }
30 |
31 | public String getOutTime() {
32 | return outTime;
33 | }
34 |
35 | public void setOutTime(String outTime) {
36 | this.outTime = outTime;
37 | }
38 |
39 | @Override
40 | public String toString() {
41 | return super.toString()+
42 | "visitingFlatNumber= " + visitingFlatNumber +" "+
43 | ", inTime= " + inTime + " "+
44 | ", outTime= " + outTime+"\n" ;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ParkingSystem/Test/ParkingManagementDemo.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Test;
2 |
3 | import ParkingSystem.Exceptions.ParkingSlotNotAvailableException;
4 | import ParkingSystem.Exceptions.VehicleNotFoundException;
5 | import ParkingSystem.Service.ParkingManagement;
6 | import ParkingSystem.Service.ResidentVehicle;
7 | import ParkingSystem.Service.Vehicle;
8 | import ParkingSystem.Service.VisitorVehicle;
9 |
10 | public class ParkingManagementDemo
11 | {
12 | public static void main(String[] args) throws ParkingSlotNotAvailableException, VehicleNotFoundException {
13 | ParkingManagement pm = new ParkingManagement();
14 | Vehicle v1 = new ResidentVehicle("Tn472","Dharanie",12345667,100,true);
15 | Vehicle v2 = new ResidentVehicle("Tn572","Simren",98765432,200,false);
16 | Vehicle v3 = new ResidentVehicle("Tn123","Nila",45367281,300,true);
17 | Vehicle v4 = new VisitorVehicle("Tn879","Dharanie",12345667,100,"15");
18 | Vehicle v5 = new VisitorVehicle("Tn784","Simren",98765432,200,"12");
19 | Vehicle v6 = new VisitorVehicle("Tn908","Nila",45367281,300,"18");
20 | System.out.println(pm.addVehicle(v1));
21 | System.out.println(pm.addVehicle(v2));
22 | System.out.println(pm.addVehicle(v3));
23 | System.out.println(pm.addVehicle(v4));
24 | System.out.println(pm.addVehicle(v5));
25 | System.out.println(pm.addVehicle(v6));
26 | System.out.println(pm.setVisitorVehicleOutTime("Tn879","18"));
27 | System.out.println(pm.setVisitorVehicleOutTime("Tn908","19"));
28 | System.out.println(pm.getParkedResidentVehicleCount());
29 | System.out.println(pm.displayAllVehicles());
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Java - Open_Source - Projects
2 |
3 | 
4 |
5 |
6 |
7 |
8 |
9 |
10 | [](https://www.java.com/en/) [](https://forthebadge.com) [](https://forthebadge.com)
11 |
12 |       
13 |
14 |
15 |
16 |
17 |
18 | ## 🌀 What is this repository for ?
19 |
20 | - This repository contains a list of projects bulid using Java .
21 |
22 | - Anyone can contribute their project to this repository .
23 |
24 |
25 |
26 | ## ☣️ How to contribute for this repo ?
27 |
28 | - Fork this repository .
29 |
30 | - Create a new project and upload it to this repo .
31 |
32 | - Create a pull request ⬆️ .
33 |
34 |
35 |
36 | ### ⚠️ Use the below link to learn about how to make a pull request ⏬.
37 |
38 |
39 |
40 | ### 📌 [Pull request example Video .](https://www.youtube.com/watch?v=_NrSWLQsDL4)
41 |
42 |
43 |
44 |
45 | ## 🌐 Rules
46 |
47 | - Do not spam ❎
48 |
49 | - Every Project must contains separate readme file and that readme will explain the project .
50 |
51 |
52 | - Create one folder(for one project) and put you project and readme in it.
53 |
54 | - push the project like this ⏬
55 |
56 |
57 |
58 | **Example :**
59 |
60 |
61 | 
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/ParkingSystem/Service/ParkingManagement.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Service;
2 |
3 | import ParkingSystem.Exceptions.ParkingSlotNotAvailableException;
4 | import ParkingSystem.Exceptions.VehicleNotFoundException;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 | import java.util.stream.Collectors;
9 |
10 | public class ParkingManagement {
11 | private List allVehicles;
12 | private int slot =10,s=0;
13 | public ParkingManagement() {
14 | allVehicles = new ArrayList();
15 | }
16 | public String addVehicle(Vehicle vehicle) throws ParkingSlotNotAvailableException {
17 | if(vehicle instanceof ResidentVehicle){
18 | allVehicles.add(vehicle);
19 | return "Vehicle parked at parking slot No :R"+(allVehicles.size()-s);
20 | }
21 | else if(slot == 0){
22 | throw new ParkingSlotNotAvailableException();
23 | }
24 | allVehicles.add(vehicle);
25 | slot--;
26 | s++;
27 | return "Vehicle parked at parking slot No :V"+allVehicles.size();
28 | }
29 | public String setVisitorVehicleOutTime(String regNumber, String outTime) throws VehicleNotFoundException {
30 | List ve = allVehicles.stream().filter(i->i instanceof VisitorVehicle)
31 | .filter(j->j.getRegNumber().equalsIgnoreCase(regNumber)).
32 | collect(Collectors.toList());
33 | if(ve.isEmpty())
34 | throw new VehicleNotFoundException();
35 | ((VisitorVehicle)ve.get(0)).setOutTime(outTime);
36 | slot++;
37 | return "Vehicle with RegNo: "+regNumber+" updated successfully";
38 | }
39 | public int getParkedResidentVehicleCount()
40 | {
41 | return (int) allVehicles.stream().filter(i->i instanceof ResidentVehicle)
42 | .filter(j->((ResidentVehicle) j).isParkingStatus()).count();
43 | }
44 |
45 | public boolean setParkingStatus(String regNumber,boolean flag){
46 | List l= allVehicles.stream()
47 | .filter(i->i.getRegNumber().equalsIgnoreCase(regNumber))
48 | .limit(1).collect(Collectors.toList());
49 | if(l.isEmpty())return false;
50 | ((ResidentVehicle)l.get(0)).setParkingStatus(flag);
51 | return true;
52 | }
53 |
54 | public int getParkedVisitorVehicleCount()
55 | {
56 | return (int) allVehicles.stream().filter(i->i instanceof ResidentVehicle)
57 | .filter(j-> ((ResidentVehicle)j).getRegNumber() != null).count();
58 | }
59 |
60 | public String displayAllVehicles()
61 | {
62 | String s = "Resident Vehicle\n\n";
63 | int j = 1;
64 | for(Vehicle i: allVehicles)
65 | if(i instanceof ResidentVehicle) {
66 | s += j+". ";
67 | s += i;
68 | j++;
69 | }
70 | j = 1;
71 | s += "\n\nVisitor Vehicle\n\n";
72 | for(Vehicle i: allVehicles)
73 | if(i instanceof VisitorVehicle){
74 | s += j+". ";
75 | s += i;
76 | j++;
77 | }
78 |
79 |
80 | return s;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/Document Downloader/URLMainGUI.java:
--------------------------------------------------------------------------------
1 | import javax.swing.*;
2 | import java.awt.*;
3 | import java.awt.event.ActionEvent;
4 | import java.awt.event.ActionListener;
5 | import java.io.BufferedInputStream;
6 | import java.io.BufferedOutputStream;
7 | import java.io.File;
8 | import java.io.FileOutputStream;
9 | import java.net.HttpURLConnection;
10 | import java.net.URL;
11 |
12 | public class URLMainGUI extends JFrame implements ActionListener {
13 |
14 | JTextField tf1,tf2,tf3;
15 | JButton jb1,jb2;
16 | JLabel jl1,jl2;
17 | String folder;
18 | String URL;
19 |
20 | URLMainGUI(){
21 | setLayout(null);
22 | setVisible(true);
23 | setSize(1000,700);
24 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
25 | setResizable(false);
26 | setLocationRelativeTo(null);
27 | getContentPane().setBackground(new Color(125, 248, 84));
28 | setTitle("Document Downloader");
29 | setIconImage(new ImageIcon("C:\\Java- DownLoad\\src\\logo.jpg").getImage());//Absolute path
30 | folder = "C:\\";
31 | URL = " ";
32 |
33 |
34 | jl1 = new JLabel("URL");
35 | jl2 = new JLabel("File Name");
36 | jb1 = new JButton("Download");
37 | jb2 = new JButton("Folder");
38 | tf1 = new JTextField();
39 | tf2 = new JTextField();
40 | tf3 = new JTextField();
41 |
42 | jl1.setFont(new Font("Times New",Font.BOLD,25));
43 | jl2.setFont(new Font("Times New",Font.BOLD,25));
44 |
45 | jl1.setBounds(163,80,100,100);
46 | jl2.setBounds(100,150,150,100);
47 |
48 | tf1.setBounds(250,110,300,40);
49 | tf2.setBounds(250,180,300,40);jb2.setBounds(550,180,100,40);
50 |
51 | jb1.setBounds(450,240,200,40);
52 | tf3.setBounds(0,630,1000,50);
53 |
54 | tf3.setHorizontalAlignment(JTextField.CENTER);
55 |
56 | tf1.setFont(new Font("Times New",Font.BOLD,18));
57 | tf2.setFont(new Font("Times New",Font.BOLD,18));
58 | tf3.setFont(new Font("Times New",Font.BOLD,18));
59 | jb1.setFont(new Font("Times New",Font.BOLD,18));
60 |
61 | jb1.setBackground(new Color(31, 210, 159));
62 | jb2.setBackground(new Color(31, 210, 159));
63 | add(jl1);add(jl2);add(jb1);
64 | add(jb2);add(tf1);add(tf2);add(tf3);
65 |
66 | jb1.setFocusable(false);
67 | jb2.setFocusable(false);
68 | tf3.setEditable(false);
69 |
70 | jb1.addActionListener(this);
71 | jb2.addActionListener(this);
72 | }
73 |
74 |
75 |
76 | @Override
77 | public void actionPerformed(ActionEvent e) {
78 | tf3.setText("");
79 | if(e.getSource() == jb2){
80 | JFileChooser fileChooser = new JFileChooser();
81 | fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
82 | int option = fileChooser.showOpenDialog(this);
83 | if(option == JFileChooser.APPROVE_OPTION){
84 | File file = fileChooser.getSelectedFile();
85 | folder = file.getAbsolutePath();
86 | }else{
87 | JOptionPane.showMessageDialog(this,"Select folder correctly");
88 | }
89 | }
90 | else if(e.getSource() == jb1){
91 |
92 | String file = tf2.getText().trim();
93 | if(!file.isEmpty())
94 | folder += "\\"+ file;
95 | else{
96 | JOptionPane.showMessageDialog(this,"Enter valid file name");
97 | }
98 |
99 | if(!tf1.getText().trim().isEmpty()){
100 | URL = tf1.getText().trim();
101 | run();
102 | }
103 | else{
104 | JOptionPane.showMessageDialog(this,"Enter valid URL");
105 | }
106 |
107 | }
108 | }
109 |
110 |
111 |
112 | public void run() {
113 | try{
114 | URL url = new URL(URL); // Object for URL
115 | HttpURLConnection http = (HttpURLConnection)url.openConnection(); //Enable connection
116 | File out = new File(folder);
117 | double fileSize = http.getContentLength();
118 | BufferedInputStream input = new BufferedInputStream(http.getInputStream()); // For Read Input from URL
119 | FileOutputStream fout = new FileOutputStream(out);
120 | BufferedOutputStream output = new BufferedOutputStream(fout,1024);// For Write output to Local(In system)
121 |
122 | byte[] buffer = new byte[1024];
123 | double downloaded =0.00;
124 | int read = 0;
125 | double percentDownloaded = 0.00;
126 | while((read = input.read(buffer,0,1024))>=0){
127 | output.write(buffer,0,read);
128 | downloaded += read;
129 | percentDownloaded = (downloaded*100)/fileSize;
130 | String percent = String.format("%.4f",percentDownloaded);
131 | tf3.setText("DownLoad "+percent+"% of a file");
132 | }
133 | tf3.setText("DownLoad Successfully");
134 |
135 | input.close();
136 | output.close();
137 | }catch (Exception e){
138 | e.printStackTrace();
139 | }
140 | }
141 |
142 | public static void main(String[] args) {
143 | new URLMainGUI();
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/Tic-Tac-Toe/Game.java:
--------------------------------------------------------------------------------
1 | import javax.swing.*;
2 | import java.awt.*;
3 | import java.awt.event.ActionEvent;
4 | import java.awt.event.ActionListener;
5 |
6 | class Game extends JFrame implements ActionListener {
7 | ImageIcon icon ;
8 | JTextField tf1;
9 | JButton [][]jb;
10 | JButton rs,ng;
11 | JTextField tfx,tfy,xs,ys,vs;
12 | String [][]a;
13 | int x;
14 |
15 | final String [] tf1v = {"X-Turn","O-Turn"};
16 | Game()
17 | {
18 | x = 0;
19 | a = new String[3][3];
20 |
21 | tf1 = new JTextField(tf1v[0]);
22 | tf1.setForeground(Color.RED);
23 | tfx = new JTextField("Player X");
24 | tfy = new JTextField("Player O");
25 | xs = new JTextField("0");
26 | ys = new JTextField("0");
27 | vs = new JTextField("VS");
28 | icon = new ImageIcon(JFrame.class.getResource("/logo.jpg"));
29 |
30 | jb = new JButton[3][3];
31 | rs = new JButton("Restart");
32 | ng = new JButton("New Game");
33 |
34 | setLayout(null);
35 | getContentPane().setBackground(new Color(0x123456));
36 | for(int i=0;i<3;i++)
37 | for(int j=0;j<3;j++){
38 | jb[i][j] = new JButton(); // Create button object
39 | jb[i][j].setOpaque(true);
40 | jb[i][j].setBackground(new Color(255,255,255));
41 | add(jb[i][j]);
42 | jb[i][j].setBounds(50+(j*100),80+(i*100),100,100);
43 | jb[i][j].setFont(new Font("TORCH",Font.BOLD,75));
44 | a[i][j] = "";
45 | }
46 |
47 |
48 | setVisible(true);
49 | setSize(500,500);
50 |
51 |
52 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
53 |
54 | setTitle("Tic-Tac-Toe");
55 | setResizable(false);
56 | setIconImage(icon.getImage());
57 |
58 |
59 | tf1.setFont(new Font("DenMark",Font.BOLD,20));
60 | tfx.setFont(new Font("Times new roman", Font.PLAIN,25));
61 | tfy.setFont(new Font("Times new roman", Font.PLAIN,25));
62 | xs.setFont(new Font("Times new roman", Font.PLAIN,25));
63 | ys.setFont(new Font("Times new roman", Font.PLAIN,25));
64 | vs.setFont(new Font("Times new roman", Font.BOLD,25));
65 |
66 | rs.setEnabled(false);
67 | ng.setEnabled(false);
68 |
69 |
70 |
71 | add(tf1);add(tfx);add(tfy);
72 | add(xs);add(ys);add(vs);
73 | add(rs);add(ng);
74 |
75 | tf1.setHorizontalAlignment(JTextField.CENTER);
76 | tfx.setBackground(new Color(0x4e42f5));
77 | tfy.setBackground(new Color(0x4e42f5));
78 |
79 | tf1.setBounds(0,0,500,30);
80 | rs.setBounds(380,100,100,50);
81 | ng.setBounds(380,170,100,50);
82 | tfx.setBounds(40,420,100,30);
83 | xs.setBounds(140,420,30,30);
84 | vs.setBounds(180,420,40,30);
85 | ys.setBounds(230,420,30,30);
86 | tfy.setBounds(260,420,100,30);
87 |
88 | tf1.setEditable(false);
89 | tfx.setEditable(false);
90 | tfy.setEditable(false);
91 | xs.setEditable(false);
92 | ys.setEditable(false);
93 |
94 | for(int i=0;i<3;i++)
95 | for(int j=0;j<3;j++)
96 | jb[i][j].addActionListener(this);
97 |
98 | rs.addActionListener(this);
99 | ng.addActionListener(this);
100 |
101 | jb[0][0].setIcon(icon);
102 | }
103 |
104 | @Override
105 | public void actionPerformed(ActionEvent e) {
106 |
107 | if(e.getSource() == rs){
108 | restart();
109 | }
110 | else if(e.getSource() == ng){
111 | newGame();
112 | }
113 | else{
114 | for(int i=0;i<3;i++)
115 | for(int j=0;j<3;j++)
116 | if(e.getSource() == jb[i][j]){
117 | if(a[i][j].equals("")){
118 | if(x%2 == 0){
119 | jb[i][j].setText("X");
120 | jb[i][j].setForeground(Color.RED);
121 | a[i][j] = "X";
122 | tf1.setText(tf1v[1]);
123 | tf1.setForeground(Color.BLUE);
124 | }
125 | else{
126 | jb[i][j].setText("O");
127 | jb[i][j].setForeground(Color.BLUE);
128 | a[i][j] = "O";
129 | tf1.setText(tf1v[0]);
130 | tf1.setForeground(Color.RED);
131 | }
132 | String result = decision_maker();
133 | if(!result.isEmpty()){
134 | if(result.equalsIgnoreCase("X")){
135 | tf1.setText("Player X wins");
136 | tf1.setForeground(Color.RED);
137 | xs.setText(String.valueOf(Integer.valueOf(xs.getText())+1));
138 | }
139 | else if(result.equalsIgnoreCase("O")){
140 | tf1.setText("Player O wins");
141 | tf1.setForeground(Color.BLUE);
142 | ys.setText(String.valueOf(Integer.valueOf(ys.getText())+1));
143 | }
144 | else{
145 | tf1.setText("Tie");
146 | tf1.setForeground(Color.CYAN);
147 | }
148 | freeze();
149 | break;
150 | }
151 | x++;
152 | }
153 | break;
154 | }
155 | }
156 | }
157 | /*After finished the game this function helps to freeze(disable) the box*/
158 | public void freeze(){
159 | for(int i=0;i<3;i++)
160 | for(int j=0;j<3;j++)
161 | jb[i][j].setEnabled(false);
162 | rs.setEnabled(true);
163 | ng.setEnabled(true);
164 | }
165 |
166 | /*This function helps to find the winner of the game*/
167 | public String decision_maker()
168 | {
169 | String ans= "";
170 | for(int i=0;i<3;i++)
171 | if((! a[i][0].isEmpty()) && a[i][0].equals(a[i][1]) && a[i][0].equals(a[i][2]))
172 | return a[i][0];
173 |
174 | for(int j=0;j<3;j++)
175 | if((! a[0][j].isEmpty()) && a[0][j].equals(a[1][j]) && a[0][j].equals(a[2][j]))
176 | return a[0][j];
177 |
178 | if((! a[0][0].isEmpty()) && a[0][0].equals(a[1][1]) && a[0][0].equals(a[2][2]))
179 | return a[0][0];
180 |
181 | if((! a[0][2].isEmpty()) && a[0][2].equals(a[1][1]) && a[0][2].equals(a[2][0]))
182 | return a[0][2];
183 |
184 | int count = 0;
185 | for(int i=0;i<3;i++)
186 | for(int j=0;j<3;j++)
187 | if(! a[i][j].isEmpty())
188 | count++;
189 | if(count == 9)
190 | ans = "Tie";
191 |
192 | return ans;
193 | }
194 |
195 | /*This function clear all the marks from box*/
196 | public void newGame()
197 | {
198 | for(int i=0;i<3;i++)
199 | for(int j=0;j<3;j++)
200 | jb[i][j].setText("");
201 | for(int i=0;i<3;i++)
202 | for(int j=0;j<3;j++)
203 | a[i][j] = "";
204 | x = 0;
205 | for(int i=0;i<3;i++)
206 | for(int j=0;j<3;j++)
207 | jb[i][j].setEnabled(true);
208 | rs.setEnabled(false);
209 | ng.setEnabled(false);
210 | tf1.setText(tf1v[0]);
211 | tf1.setForeground(Color.RED);
212 | }
213 |
214 | /*This function set the points as 0 and start the game from beginning*/
215 | public void restart()
216 | {
217 | xs.setText("0");
218 | ys.setText("0");
219 | newGame();
220 | }
221 |
222 |
223 | public static void main(String[] args) {
224 | new Game();
225 | }
226 |
227 |
228 | }
229 |
--------------------------------------------------------------------------------
/ParkingSystem/Test/ParkingManagementGUI.java:
--------------------------------------------------------------------------------
1 | package ParkingSystem.Test;
2 |
3 | import ParkingSystem.Exceptions.ParkingSlotNotAvailableException;
4 | import ParkingSystem.Exceptions.VehicleNotFoundException;
5 | import ParkingSystem.Service.ParkingManagement;
6 | import ParkingSystem.Service.ResidentVehicle;
7 | import ParkingSystem.Service.VisitorVehicle;
8 |
9 | import javax.swing.*;
10 | import java.awt.*;
11 | import java.awt.event.ActionEvent;
12 | import java.awt.event.ActionListener;
13 |
14 | public class ParkingManagementGUI extends JFrame implements ActionListener {
15 |
16 | boolean flag;
17 | CardLayout card;
18 | JPanel panel;
19 | ImageIcon logo;
20 | ParkingManagement parkingManagement;
21 |
22 | JPanel hp;
23 | JButton b1,b2,b3;
24 | JTextField tf1;
25 |
26 | JPanel rvp;
27 | JButton b4,b5,b6,b7;
28 | JTextField tf2;
29 |
30 | JPanel cio;
31 | JTextField tf9,tf10;
32 | JLabel l6;
33 | JButton b9,b10,b11;
34 |
35 | JPanel ot;
36 | JTextField tf11,tf12,tf13;
37 | JLabel l7,l8;
38 | JButton b12,b13;
39 |
40 | JPanel ap;
41 | JTextField tf3,tf4,tf5,tf6,tf7,tf8;
42 | JLabel l1,l2,l3,l4,l5;
43 | JButton b8,b14;
44 |
45 | JPanel dp;
46 | JTextField tf14;
47 | JTextArea ta1;
48 | JButton b15;
49 | JScrollPane scroll;
50 |
51 |
52 |
53 |
54 | ParkingManagementGUI()
55 | {
56 | panel = new JPanel();
57 | card = new CardLayout();
58 | panel.setLayout(card);
59 | flag = true;
60 | parkingManagement = new ParkingManagement();
61 |
62 |
63 | homePage();
64 | add();
65 | residentOrVisitorPage();
66 | checkIO();
67 | setOutTime();
68 | details();
69 |
70 | setFont();
71 |
72 | panel.add(hp,"1");
73 | panel.add(rvp,"2");
74 | panel.add(cio,"3");
75 | panel.add(ot,"4");
76 | panel.add(ap,"5");
77 | panel.add(dp,"6");
78 |
79 | card.show(panel,"1");
80 |
81 | add(panel);
82 | setVisible(true);
83 | setSize(500,500);
84 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
85 | setResizable(false);
86 | setTitle("Parking System");
87 |
88 | // ImageIcon logo;
89 | logo = new ImageIcon("C:\\Users\\USER\\IdeaProjects\\ParkingManagementSystem" +
90 | "\\src\\main\\java\\ParkingSystem\\Test\\logo.png");
91 | // give absolute path for image
92 | setIconImage(logo.getImage());
93 |
94 | }
95 |
96 | public void homePage(){
97 | hp = new JPanel();
98 | hp.setLayout(null);
99 | hp.setBackground(new Color(30, 74, 186));
100 |
101 | b1 = new JButton("Resident");
102 | b2 = new JButton("Visitor");
103 | b3 = new JButton("Display");
104 |
105 | tf1 = new JTextField("Home Page");
106 |
107 | tf1.setBackground(new Color(8, 245, 141));
108 | tf1.setForeground(new Color(0,0,0));
109 | tf1.setHorizontalAlignment(JTextField.CENTER);
110 | tf1.setEditable(false);
111 |
112 | hp.add(tf1);hp.add(b1);hp.add(b2);
113 | hp.add(b3);
114 |
115 | tf1.setBounds(0,0,500,35);
116 | b1.setBounds(200,100,100,50);
117 | b2.setBounds(200,200,100,50);
118 | b3.setBounds(200,300,100,50);
119 |
120 | b1.setFocusable(false);
121 | b2.setFocusable(false);
122 | b3.setFocusable(false);
123 |
124 | b1.addActionListener(this);
125 | b2.addActionListener(this);
126 | b3.addActionListener(this);
127 | }
128 |
129 | public void residentOrVisitorPage(){
130 | rvp = new JPanel();
131 | rvp.setLayout(null);
132 | rvp.setBackground(new Color(178, 18, 196));
133 |
134 | b4 = new JButton("Add");
135 | b5 = new JButton("Set");
136 | b6 = new JButton("Count");
137 | b7 = new JButton("Home");
138 |
139 | tf2 = new JTextField("Vehicle");
140 |
141 | tf2.setBackground(new Color(174, 245, 8));
142 | tf2.setForeground(new Color(0,0,0));
143 | tf2.setHorizontalAlignment(JTextField.CENTER);
144 | tf2.setEditable(false);
145 |
146 | tf2.setBounds(0,0,500,35);
147 | b4.setBounds(200,70,100,50);
148 | b5.setBounds(200,170,100,50);
149 | b6.setBounds(200,270,100,50);
150 | b7.setBounds(200,370,100,50);
151 |
152 | rvp.add(b4);rvp.add(b5);
153 | rvp.add(b6);rvp.add(b7);
154 | rvp.add(tf2);
155 |
156 | b4.setFocusable(false);
157 | b5.setFocusable(false);
158 | b6.setFocusable(false);
159 | b7.setFocusable(false);
160 |
161 | b4.addActionListener(this);
162 | b5.addActionListener(this);
163 | b6.addActionListener(this);
164 | b7.addActionListener(this);
165 | }
166 |
167 | public void checkIO()
168 | {
169 | cio = new JPanel();
170 | cio.setLayout(null);
171 | cio.setBackground(new Color(158, 39, 39));
172 |
173 |
174 | l6 = new JLabel("Reg No");
175 | l6.setBounds(100,100,100,50);
176 | l6.setFont(new Font("Times new roman", Font.BOLD,25));
177 |
178 | tf10 = new JTextField();
179 | tf10.setBounds(205,113,100,25);
180 |
181 | tf9 = new JTextField("CheckIn/CheckOut");
182 | tf9.setBounds(50,100,100,50);
183 |
184 |
185 | tf9.setBackground(new Color(8, 115, 245));
186 | tf9.setForeground(new Color(21, 20, 20));
187 | tf9.setHorizontalAlignment(JTextField.CENTER);
188 | tf9.setEditable(false);
189 |
190 | tf9.setBounds(0,0,500,35);
191 |
192 | b9 = new JButton("In");
193 | b10 = new JButton("Out");
194 | b11 = new JButton("Home");
195 | b9.setBounds(100,170,100,50);
196 | b10.setBounds(220,170,100,50);
197 | b11.setBounds(340,170,100,50);
198 |
199 | b9.addActionListener(this);
200 | b10.addActionListener(this);
201 | b11.addActionListener(this);
202 |
203 | b9.setFocusable(false);
204 | b10.setFocusable(false);
205 | b11.setFocusable(false);
206 |
207 | b11.setVisible(false);
208 |
209 | cio.add(tf9);cio.add(tf10);
210 | cio.add(l6);cio.add(b9);
211 | cio.add(b10);cio.add(b11);
212 | }
213 |
214 | public void setOutTime()
215 | {
216 | ot = new JPanel();
217 | ot.setLayout(null);
218 | ot.setBackground(new Color(23, 182, 76));
219 |
220 | tf11 = new JTextField("OutTime");
221 | tf11.setBounds(0,0,500,50);
222 |
223 |
224 |
225 | tf11.setBackground(new Color(134, 8, 245));
226 | tf11.setForeground(new Color(21, 20, 20));
227 | tf11.setHorizontalAlignment(JTextField.CENTER);
228 | tf11.setEditable(false);
229 |
230 | l7 = new JLabel("Reg No");
231 | l7.setBounds(100,100,100,50);
232 | l7.setFont(new Font("Times new roman", Font.BOLD,25));
233 |
234 | tf12 = new JTextField();
235 | tf12.setBounds(205,113,100,25);
236 |
237 | tf13 = new JTextField();
238 | tf13.setBounds(205,163,100,25);
239 |
240 | b12 = new JButton("Set");
241 | b13 = new JButton("Home");
242 |
243 |
244 | l8 = new JLabel("OutTime");
245 | l8.setBounds(100,150,100,50);
246 | l8.setFont(new Font("Times new roman", Font.BOLD,25));
247 |
248 |
249 | b12.setBounds(100,220,100,50);
250 | b13.setBounds(220,220,100,50);
251 |
252 |
253 |
254 | b12.addActionListener(this);
255 | b13.addActionListener(this);
256 |
257 | b12.setFocusable(false);
258 | b13.setFocusable(false);
259 |
260 | ot.add(tf11);ot.add(tf12);
261 | ot.add(b12);ot.add(b13);
262 | ot.add(l7);ot.add(l8);
263 | ot.add(tf13);
264 |
265 | }
266 |
267 |
268 | public void add()
269 | {
270 | ap = new JPanel();
271 | ap.setLayout(null);
272 | ap.setBackground(new Color(21, 236, 161));
273 |
274 | tf3 = new JTextField("Add");
275 |
276 | tf3.setBounds(0,0,500,50);
277 |
278 | tf3.setBackground(new Color(245, 8, 241));
279 | tf3.setForeground(new Color(21, 20, 20));
280 | tf3.setHorizontalAlignment(JTextField.CENTER);
281 | tf3.setEditable(false);
282 |
283 | l1 = new JLabel("Reg No");
284 | l1.setBounds(80,100,100,50);
285 | l1.setFont(new Font("Times new roman", Font.BOLD,25));
286 |
287 | l2 = new JLabel("Name");
288 | l2.setBounds(80,150,100,50);
289 | l2.setFont(new Font("Times new roman", Font.BOLD,25));
290 |
291 | l3 = new JLabel("Phone No");
292 | l3.setBounds(80,200,120,50);
293 | l3.setFont(new Font("Times new roman", Font.BOLD,25));
294 |
295 |
296 | l4 = new JLabel("Flat No");
297 | l4.setBounds(80,250,100,50);
298 | l4.setFont(new Font("Times new roman", Font.BOLD,25));
299 |
300 | l5 = new JLabel("InTime");
301 | l5.setBounds(80,300,100,50);
302 | l5.setFont(new Font("Times new roman", Font.BOLD,25));
303 |
304 | tf4 = new JTextField();
305 | tf4.setBounds(220,115,100,25);
306 |
307 | tf5 = new JTextField();
308 | tf5.setBounds(220,165,100,25);
309 |
310 | tf6 = new JTextField();
311 | tf6.setBounds(220,215,100,25);
312 |
313 | tf7 = new JTextField();
314 | tf7.setBounds(220,265,100,25);
315 |
316 | tf8 = new JTextField();
317 | tf8.setBounds(220,315,100,25);
318 |
319 | b8 = new JButton("Submit");
320 | b14 = new JButton("Home");
321 |
322 | b14.setBounds(100,365,100,50);
323 | b8.setBounds(220,365,100,50);
324 |
325 | b8.addActionListener(this);
326 | b14.addActionListener(this);
327 |
328 | b8.setFocusable(false);
329 |
330 | ap.add(tf3);ap.add(l1);ap.add(l2);
331 | ap.add(l3);ap.add(l4);ap.add(l5);
332 | ap.add(tf4);ap.add(tf5);ap.add(tf6);ap.add(tf7);
333 | ap.add(tf8);ap.add(b8);ap.add(b14);
334 | }
335 |
336 | public void details()
337 | {
338 | dp = new JPanel();
339 | dp.setLayout(null);
340 |
341 | tf14 = new JTextField("Vehicle Details");
342 |
343 | tf14.setBounds(0,0,500,50);
344 |
345 | tf14.setBackground(new Color(8, 40, 245));
346 | tf14.setForeground(new Color(21, 20, 20));
347 | tf14.setHorizontalAlignment(JTextField.CENTER);
348 | tf14.setEditable(false);
349 |
350 |
351 |
352 | ta1 = new JTextArea("Hai");
353 |
354 | ta1.setEditable(false);
355 | scroll = new JScrollPane(ta1,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
356 | ,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
357 | scroll.setBounds(0,50,490,300);
358 | scroll.setVisible(true);
359 | b15 = new JButton("Home");
360 | b15.setBounds(360,360,100,50);
361 |
362 | b15.setFocusable(false);
363 |
364 | dp.add(b15);dp.add(scroll);dp.add(tf14);
365 | dp.add(scroll);
366 | b15.addActionListener(this);
367 |
368 |
369 | }
370 |
371 | public void setFont(){
372 | Font f1 = new Font("Courier",Font.BOLD,25);
373 | tf1.setFont(f1);tf2.setFont(f1);tf3.setFont(f1);
374 | tf11.setFont(f1);tf14.setFont(f1);tf9.setFont(f1);
375 |
376 | Font f2 = new Font("Times",Font.BOLD,15);
377 | b1.setFont(f2);b2.setFont(f2);b3.setFont(f2);
378 | b4.setFont(f2);b5.setFont(f2);b6.setFont(f2);
379 | b7.setFont(f2);b8.setFont(f2);b9.setFont(f2);
380 | b10.setFont(f2);b11.setFont(f2);b12.setFont(f2);
381 | b13.setFont(f2);b14.setFont(f2);b15.setFont(f2);
382 |
383 |
384 | ta1.setFont(f2);
385 |
386 | }
387 |
388 | @Override
389 | public void actionPerformed(ActionEvent e) {
390 |
391 | if(e.getSource() == b1){
392 | flag = true;
393 | tf2.setText("Resident Vehicle");
394 | rvp.setBackground(new Color(178, 18, 196));
395 | card.show(panel,"2");
396 | }
397 | else if(e.getSource() == b2){
398 | flag = false;
399 | tf2.setText("Visitor Vehicle");
400 | rvp.setBackground(new Color(23, 92, 76));
401 | card.show(panel,"2");
402 | }
403 | else if(e.getSource() == b7 || e.getSource() == b11 ||
404 | e.getSource() == b13 || e.getSource() == b14 || e.getSource() == b15){
405 | card.show(panel,"1");
406 | }
407 | else if(e.getSource() == b5){
408 | if(flag) {
409 | b11.setVisible(false);
410 | tf10.setText("");
411 | card.show(panel, "3");
412 | }
413 | else{
414 |
415 | tf12.setText("");
416 | card.show(panel, "4");
417 | }
418 | }
419 | else if(e.getSource() == b9){
420 | boolean status = parkingManagement.setParkingStatus(tf10.getText().trim(),true);
421 | if(status)
422 | JOptionPane.showMessageDialog(this
423 | ,"status set successfully");
424 | else
425 | JOptionPane.showMessageDialog(this
426 | ,"Wrong register number"
427 | ,"Wrong",JOptionPane.WARNING_MESSAGE);
428 | b11.setVisible(true);
429 | }
430 | else if(e.getSource() == b10){
431 | boolean status = parkingManagement.setParkingStatus(tf10.getText().trim(),false);
432 | if(status)
433 | JOptionPane.showMessageDialog(this
434 | ,"status set successfully");
435 | else
436 | JOptionPane.showMessageDialog(this
437 | ,"Wrong register number"
438 | ,"Wrong",JOptionPane.WARNING_MESSAGE);
439 | b11.setVisible(true);
440 | }
441 | else if(e.getSource() == b12){
442 |
443 | try {
444 | parkingManagement.setVisitorVehicleOutTime(tf12.getText().trim()
445 | ,tf13.getText().trim());
446 | JOptionPane.showMessageDialog(this
447 | ,"OutTime set successfully");
448 | } catch (VehicleNotFoundException vehicleNotFoundException) {
449 | JOptionPane.showMessageDialog(this
450 | ,"Wrong register number"
451 | ,"Wrong",JOptionPane.WARNING_MESSAGE);
452 | }
453 | }
454 | else if(e.getSource() == b4){
455 | tf4.setText("");
456 | tf5.setText("");
457 | tf6.setText("");
458 | tf7.setText("");
459 | tf8.setText("");
460 | if(flag){
461 | l5.setVisible(false);
462 | tf8.setVisible(false);
463 | }
464 | else{
465 | l5.setVisible(true);
466 | tf8.setVisible(true);
467 | }
468 | card.show(panel,"5");
469 | }
470 | else if(e.getSource() == b3){
471 | ta1.setText("");
472 | String s = parkingManagement.displayAllVehicles();
473 |
474 | ta1.setText(s);
475 | card.show(panel,"6");
476 | }
477 | else if(e.getSource() == b6){
478 | if(flag){
479 | int count = parkingManagement.getParkedResidentVehicleCount();
480 | JOptionPane.showMessageDialog(this
481 | ,"No of Resident Vehicle count : "+count);
482 | }
483 | else{
484 | int count = parkingManagement.getParkedVisitorVehicleCount();
485 | JOptionPane.showMessageDialog(this
486 | ,"No of Visitor Vehicle count : "+count);
487 | }
488 | }
489 | else if(e.getSource() == b8){
490 | if(flag){
491 | try {
492 | String s = parkingManagement.addVehicle(new ResidentVehicle(tf4.getText(),
493 | tf5.getText(),Long.valueOf(tf6.getText()),
494 | Integer.parseInt(tf7.getText()),true));
495 | JOptionPane.showMessageDialog(this,s);
496 | } catch (ParkingSlotNotAvailableException parkingSlotNotAvailableException) {
497 |
498 | }
499 | }
500 | else{
501 | try {
502 | String s = parkingManagement.addVehicle(new VisitorVehicle(tf4.getText(),
503 | tf5.getText(),Long.valueOf(tf6.getText()),
504 | Integer.parseInt(tf7.getText()),tf8.getText()));
505 | JOptionPane.showMessageDialog(this,s);
506 | } catch (ParkingSlotNotAvailableException parkingSlotNotAvailableException) {
507 | JOptionPane.showMessageDialog(this
508 | ,parkingSlotNotAvailableException.getMessage());
509 | }
510 | }
511 | card.show(panel,"1");
512 | }
513 | }
514 |
515 | public static void main(String[] args){
516 | new ParkingManagementGUI();
517 | }
518 | }
--------------------------------------------------------------------------------