-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitialFrame.java
346 lines (294 loc) · 12.8 KB
/
InitialFrame.java
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.awt.Color;
import java.awt.Image;
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.ResultSet;
/**
*
* @author root
*/
public class InitialFrame extends JFrame {
JLabel l1, l2, l3, l4, l5, l6;
JButton b1, b2, b3;
JTextField t1;
JComboBox j1;
void initialframe() throws IOException {
setTitle("Initial configuration setup");
// setSize(610, 600);
getContentPane().setBackground(new Color(44, 43, 48));
setVisible(true);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(700, 300, 610, 400);
l1 = new JLabel("Create New Dbname : ");
l1.setBounds(60, 10, 200, 30);
l1.setForeground(Color.white);
t1 = new JTextField();
t1.setSize(100, 30);
t1.setBounds(200, 10, 200, 30);
b1 = new JButton("Create DB & Use");
b1.setBounds(420, 10, 170, 30);
//Class cls = this.getClass();
// URL url;
// url = cls.getResource("\\icon\\32.png");
// url = new URL("\\icon\\32.png");
//Image image=null;
// try {
//e ImageIO.read(getClass().getResource("yourFolder/yourIcon.png"))
// Image image = ImageIO.read(this.getClass().getResource("anyFiles\\icon\\icon\\32.png"));
// Image image1 = ImageIO.read(new File("icon/db.jpg"));
// image= ImageIO.read(url);
// b1.setIcon(new ImageIcon(image));
// } catch (Exception e) {
// e.printStackTrace();
//}
// jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/javaapplication2/11.png")));
b1.setIcon(new ImageIcon(getClass().getResource("/32.png")));
b1.setHorizontalAlignment(SwingConstants.LEFT);
JavaConnection db = new JavaConnection();
db.connectionInitial();
j1 = new JComboBox();
j1.setBounds(150, 170, 100, 30);
j1.setVisible(false);
add(j1);
l2 = new JLabel("We find an Existing Database in Your Computer Of Our Software Wana Use?:");
l2.setBounds(10, 100, 500, 30);
l2.setVisible(false);
l2.setForeground(Color.green);
add(l2);
l3 = new JLabel("Select the existing database and Click on Use Button.");
l3.setBounds(10, 140, 500, 30);
l3.setVisible(false);
l3.setForeground(Color.white);
add(l3);
l4 = new JLabel("Existing Database ");
l4.setBounds(10, 170, 500, 30);
l4.setVisible(false);
l4.setForeground(Color.white);
add(l4);
l5 = new JLabel("OR");
l5.setBounds(10, 70, 500, 20);
l5.setForeground(Color.red);
//l5.setOpaque(true);
// l5.setBackground(Color.yellow);
l5.setVisible(false);
add(l5);
l6 = new JLabel(new ImageIcon(getClass().getResource("/db.jpg")));
//url = cls.getResource("anyfiles\\icon\\icon\\db.jpg");
l6.setBounds(0, 260, 100, 100);
l6.setForeground(Color.red);
l6.setVisible(true);
add(l6);
b2 = new JButton("USE");
b2.setBounds(300, 170, 100, 30);
b2.setIcon(new ImageIcon(getClass().getResource("/33.png")));
// url = cls.getResource("anyfiles\\icon\\icon\\33.png");
b2.setHorizontalAlignment(SwingConstants.LEFT);
b2.setVisible(false);
File file = new File(".\\initialdbsetup.txt");
if (file.exists()) {
setVisible(false);
Login L1 = new Login();
L1.LoginFrame();
}
try {
ResultSet check = db.executeQuery(" SHOW TABLES LIKE 'dbname'");
//ResultSet rs2 = db.executeQuery("select username from dbname");;
if (check.next()) {
l2.setVisible(true);
l3.setVisible(true);
l4.setVisible(true);
b2.setVisible(true);
j1.setVisible(true);
l5.setVisible(true);
ResultSet rs = db.executeQuery("select username from dbname");
while (rs.next()) {
j1.addItem(rs.getString("username"));
}
} else {
JOptionPane.showMessageDialog(null, "welcome we Figuered out You haven't used this Software on this computer");
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "please Connect Xamp Start Mysql","Error the Developer Wants You to Start Xamp/Wamp",JOptionPane.ERROR_MESSAGE);
}
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String blank = "";
String isblank = t1.getText();
if (isblank.equals(blank)) {
JOptionPane.showMessageDialog(null, "Fill Db Name to Create");
} else {
call();
}
} catch (Exception ev) {
System.out.println(ev);
}
}
});
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//refresh();
String dbselected = (String) j1.getSelectedItem();
String addd = "update currentdb set id='" + 1 + "',name='" + dbselected + "'";
db.executeUpdate(addd);
try {
file.createNewFile();
setVisible(false);
Login L1 = new Login();
L1.LoginFrame();
} catch (Exception ev) {
System.out.println(ev);
}
}
});
add(b2);
b3 = new JButton("refresh");
b3.setBounds(300, 270, 100, 30);
/* try {
//e ImageIO.read(getClass().getResource("yourFolder/yourIcon.png"))
Image image3 = ImageIO.read(this.getClass().getResource("anyFiles\\icon\\icon\\31.png"));
// Image image1 = ImageIO.read(new File("icon/db.jpg"));
// image= ImageIO.read(url);
b3.setIcon(new ImageIcon(image3));
} catch (Exception e) {
e.printStackTrace();
}
*/
b3.setIcon(new ImageIcon(getClass().getResource("/31.png")));
//url = cls.getResource("anyfiles\\icon\\icon\\31.png");
b3.setHorizontalAlignment(SwingConstants.LEFT);
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
refresh();
} catch (Exception ex) {
}
}
});
add(b3);
add(b1);
add(l1);
add(t1);
revalidate();
repaint();
}
void refresh() throws IOException {
revalidate();
repaint();
setVisible(false);
remove(this);
InitialFrame s = new InitialFrame();
s.initialframe();
}
void call() {
JavaConnection db = new JavaConnection();
db.connectionInitial();
String dbname = t1.getText();
File file = new File(".\\initialdbsetup.txt");
//String dbname = "db4";
String sql = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='" + dbname + "'";
ResultSet rs1 = db.executeQuery(sql);
try {
if (rs1.next()) {
JOptionPane.showMessageDialog(null, rs1.getString(1) + " already exits");
System.out.println(rs1.getString(1) + " already exits");
// b1.setVisible(false);
} else {
JOptionPane.showMessageDialog(null, dbname + " Not exits");
System.out.println(dbname + " Not exits");
// b1.setVisible(true);
// ResultSet rs2 = db.executeQuery("SHOW TABLES LIKE 'dbname'");
int r = db.executeUpdate("CREATE DATABASE " + dbname);
if (r == 0) {
JOptionPane.showMessageDialog(null, dbname + ", database already exists");
// System.out.println("Database exists");
} else {
JOptionPane.showMessageDialog(null, dbname + ", database created");
}
System.out.println("1");
ResultSet rs2 = db.executeQuery(" SELECT * FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'dbname'");
if (rs2.next()) {
System.out.println("2");
System.out.println(rs2.getString(1) + " dbname table exits");
String add = "Insert into dbname values ('" + dbname + "')";
db.executeUpdate(add);
ResultSet rs22 = db.executeQuery(" SELECT * FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'currentdb'");
if (rs22.next()) {
System.out.println("3");
String addd = "update currentdb set id='" + 1 + "',name='" + dbname + "'";
db.executeUpdate(addd);
PrimarySetup s = new PrimarySetup();
// s.grantUser();
s.call();
file.createNewFile();
setVisible(false);
Login L1 = new Login();
L1.LoginFrame();
} else {
System.out.println("4");
String currentdb = "CREATE TABLE currentdb ( id INT not NUll,name VARCHAR(255) not NULL,PRIMARY KEY (id))";
db.executeUpdate(currentdb);
String addd = "Insert into currentdb values ('" + 1 + "','" + dbname + "')";
db.executeUpdate(addd);
PrimarySetup s = new PrimarySetup();
// s.grantUser();
s.call();
file.createNewFile();
setVisible(false);
Login L1 = new Login();
L1.LoginFrame();
}
} else {
System.out.println("5");
String dbTablename = "CREATE TABLE dbname ( username VARCHAR(255) not NULL) ";
db.executeUpdate(dbTablename);
String add = "Insert into dbname values ('" + dbname + "')";
db.executeUpdate(add);
JOptionPane.showMessageDialog(null, " dbname table is created");
ResultSet rs22 = db.executeQuery(" SELECT * FROM information_schema.tables WHERE table_schema = 'test' AND table_name = 'currentdb'");
if (rs22.next()) {
System.out.println("6");
String addd = "update currentdb set id='" + 1 + "',name='" + dbname + "'";
db.executeUpdate(addd);
PrimarySetup s = new PrimarySetup();
// s.grantUser();
s.call();
file.createNewFile();
setVisible(false);
Login L1 = new Login();
L1.LoginFrame();
} else {
System.out.println("7");
String currentdb = "CREATE TABLE currentdb ( id INT not NUll,name VARCHAR(255) not NULL,PRIMARY KEY (id))";
db.executeUpdate(currentdb);
String addd = "Insert into currentdb values ('" + 1 + "','" + dbname + "')";
db.executeUpdate(addd);
PrimarySetup s = new PrimarySetup();
// s.grantUser();
s.call();
file.createNewFile();
setVisible(false);
Login L1 = new Login();
L1.LoginFrame();
}
}
}
} catch (Exception e) {
System.out.println(" something code wrong" + e);
}
}
}
class frrt {
public static void main(String[] args) throws IOException {
InitialFrame s = new InitialFrame();
s.initialframe();
// s.call();
}
}