-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLei.java
More file actions
148 lines (136 loc) · 4.6 KB
/
Copy pathLei.java
File metadata and controls
148 lines (136 loc) · 4.6 KB
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
package sinaData;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.junit.Test;
public class Lei {
public static GuPiaoData selelctedPiaoData;
public static void main(String[] args) throws IOException {
UIData.getInstance();
}
public static void writeUIData() {
if (selelctedPiaoData == null || selelctedPiaoData.getName() == "") {
return;
}
JLabel l = UIData.getInstance().getNameJlabel();
JFrame f = UIData.getInstance().getMainFrame();
UIData.getInstance().getNameJlabel().setText(selelctedPiaoData.getName());
UIData.getInstance().getTodayOpenPriceJlabel().setText(selelctedPiaoData.getNowPrice());
// 文字颜色
l.setForeground(Color.red);
l.setBounds(50, 150, 280, 30);
UIData.getInstance().getTodayOpenPriceJlabel().setForeground(Color.red);
UIData.getInstance().getTodayOpenPriceJlabel().setBounds(130, 150, 280, 30);
f.add(UIData.getInstance().getTodayOpenPriceJlabel());
f.add(l);
f.setVisible(true);
}
static ScheduledExecutorService runningTimer = null;
public static ActionListener listenerStart = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JButton startButton = UIData.getInstance().getStartButton();
if (startButton.getText().equals("停止监控")) {
runningTimer.shutdownNow();
startButton.setText("开始监控");
UIData.getInstance().getNameJlabel().setText("");
} else {
System.out.println("我要启动了");
ScheduledExecutorService runningTime = Executors.newScheduledThreadPool(1);
runningTimer = runningTime;
runningTime.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
getUrl();
writeUIData();
}
}, 0, 1000, TimeUnit.MILLISECONDS);
startButton.setText("停止监控");
}
}
};
@Test
public static void getUrl() {
String url = "http://hq.sinajs.cn/list=sh600985";
try {
URL u = new url(url);
InputStream in = null;
StringBuilder sb = new StringBuilder();
String str;
try {
in = u.openStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in, "GB2312"));
while ((str = br.readLine()) != null) {
sb.append(str);
}
String result = sb.toString();
String[] stocks = result.split(";");
for (String stock : stocks) {
String[] datas = stock.split(",");
if (datas.length <= 30) {
continue;
}
selelctedPiaoData = formatData(datas);
}
System.out.println(selelctedPiaoData.toString());
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
if (in != null) {
in.close();
}
}
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
public static GuPiaoData formatData(String[] datas) {
GuPiaoData guPiaoData = new GuPiaoData();
// 根据对照自己对应数据
guPiaoData.setName(datas[0].split("\"")[1]);
guPiaoData.setTodayOpenPrice(datas[1]);
guPiaoData.setYstdayOpenPrice(datas[2]);
guPiaoData.setNowPrice(datas[3]);
guPiaoData.setTodayHightPrice(datas[4]);
guPiaoData.setTodayLowPrice(datas[5]);
guPiaoData.setJingmaiPayPrice1(datas[6]);
guPiaoData.setJingmaiGetPrice1(datas[7]);
guPiaoData.setChengjiaoNum(datas[8]);
guPiaoData.setChengjiaoTall(datas[9]);
guPiaoData.setPayPrice1(datas[10]);
guPiaoData.setPayNumber1(datas[11]);
guPiaoData.setPayPrice2(datas[12]);
guPiaoData.setPayNumber2(datas[13]);
guPiaoData.setPayPrice3(datas[14]);
guPiaoData.setPayNumber3(datas[15]);
guPiaoData.setPayPrice4(datas[16]);
guPiaoData.setPayNumber4(datas[17]);
guPiaoData.setPayPrice5(datas[18]);
guPiaoData.setPayNumber5(datas[19]);
guPiaoData.setGetPrice1(datas[20]);
guPiaoData.setGetNumber1(datas[21]);
guPiaoData.setGetPrice2(datas[22]);
guPiaoData.setGetNumber2(datas[23]);
guPiaoData.setGetPrice3(datas[24]);
guPiaoData.setGetNumber3(datas[25]);
guPiaoData.setGetPrice4(datas[26]);
guPiaoData.setGetNumber4(datas[27]);
guPiaoData.setGetPrice5(datas[28]);
guPiaoData.setGetNumber5(datas[29]);
guPiaoData.setData(datas[30]);
guPiaoData.setTime(datas[31]);
guPiaoData.setOther(datas[32]);
return guPiaoData;
}
}