-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCategoryCreateView.java
More file actions
179 lines (155 loc) · 5.64 KB
/
Copy pathCategoryCreateView.java
File metadata and controls
179 lines (155 loc) · 5.64 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
178
179
package view;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import javax.swing.JTextField;
import daoLibrary.CategoryDAO;
import modelsLibrary.Category;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.text.AbstractDocument;
import Utils.CharacterLimitFilter;
public class CategoryCreateView extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private Point fixar;
private JTextField jtxtNome;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CategoryCreateView frame = new CategoryCreateView();
frame.setVisible(true);
//Captura a posição central depois de visível
frame.fixar = frame.getLocation();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public CategoryCreateView() {
setType(Type.UTILITY);
//removendo as bordas do Jframe
setUndecorated(true);
getRootPane().setBorder(BorderFactory.createMatteBorder(3, 3, 3, 3, Color.DARK_GRAY));
setSize(new Dimension(1300, 700));
setResizable(false);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setBounds(100, 100, 480, 335);
contentPane = new JPanel();
contentPane.setBorder(null);
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel jlabelTitulo = new JLabel("Cadastro de Categorias dos Produtos");
jlabelTitulo.setHorizontalAlignment(SwingConstants.CENTER);
jlabelTitulo.setFont(new Font("Arial Black", Font.BOLD, 30));
jlabelTitulo.setBounds(367, 143, 666, 43);
jlabelTitulo.setBackground(new Color(240, 240, 240));
contentPane.add(jlabelTitulo);
JButton jbtnfechar = new JButton("Voltar");
jbtnfechar.setBackground(new Color(192, 192, 192));
jbtnfechar.setFocusPainted(false);
jbtnfechar.setBorder(null);
jbtnfechar.setBounds(1228, 666, 62, 23);
contentPane.add(jbtnfechar);
jbtnfechar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainView tprincipal = new MainView();
tprincipal.setVisible(true);
dispose();
}
});
jtxtNome = new JTextField();
jtxtNome.setFont(new Font("Arial", Font.PLAIN, 17));
jtxtNome.setBounds(444, 291, 246, 30);
jtxtNome.setBorder(null);
contentPane.add(jtxtNome);
jtxtNome.setColumns(10);
JTextArea jtextArea = new JTextArea();
jtextArea.setFont(new Font("Arial", Font.PLAIN, 17));
jtextArea.setBounds(367, 384, 323, 134);
jtextArea.setLineWrap(true);
jtextArea.setWrapStyleWord(true);
//Limitando o TextArea para 200 caracters
((AbstractDocument) jtextArea.getDocument()).setDocumentFilter(new CharacterLimitFilter(200));
contentPane.add(jtextArea);
JLabel jlabelNome = new JLabel("Nome:");
jlabelNome.setFont(new Font("Arial", Font.BOLD, 18));
jlabelNome.setBounds(367, 296, 67, 19);
contentPane.add(jlabelNome);
JLabel jlabelDescricao = new JLabel("Descrição:");
jlabelDescricao.setFont(new Font("Arial", Font.BOLD, 18));
jlabelDescricao.setBounds(367, 359, 103, 19);
contentPane.add(jlabelDescricao);
JButton jbtnTelaListarCategoria = new JButton("Listar Catgoiras");
jbtnTelaListarCategoria.setFont(new Font("Arial Black", Font.PLAIN, 25));
jbtnTelaListarCategoria.setBackground(new Color(192, 192, 192));
jbtnTelaListarCategoria.setFocusPainted(false);
jbtnTelaListarCategoria.setBorder(null);
jbtnTelaListarCategoria.setBounds(737, 552, 323, 80);
contentPane.add(jbtnTelaListarCategoria);
jbtnTelaListarCategoria.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CategoryListView tlcategoria = new CategoryListView();
tlcategoria.setVisible(true);
dispose();
}
});
JButton jbtnCadastrarCategoria = new JButton("Cadastrar");
jbtnCadastrarCategoria.setFont(new Font("Arial Black", Font.PLAIN, 25));
jbtnCadastrarCategoria.setBackground(new Color(192, 192, 192));
jbtnCadastrarCategoria.setBounds(367, 552, 323, 80);
jbtnCadastrarCategoria.setFocusPainted(false);
jbtnCadastrarCategoria.setBorder(null);
contentPane.add(jbtnCadastrarCategoria);
jbtnCadastrarCategoria.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Category categoria = new Category();
CategoryDAO ddcategoria = new CategoryDAO();
categoria.setNome(jtxtNome.getText());
categoria.setDescricao(jtextArea.getText());
if (jtxtNome.getText().equals(null) || jtxtNome.getText().equals("")) {
JOptionPane.showMessageDialog(null, "O nome está vazio!");
}else if(jtextArea.getText().equals(null) || jtextArea.getText().equals("")) {
JOptionPane.showMessageDialog(null, "A Descrição está vazia!");
}else {
categoria.setNome(jtxtNome.getText());
categoria.setDescricao(jtextArea.getText());
ddcategoria.insertCategoria(categoria);
JOptionPane.showMessageDialog(null, "Categoria cadastrada com sucesso!");
jtxtNome.setText("");
jtextArea.setText("");
}
}
});
//Impede do o usuário mover a janela após abrir
addComponentListener(new ComponentAdapter() {
@Override
public void componentMoved(ComponentEvent e) {
if (fixar != null) {
setLocation(fixar);
}
}
});
}
}