-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomComplaints.java
146 lines (126 loc) · 4.48 KB
/
CustomComplaints.java
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
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import java.awt.Color;
public class CustomComplaints extends JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
static String info1[]=new String[100];
private final JPanel contentPanel = new JPanel();
static CustomComplaints dialog ;
public static void main(String info[]) {
try {
for(int i=0;i<info.length;i++){
info1[i]=info[i];
}
try {
// Set System L&F
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) {
// handle exception
}
dialog = new CustomComplaints();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
private JTextField textField;
/**
* Create the dialog.
*/
public CustomComplaints() {
setModalityType(JDialog.DEFAULT_MODALITY_TYPE);
setAutoRequestFocus(false);
Image Imgh=new ImageIcon(this.getClass().getResource("/LOGO.png")).getImage();
setIconImage(Imgh);
setBounds(100, 100, 498, 194);
setLocation(GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().x-498/2,GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint().y-439/2);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
textField = new JTextField();
textField.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, null, null, null));
textField.setBounds(118, 44, 350, 27);
contentPanel.add(textField);
textField.setColumns(10);
JLabel lblPrescription = new JLabel("Complaint :");
lblPrescription.setFont(new Font("Tahoma", Font.BOLD, 15));
lblPrescription.setBounds(12, 47, 101, 19);
contentPanel.add(lblPrescription);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton btnAddToList = new JButton("Add to list ");
btnAddToList.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
Connection connection=sqliteconnection.dbconnector();
try{
final String cm=textField.getText();
if(cm==null||cm==""||cm==" "){
JOptionPane.showMessageDialog(null, "please enter valid values");
}
else
{
String query="insert into complaint (comlaint) values(?)";
PreparedStatement pst=connection.prepareStatement(query);
pst.setString(1, textField.getText() );
pst.execute();
pst.close();
}
JOptionPane.showMessageDialog(null, "Desired Complaint added to List, You can now select it from list !");
textField.setText("");
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
finally {
try {connection.close();} catch (SQLException e) {e.printStackTrace();}
}
}
});
btnAddToList.setFont(new Font("Tahoma", Font.BOLD, 14));
buttonPane.add(btnAddToList);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.dispose();
}
});
cancelButton.setFont(new Font("Tahoma", Font.BOLD, 14));
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
}
}