-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd_Book.java
More file actions
118 lines (96 loc) · 3.04 KB
/
Add_Book.java
File metadata and controls
118 lines (96 loc) · 3.04 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
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Add_Book implements ActionListener{
JFrame jf;
JPanel jp;
JLabel labname,labid,labisbn,labqty,labprice;
JButton save,exit;
JTextField txtname,txtid,txtisbn,txtqty,txtprice;
Add_Book()
{
labid=new JLabel("Book ID : ", null, 0);
labname=new JLabel("Book Name : ", null, 0);
labisbn=new JLabel("ISBN Number : ", null, 0);
labqty=new JLabel("Quantity : ", null, 0);
labprice=new JLabel("Price : ", null, 0);
txtname=new JTextField(20);
txtid=new JTextField(10);
txtisbn=new JTextField(10);
txtqty=new JTextField(20);
txtprice=new JTextField(2);
save=new JButton("ADD", null);
exit=new JButton("EXIT", null);
save.addActionListener(this);
exit.addActionListener(this);
jp=new JPanel(new GridBagLayout(), false);
jp.setPreferredSize(new Dimension(400, 300));
jf=new JFrame("ADD NEW BOOK", null);
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(7, 7, 7, 7);
gbc.ipadx = 50;
gbc.ipady = 30;
gbc.gridx = 0;
gbc.gridy = 0;
jp.add(labid, gbc);
gbc.gridx = 1;
jp.add(txtid, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
jp.add(labname, gbc);
gbc.gridx = 1;
jp.add(txtname, gbc);
gbc.gridx = 0;
gbc.gridy = 2;
jp.add(labisbn, gbc);
gbc.gridx = 1;
jp.add(txtisbn, gbc);
gbc.gridx = 0;
gbc.gridy = 3;
jp.add(labqty, gbc);
gbc.gridx = 1;
jp.add(txtqty, gbc);
gbc.gridx = 0;
gbc.gridy = 4;
jp.add(labprice, gbc);
gbc.gridx = 1;
jp.add(txtprice, gbc);
gbc.gridx = 0;
gbc.gridy = 5;
jp.add(exit, gbc);
gbc.gridx = 1;
jp.add(save, gbc);
jf.add(jp);
jf.setSize(900,500);
jf.setVisible(true);;
jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s=="ADD")
{
Main.obj.addBook( Long.parseLong(txtid.getText()), txtname.getText(), Long.parseLong(txtisbn.getText()), Integer.parseInt(txtqty.getText()), Double.parseDouble(txtprice.getText()));
save.setText("ADD MORE");
exit.setText("Book Added!!!");
exit.setEnabled(false);
}
else if(s=="ADD MORE")
{
save.setText("SAVE");
exit.setEnabled(true);
exit.setText("EXIT");
}
else
jf.dispose();
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
new AddSt();
}
});
}
}