-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetName.java
More file actions
97 lines (92 loc) · 2.26 KB
/
getName.java
File metadata and controls
97 lines (92 loc) · 2.26 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
package flappyBirdGame;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.sql.*;
public class getName implements ActionListener {
JFrame x;
JLabel l;
JButton b;
JTextField t;
String str="";
int score;
getName()
{
x=new JFrame("Enter Name");
x.setLayout(null);
x.setSize(300,200);
x.getContentPane().setBackground(new Color(0x5E372E));
x.setResizable(false);
l=new JLabel();
b=new JButton("Enter");
t=new JTextField();
l.setBounds(50,50,100,50);
l.setText("Enter Name");
l.setForeground(new Color(0xFFFFFF));
l.setFont(new Font("AngryBirds",1,13));
b.setBounds(100, 120, 80, 20);
b.setFont(new Font("AngryBirds",1,10));
b.setBackground(new Color(0x739957));
b.setForeground(new Color(0xFFFFFF));
b.setOpaque(true);
b.setBorderPainted(false);
b.addActionListener(this);
t.setBackground(new Color(0xFFE3A0));
t.setForeground(new Color(0x000000));
t.setFont(new Font("AngryBirds",1,13));
t.setBounds(120,60,100,30);
x.add(b);
x.add(l);
x.add(t);
x.setVisible(true);
}
void setVal(int score)
{
this.score=score;
}
void updateTable(String s)
{
@SuppressWarnings("unused")
String cur;
@SuppressWarnings("unused")
int id;
Connection con=null;
try {
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/newdb","root","12345678");
@SuppressWarnings("unused")
Statement stmt = con.createStatement();
PreparedStatement str = con.prepareStatement("insert into highscore(name,score) values(?,?)");
str.setInt(2,score);
str.setString(1, s);
System.out.println("entered");
@SuppressWarnings("unused")
int i =str.executeUpdate();
str=con.prepareStatement("delete from highscore where name= ? and score= ? ");
str.setString(1,"Guest");
str.setInt(2, score);
i=str.executeUpdate();
}
catch(Exception e)
{
System.out.println(e);
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==b)
{
str=t.getText();
t.setText("");
updateTable(str);
x.dispose();
@SuppressWarnings("unused")
menu m=new menu();
}
}
}