-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBill.java
299 lines (272 loc) · 15.1 KB
/
Bill.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package basicjava.electricity_billing_system;
import java.util.Date;
import javax.swing.*;
/**
*
* @author Hp
*/
public class Bill extends javax.swing.JFrame {
/**
* Creates new form Bill
*/
public Bill() {
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() {
jPanel2 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
txtusname = new javax.swing.JTextField();
lblcsname = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
btnsbill = new javax.swing.JButton();
btnlout = new javax.swing.JButton();
lblcsid = new javax.swing.JLabel();
txtcsid = new javax.swing.JTextField();
txtusunit = new javax.swing.JTextField();
lblunit = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtbill = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel2.setBackground(new java.awt.Color(0, 102, 102));
jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jLabel1.setFont(new java.awt.Font("Segoe UI", 3, 24)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Electricity Billing System");
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(241, 241, 241)
.addComponent(jLabel1)
.addContainerGap(285, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
.addGap(21, 21, 21))
);
lblcsname.setFont(new java.awt.Font("Segoe UI", 3, 16)); // NOI18N
lblcsname.setForeground(new java.awt.Color(0, 102, 102));
lblcsname.setText("Customer Name:");
jPanel3.setBackground(new java.awt.Color(0, 102, 102));
btnsbill.setFont(new java.awt.Font("Segoe UI", 3, 16)); // NOI18N
btnsbill.setForeground(new java.awt.Color(0, 102, 102));
btnsbill.setText("Show Bill");
btnsbill.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsbillActionPerformed(evt);
}
});
btnlout.setFont(new java.awt.Font("Segoe UI", 3, 16)); // NOI18N
btnlout.setForeground(new java.awt.Color(0, 102, 102));
btnlout.setText("Log Out");
btnlout.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnloutActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnsbill, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(85, 85, 85)
.addComponent(btnlout, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnsbill)
.addComponent(btnlout))
.addContainerGap(17, Short.MAX_VALUE))
);
lblcsid.setFont(new java.awt.Font("Segoe UI", 3, 16)); // NOI18N
lblcsid.setForeground(new java.awt.Color(0, 102, 102));
lblcsid.setText("Customer ID:");
txtcsid.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtcsidActionPerformed(evt);
}
});
lblunit.setFont(new java.awt.Font("Segoe UI", 3, 16)); // NOI18N
lblunit.setForeground(new java.awt.Color(0, 102, 102));
lblunit.setText("Unit :");
txtbill.setColumns(20);
txtbill.setFont(new java.awt.Font("Segoe UI", 3, 14)); // NOI18N
txtbill.setRows(5);
txtbill.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
txtbill.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
jScrollPane1.setViewportView(txtbill);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(lblcsname, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblcsid)
.addComponent(lblunit, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(46, 46, 46)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtcsid, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtusname, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtusunit, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(37, 37, 37))
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(27, 27, 27)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtusname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblcsname))
.addGap(51, 51, 51)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtcsid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblcsid, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblunit)
.addComponent(txtusunit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(61, 61, 61))
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)))
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
setLocationRelativeTo(null);
}// </editor-fold>//GEN-END:initComponents
String cid, cname;
double charge , total;
int count;
public void print(){
String cid = txtcsid.getText();
String cname = txtusname.getText();
String unit = txtusunit.getText();
txtbill.setText(txtbill.getText() + "Electricity Billing System" + "\n");
txtbill.setText(txtbill.getText() + "\n");
txtbill.setText(txtbill.getText() + "Customer Name: " + cname + "\n\n");
txtbill.setText(txtbill.getText() + "Customer ID: " + cid + "\n\n");
txtbill.setText(txtbill.getText() + "Unit: " + unit + "\n\n");
txtbill.setText(txtbill.getText() + "Total bill: " + total + "\n\n");
Date obj = new Date();
String date = obj.toString();
txtbill.setText(txtbill.getText() +"Date: "+date );
}
private void btnsbillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnsbillActionPerformed
// TODO add your handling code here:
if(txtcsid.getText().trim().isEmpty() || txtusname.getText().trim().isEmpty() || txtusunit.getText().trim().isEmpty() ){
JOptionPane.showMessageDialog(Bill.this,"Enter your information correctly:");
txtusname.grabFocus();
txtcsid.grabFocus();
txtusunit.grabFocus();
return;
}
cid = txtcsid.getText();
count = Integer.parseInt(txtusunit.getText());
if(count < 500)
charge = 1.00;
else if(count < 500 && count <600)
charge = 1.80;
else if(count < 600 && count <800)
charge = 2.80;
else
charge = 3.00;
total = charge * count ;
txtbill.setEditable(false);
print();
}//GEN-LAST:event_btnsbillActionPerformed
private void txtcsidActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtcsidActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtcsidActionPerformed
private void btnloutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnloutActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_btnloutActionPerformed
/**
* @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 ("windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Bill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Bill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Bill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Bill.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
new Bill().setVisible(true);
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnlout;
private javax.swing.JButton btnsbill;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblcsid;
private javax.swing.JLabel lblcsname;
private javax.swing.JLabel lblunit;
private javax.swing.JTextArea txtbill;
private javax.swing.JTextField txtcsid;
private javax.swing.JTextField txtusname;
private javax.swing.JTextField txtusunit;
// End of variables declaration//GEN-END:variables
}
<!DOCTYPE html>
<html>
<body>
<h2>Project Done by © Nushrat Jaben Aurnima. All Rights Reserved .</h2>
</body>
</html>