-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.java
115 lines (86 loc) · 3.27 KB
/
Account.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
package oodp;
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;
public class Account extends JPanel implements ActionListener
{
JPanel panel = new JPanel();
JButton recharge;
JTextField id;
JTextField coupon;
JTextField point;
int current_point;
public Account()
{
if(MainBoard.getInstanceCustomer() instanceof Student){
id = new JTextField(10);
coupon = new JTextField(10);
point = new JTextField(10);
id.setEditable(false);
panel.add(id,BorderLayout.SOUTH);
coupon.setEditable(false);
panel.add(coupon,BorderLayout.SOUTH);
point.setEditable(false);
panel.add(point,BorderLayout.SOUTH);
id.setText(MainBoard.getInstanceCustomer().getId());
coupon.setText(String.valueOf(MainBoard.getInstanceCustomer().getCoupon()));
try{
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "bitnami");
Statement stmt=conn.createStatement();
ResultSet qry = stmt.executeQuery("SELECT * FROM stuinfo");
while(qry.next()){
if(qry.getString("id").equals(MainBoard.getInstanceCustomer().getId())){
point.setText(String.valueOf(qry.getInt("point")));
current_point = qry.getInt("point");
}
}
}
catch(Exception exp){}
recharge = new JButton("recharge");
// 추가
panel.add(recharge,BorderLayout.SOUTH);
recharge.addActionListener(this);
}
else{
id = new JTextField(10);
coupon = new JTextField(10);
id.setEditable(false);
panel.add(id,BorderLayout.SOUTH);
coupon.setEditable(false);
panel.add(coupon,BorderLayout.SOUTH);
id.setText(MainBoard.getInstanceCustomer().getId());
coupon.setText(String.valueOf(MainBoard.getInstanceCustomer().getCoupon()));
}
}
public void actionPerformed(ActionEvent e){
Object event = e.getSource();
MainBoard.board.remove(MainBoard.board_panel);
MainBoard.board.repaint();
MainBoard.board.revalidate();
MainBoard.board_panel=this.panel;
MainBoard.board_panel.setBackground(Color.white);
MainBoard.board_panel.setBounds(150,40,650,560);
MainBoard.board.add(MainBoard.board_panel);
if(event == this.recharge){
String input;
int money;
input = JOptionPane.showInputDialog("충전할 포인트를 입력하여 주세요.");
money = Integer.parseInt(input);
try{
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root", "bitnami");
PreparedStatement s;
s = conn.prepareStatement("UPDATE stuinfo SET point = point + '"+money+"' WHERE id=?");
s.setString(1, MainBoard.getInstanceCustomer().getId());
s.executeUpdate();
JOptionPane.showMessageDialog(null, "충전이 완료되었습니다..");
point.setText(String.valueOf(current_point+money));
}
catch(Exception exp){}
}
}
}