-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewBook.java
More file actions
177 lines (146 loc) · 5.13 KB
/
NewBook.java
File metadata and controls
177 lines (146 loc) · 5.13 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
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
/*
* 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.Font;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.TitledBorder;
/**
*
* @author user
*/
public class NewBook extends JFrame {
JLabel l1, l2, l3, l4, l5, l6;
JTextField t1, t2, t3, t4, t5, t6;
JButton add, back;
String name, publisher;
int edition, pages;
float price;
JPanel p = new JPanel();
NewBook() {
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(700, 270, 600, 500);
setTitle("New Book");
setLayout(null);
setSize(500, 500);
TitledBorder title;
title = BorderFactory.createTitledBorder(" New Book");
//BorderFactory.createTitledBorder(null, "text", TitledBorder.CENTER, TitledBorder.BOTTOM, new Font("times new roman",Font.PLAIN,12), Color.yellow)
title.setTitleColor(Color.RED);
title.setTitleFont(new Font("times new roman", Font.PLAIN, 20));
// title.setTitleJustification(TitledBorder.LEFT);
p.setBorder(title);
// p.setBackground();
p.setBounds(0, 0, 490, 490);
p.setLayout(null);
p.setBackground(Color.white);
l1 = new JLabel("Book ID");
l1.setBounds(50, 60, 100, 30);
p.add(l1);
l2 = new JLabel("Name");
l2.setBounds(50, 100, 100, 30);
p.add(l2);
l3 = new JLabel("Edition");
l3.setBounds(50, 140, 100, 30);
p.add(l3);
l4 = new JLabel("Publisher");
l4.setBounds(50, 180, 200, 30);
p.add(l4);
l5 = new JLabel("Price");
l5.setBounds(50, 220, 100, 30);
p.add(l5);
l6 = new JLabel("Pages");
l6.setBounds(50, 260, 100, 30);
p.add(l6);
t1 = new JTextField();
t1.setBounds(200, 60, 200, 30);
p.add(t1);
t1.setText(" Automatic Generate");
t1.setEditable(false);
t2 = new JTextField();
t2.setBounds(200, 100, 200, 30);
p.add(t2);
t3 = new JTextField();
t3.setBounds(200, 140, 200, 30);
t3.setText("0");
p.add(t3);
t4 = new JTextField();
t4.setBounds(200, 180, 200, 30);
p.add(t4);
t5 = new JTextField();
t5.setBounds(200, 220, 200, 30);
t5.setText("0");
p.add(t5);
t6 = new JTextField();
t6.setBounds(200, 260, 200, 30);
t6.setText("0");
p.add(t6);
add = new JButton("Add");
add.setBounds(70, 350, 100, 30);
add.setIcon(new ImageIcon(getClass().getResource("/12.png")));
add.setHorizontalAlignment(SwingConstants.LEFT);
p.add(add);
back = new JButton("Back");
back.setBounds(300, 350, 100, 30);
back.setIcon(new ImageIcon(getClass().getResource("/11.png")));
back.setHorizontalAlignment(SwingConstants.LEFT);
back.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(false);
WelcomePage w = new WelcomePage();
}
});
p.add(back);
revalidate();
repaint();
add(p);
add.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
add();
}
});
}
void add() {
JavaConnection db = new JavaConnection();
db.connection();
String nam, pub, s1, s2, s3, s4, s5,edi,pric,pag;
float pri;
int page;
nam = pub =edi=pric=pag= "";
pri = 0;
s1 = t2.getText();
s2 = t3.getText();
s3 = t4.getText();
s4 = t5.getText();
s5 = t6.getText();
//page = editionn = 0;&& pri == price && page == pages && editionn == edition
String insert;
if (nam.equals(s1) || edi.equals(s2) || pub.equals(s3) || pric.equals(s4) || pag.equals(s5)) {
JOptionPane.showMessageDialog(null, "This is an illegal input !");
} else {
name = t2.getText();
edition = Integer.parseInt(t3.getText());
publisher = t4.getText();
price = Float.parseFloat(t5.getText());
pages = Integer.parseInt(t6.getText());
insert = "INSERT INTO Book (name,edition,publisher,price,pages) VALUES('" + name + "','" + edition + "','" + publisher + "'," + price + "," + pages + ")";
JOptionPane.showMessageDialog(null, "Your Book is added !");
t2.setText("");
t3.setText("0");
t4.setText("");
t5.setText("0");
t6.setText("0");
db.executeUpdate(insert);
}
db.connClose();
}
}
class Sigsnupe {
public static void main(String[] args) {
NewBook s = new NewBook();
}
}