-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcancel.java
172 lines (145 loc) · 6.72 KB
/
cancel.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
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package restaurant;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.JOptionPane;
/**
*
* @author Circuit Lab
*/
public class cancel extends javax.swing.JFrame {
/**
* Creates new form cancel
*/
public cancel() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jTextField2 = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel5.setFont(new java.awt.Font("Trebuchet MS", 1, 18)); // NOI18N
jLabel5.setText("Mobile No.");
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 160, -1, -1));
jLabel6.setFont(new java.awt.Font("Trebuchet MS", 1, 18)); // NOI18N
jLabel6.setText("Total");
getContentPane().add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(280, 240, -1, -1));
jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 36)); // NOI18N
jLabel1.setText("DIL HAI HINDUSTANI RESTAURANT");
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 40, -1, -1));
jTextField1.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 160, 140, -1));
jButton1.setBackground(new java.awt.Color(204, 204, 255));
jButton1.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
jButton1.setForeground(new java.awt.Color(51, 51, 51));
jButton1.setText("CANCEL PAYMENT");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 370, -1, -1));
jTextField2.setFont(new java.awt.Font("Trebuchet MS", 1, 14)); // NOI18N
getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 250, 140, -1));
jLabel2.setIcon(new javax.swing.ImageIcon("C:\\Users\\Circuit Lab\\OneDrive\\Desktop\\Restaurant\\Restaurant\\src\\restaurant\\cancel.jpg")); // NOI18N
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 890, 600));
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
String num,total;
num=jTextField1.getText();
total=jTextField2.getText();
int result = JOptionPane.showConfirmDialog(null,"Sure? You want to exit?", "Swing Tester", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
if(result == JOptionPane.YES_OPTION){
try
{
// create the mysql database connection
String myDriver = "org.gjt.mm.mysql.Driver";
String myUrl = "jdbc:mysql://localhost/restaurant";
Class.forName(myDriver);
try (Connection conn = DriverManager.getConnection(myUrl, "root", "2511")) {
// create the mysql delete statement.
// i'm deleting the row where the id is "3", which corresponds to my
// "Barney Rubble" record.
String query = "delete from trial where num = ? and ftotal=? ";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setString(1, num);
preparedStmt.setString(2, total);
// execute the preparedstatement
preparedStmt.execute();
JOptionPane.showMessageDialog(null,"payment canceled");
this.dispose();
}
}
catch (ClassNotFoundException | SQLException e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
else{
exit e=new exit();
e.setVisible(true);
dispose();
}
// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(cancel.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new cancel().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration//GEN-END:variables
}