-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
114 lines (101 loc) · 3.49 KB
/
GUI.java
File metadata and controls
114 lines (101 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.FlowLayout;
import java.awt.BorderLayout;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
public class GUI extends JFrame implements ActionListener {
JPanel cpanel, npanel;
JTextField nfield,mfield,gfield;
JLabel nlabel, mlabel, glabel;
JButton dbutton, cbutton, qbutton;
ServerSocket server;
Socket socket,socket1,socket2, socket3;
ObjectInputStream input;
ObjectOutputStream output, output1, output2, output3;
JOptionPane opane;
public GUI() {
setTitle("RafScore");
nlabel = new JLabel("Players Name");
nfield = new JTextField(20);
mlabel = new JLabel(" Matches");
mfield = new JTextField(20);
glabel = new JLabel(" Runs");
gfield = new JTextField(20);
cpanel = new JPanel();
cpanel.setLayout(new FlowLayout());
cpanel.add(nlabel);
cpanel.add(nfield);
cpanel.add(mlabel);
cpanel.add(mfield);
cpanel.add(glabel);
cpanel.add(gfield);
add(cpanel, BorderLayout.CENTER);
npanel = new JPanel();
cpanel.setLayout(new FlowLayout());
dbutton = new JButton("Done");
dbutton.addActionListener(this);
cbutton = new JButton("Start Over");
cbutton.addActionListener(this);
qbutton = new JButton("Quit");
qbutton.addActionListener(this);
npanel.add(dbutton);
npanel.add(cbutton);
npanel.add(qbutton);
add(npanel, BorderLayout.SOUTH);
setSize(400,200);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent event) {
if(event.getSource()== dbutton) { // If user clicks the done button
String playerName = nfield.getText();
String Match = mfield.getText();
int mtch = Integer.parseInt(Match);
String goals = gfield.getText();
int gls = Integer.parseInt(goals);
double average = gls / mtch;
String insert = "insert into records(Name, Matches,Runs, Average) values('" + playerName + "' , " + mtch + " , " + gls + " , " + average + " );";
String select = "Select Runs from records where Name = " + "'" + playerName + "'";
System.out.println(select);
try {
socket = new Socket("", 1097);
socket1 = new Socket("", 1098);
socket2 = new Socket("", 1099);
socket3 = new Socket("", 1096);
output = new ObjectOutputStream(socket.getOutputStream());
output1 = new ObjectOutputStream(socket1.getOutputStream());
output2 = new ObjectOutputStream(socket2.getOutputStream());
output3 = new ObjectOutputStream(socket3.getOutputStream());
output.writeObject(insert); // Sends the insert statement to the server
output1.writeObject(select); // Sends the select statement to the server
output2.writeObject(gls); // Sends the runs to the server
output3.writeObject(playerName); // Sends player name to the server
output.flush();
output1.flush();
output2.flush();
output3.flush();
}catch (IOException e) {
e.printStackTrace(System.out);
}
}else if (event.getSource() == cbutton) { // If user clicks on cancel button
mfield.setText(" ");
nfield.setText(" ");
gfield.setText(" ");
}else if (event.getSource() == qbutton) { // If user clicks on quit button
opane.showMessageDialog(null,"Thank you for using my app, Rafsan");
}
}
public static void main(String[] args) {
GUI s = new GUI();
}
}