- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateBookPanel.java
More file actions
Latest commit
119 lines (103 loc) · 3.05 KB
/
Copy pathCreateBookPanel.java
File metadata and controls
119 lines (103 loc) · 3.05 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
packagecom.cruds.swingproj;
importjava.awt.CardLayout;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JButton;
importjavax.swing.JLabel;
importjavax.swing.JOptionPane;
importjavax.swing.JPanel;
importjavax.swing.JTextField;
importcom.cruds.exception.SMSException;
publicclassCreateBookPanelextendsJPanel
{
JTextFieldtxtISBN;
JLabellblISBN;
JTextFieldtxttitle;
JLabellbltitle;
JTextFieldtxtcategory;
JLabellblcategory;
JTextFieldtxtno_of_books;
JLabellblno_of_books;
JTextFieldtxtname;
JLabellblname;
JTextFieldtxtemail;
JLabellblemail;
JButtonbtncreate;
JButtonbtnhome;
CreateBookPanel()
{
lblISBN = newJLabel("Book ISBN");
txtISBN = newJTextField(5);
lbltitle = newJLabel("Book Title");
txttitle = newJTextField(15);
lblcategory = newJLabel("Book Category");
txtcategory = newJTextField(7);
lblno_of_books = newJLabel("No of Books");
txtno_of_books = newJTextField(5);
lblname = newJLabel("Author Name");
txtname = newJTextField(7);
lblemail = newJLabel("Author Email Id");
txtemail = newJTextField(15);
btncreate = newJButton("Create");
btncreate.addActionListener(newActionListener() {
@Override
publicvoidactionPerformed(ActionEvente)
{
StringstrISBN = txtISBN.getText();
Stringstrtitle = txttitle.getText();
Stringstrcategory = txtcategory.getText();
Stringstrno_of_books = txtno_of_books.getText();
Stringstrname = txtname.getText();
Stringstremail = txtemail.getText();
try
{
Authora = newAuthor(strname, stremail);
Bookb = newBook(Integer.parseInt(strISBN), strtitle, strcategory, Integer.parseInt(strno_of_books), a);
BookDAOdao = newBookDAO();
if(dao.create(b))
{
txtISBN.setText("");
txttitle.setText("");
txtcategory.setText("");
txtno_of_books.setText("");
txtname.setText("");
txtemail.setText("");
JOptionPane.showMessageDialog(getParent(), "Book Created Successfully", "Success", JOptionPane.INFORMATION_MESSAGE);
}
}
catch(NumberFormatExceptionnfe)
{
getToolkit().beep();
JOptionPane.showMessageDialog(getParent(), "Invalid Book ISBN","Error", JOptionPane.ERROR_MESSAGE);
}
catch(SMSExceptionsmse)
{
getToolkit().beep();
JOptionPane.showMessageDialog(getParent(), smse.getInfo(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
});
btnhome = newJButton("Home");
btnhome.addActionListener(newActionListener() {
@Override
publicvoidactionPerformed(ActionEvente) {
CardLayoutcard = (CardLayout) getParent().getLayout();
card.show(getParent(),"HOMEPANEL");
}
});
add(lblISBN);
add(txtISBN);
add(lbltitle);
add(txttitle);
add(lblcategory);
add(txtcategory);
add(lblno_of_books);
add(txtno_of_books);
add(lblname);
add(txtname);
add(lblemail);
add(txtemail);
add(btncreate);
add(btnhome);
}
}