forked from kongxin-github/Java_Library_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddCategory.java
More file actions
84 lines (68 loc) · 1.8 KB
/
AddCategory.java
File metadata and controls
84 lines (68 loc) · 1.8 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
package view;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import database.Category;
public class AddCategory extends JFrame{
// 面板
private JPanel jPanel = new JPanel();
// 标签
private JLabel jLabel = new JLabel("类别名:");
// 文本框
private JTextField field = new JTextField(22);
// 字体
private Font font2 = new Font("宋体", Font.BOLD, 22);
private Font font3 = new Font("宋体", Font.BOLD, 18);
// 按钮 修改
private JButton button = new JButton("确 定");
public AddCategory() {
setSize(400, 450);
setTitle("添加图书类别");
// 改变背景图片
Icon i = new ImageIcon("img\\ah.jpg");
JLabel Label = new JLabel(i);
Label.setBounds(0, 0, 400, 100);
jLabel.setFont(font2);
field.setFont(font2);
button.setFont(font3);
jLabel.setBounds(50, 180, 100, 30);
field.setBounds(150, 180, 185, 28);
button.setBounds(47, 270, 288, 35);
//添加事件
addEvent();
jPanel.add(jLabel);
jPanel.add(field);
jPanel.add(button);
jPanel.setLayout(null);
jPanel.setBounds(0, 0, 600, 400);
jPanel.setOpaque(false);
add(jPanel);
add(Label);
// 不可以改变窗体的大小
setResizable(false);
setLocationRelativeTo(null);
setLayout(null);
setVisible(true);
}
private void addEvent() {
// 添加确定按钮事件
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s = field.getText().trim();
if(Category.addcategory(s)) {
JOptionPane.showMessageDialog(null, "操作完成");
}
}
});
}
}