-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicketsQueryFragment.java
154 lines (129 loc) · 5.75 KB
/
TicketsQueryFragment.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
package com.fragment;
import com.activity.UserActivity;
import com.base.BaseFragment;
import com.bean.TrainClass;
import com.db.SqlUser;
import com.dialog.IdCardChooseDialog;
import com.ui.MyButton;
import com.ui.MyLabel;
import com.ui.MyTextField;
import com.utils.ConstantsUtils;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
public class TicketsQueryFragment extends BaseFragment {
private JTextField inputTextField;
private JLabel inputLabel;
private JButton okButton;
private JLabel informationLabel;
private JLabel classNumber;
private JLabel trainNumber;
private JLabel depaturePlace;
private JLabel goalPlace;
private JLabel depatureTimeLabel;
private JLabel restSeetNumber;
private Document document;
private JLabel depatureTime;
private TrainClass trainClass;
private BuyRecordFragment buyRecordFragment;
private InformationFragment informationFragment;
public TicketsQueryFragment(BuyRecordFragment buyRecordFragment, InformationFragment informationFragment) {
this.buyRecordFragment = buyRecordFragment;
this.informationFragment = informationFragment;
}
@Override
public void initView() {
this.setLayout(null);
//背景图
ImageIcon bg = new ImageIcon(UserActivity.class.getResource("images//user_bg_2_cai.jpg"));//背景图案
bg.setImage(bg.getImage().
getScaledInstance(ConstantsUtils.LOGIN_WIDTH,
ConstantsUtils.LOGIN_HEIGH - 70,
Image.SCALE_DEFAULT));
JLabel bgLabel = new JLabel(bg);
bgLabel.setBounds(0, 0, ConstantsUtils.LOGIN_WIDTH, ConstantsUtils.LOGIN_HEIGH - 70);
inputLabel = new MyLabel("请输入班次号:", 20, 50, 150, 50, titleFont);
inputTextField = new MyTextField(150, 50, 220, 50, titleFont);
document = inputTextField.getDocument();
okButton = new MyButton("查询", 155, 420, 100, 50, textFont, 1);
informationLabel = new JLabel();
informationLabel.setBounds(130, 110, 260, 300);
int starty = 10;
int margin = 40;
classNumber = new MyLabel("班次号:" + ConstantsUtils.TESTCLASS.getClassNumber(), 10, starty, 200, 50, textFont);
trainNumber = new MyLabel("火车号:" + ConstantsUtils.TESTCLASS.getTrainNumber(), 10, starty += margin, 200, 50, textFont);
depaturePlace = new MyLabel("出发地点:" + ConstantsUtils.TESTCLASS.getDepaturePlace(), 10, starty += margin, 200, 50, textFont);
goalPlace = new MyLabel("目的地:" + ConstantsUtils.TESTCLASS.getGoalPlace(), 10, starty += margin, 200, 50, textFont);
depatureTimeLabel = new MyLabel("出发时间:", 10, starty += margin, 200, 50, textFont);
depatureTime = new MyLabel(ConstantsUtils.TESTCLASS.getDepatureDay() + "", 10, starty += margin, 200, 50, textFont);
restSeetNumber = new MyLabel("剩余座位:" + ConstantsUtils.TESTCLASS.getPassengerNumber(), 10, starty += margin, 200, 50, textFont);
informationLabel.setVisible(false);
informationLabel.add(depatureTime);
informationLabel.add(classNumber);
informationLabel.add(trainNumber);
informationLabel.add(depaturePlace);
informationLabel.add(goalPlace);
informationLabel.add(depatureTimeLabel);
informationLabel.add(restSeetNumber);
// informationLabel.setBackground(Color.red);
// informationLabel.setLayout(null);
this.add(informationLabel);
this.add(okButton);
this.add(inputTextField);
this.add(inputLabel);
this.add(bgLabel);
}
@Override
public SqlUser initSqlUser() {
return SqlUser.newInstance(SqlUser.USER_TYPE);
}
@Override
public void loadData() {
}
@Override
public void addListener() {
document.addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
okButton.setText("查询");
}
@Override
public void removeUpdate(DocumentEvent e) {
}
@Override
public void changedUpdate(DocumentEvent e) {
okButton.setText("查询");
}
});
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (okButton.getText().equals("查询")) {
try {
trainClass = getSqlHelper().queryClasses(inputTextField.getText());
updateText(trainClass);
okButton.setText("购买");
} catch (SQLException e1) {
e1.printStackTrace();
}
} else {
IdCardChooseDialog idCardChooseDialog = new IdCardChooseDialog(trainClass, buyRecordFragment, informationFragment);
}
}
});
}
private void updateText(TrainClass trainClass) {
classNumber.setText("班次号:" + trainClass.getClassNumber());
trainNumber.setText("火车号:" + trainClass.getTrainNumber());
depaturePlace.setText("出发地点:" + trainClass.getDepaturePlace());
goalPlace.setText("目的地:" + trainClass.getGoalPlace());
depatureTime.setText("" + trainClass.getDepatureDay() + " " + trainClass.getTime());
restSeetNumber.setText("剩余座位:" + (10 * 40 - trainClass.getPassengerNumber()) + "");
informationLabel.setVisible(true);
}
}