0
|
1 package treeVnc;
|
|
2
|
|
3 import javax.swing.*;
|
|
4 import java.awt.*;
|
|
5 import java.awt.event.*;
|
|
6 import java.util.ArrayList;
|
|
7
|
|
8 public class TextBoxClient extends JFrame implements ActionListener,
|
|
9 ItemListener {
|
|
10 /**
|
|
11 *
|
|
12 */
|
|
13 private static final long serialVersionUID = 1L;
|
|
14 private JPanel panel = new JPanel();
|
|
15 private JButton button = new JButton("Connect");
|
|
16 private TextField t1;
|
|
17 private TextField t2;
|
|
18 private double width = 750;
|
|
19 private double height = 500;
|
|
20 private JLabel label;
|
|
21 private boolean flag;
|
|
22 private ArrayList<String> temp = new ArrayList<String>();
|
|
23 private int counter = 0;
|
|
24 // private JCheckBox[] check = new JCheckBox[20];
|
|
25 private Checkbox[] check = new Checkbox[20];
|
|
26 private boolean firstFlag = true;
|
|
27 private String hostAddress;
|
|
28 private String port;
|
|
29 private CheckboxGroup ch = new CheckboxGroup();
|
|
30
|
|
31 public TextBoxClient() {
|
|
32 setTitle("Informatin Connection Address");
|
|
33 setResizable(false);
|
|
34 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
35 }
|
|
36
|
|
37 public void ipRegister() {
|
|
38 setSize();
|
|
39 setText();
|
|
40 visible();
|
|
41 }
|
|
42
|
|
43 private void setSize() {
|
|
44 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
|
45 width = (d.getWidth() / 2);
|
|
46 height = (d.getHeight() / 2);
|
|
47 }
|
|
48
|
|
49 void visible() {
|
|
50 Point point = new Point();
|
|
51 point.setLocation(width - 250, height - 80);
|
|
52 setLocation(point.getLocation());
|
|
53 pack();
|
|
54 setVisible(true);
|
|
55 }
|
|
56
|
|
57 public void unVisible() {
|
|
58 setVisible(false);
|
|
59 }
|
|
60
|
|
61 private void setText() {
|
|
62 t1 = new TextField("Address", 30);
|
|
63 t2 = new TextField("5999", 5);
|
|
64 panel.add(t1);
|
|
65 panel.add(t2);
|
|
66 panel.add(button);
|
|
67 button.addActionListener(this);
|
|
68 label = new JLabel();
|
|
69 Container contentPane = getContentPane();
|
|
70 contentPane.add(panel, BorderLayout.CENTER);
|
|
71 contentPane.add(label, BorderLayout.SOUTH);
|
|
72 }
|
|
73
|
|
74 void checkBox(String str) {
|
|
75 // CheckboxGroup ch = new CheckboxGroup();
|
|
76 if (counter == 0)
|
|
77 check[counter] = new Checkbox(str, true, ch);
|
|
78 else
|
|
79 check[counter] = new Checkbox(str, false, ch);
|
|
80 // check[counter].setBackground(new Color(0, 153, 255));
|
|
81 check[counter].addItemListener(this);
|
|
82 panel.add(check[counter]);
|
|
83 panel.setLayout(new GridLayout(counter + 2, 0));
|
|
84 panel.setLocation((int) width - 250, (int) height - 80);
|
|
85 counter++;
|
|
86 }
|
|
87
|
|
88 public void setButton() {
|
|
89 panel.add(button);
|
|
90 // panel.setBackground(Color.blue);
|
|
91 button.addActionListener(this);
|
|
92 Container contentPane = getContentPane();
|
|
93 contentPane.add(panel, BorderLayout.CENTER);
|
|
94 }
|
|
95
|
|
96 private void reportWindow() {
|
|
97 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
98 Container pane = getContentPane();
|
|
99 JLabel label = new JLabel(
|
|
100 "Not found Proxy. If you use Client-mode you must set-up Proxy");
|
|
101 label.setPreferredSize(new Dimension(580, 50));
|
|
102 label.setFont(new Font("Arial", Font.PLAIN, 20));
|
|
103 pane.add(label);
|
|
104 }
|
|
105
|
|
106 public String getAddressOption() {
|
|
107 while (!(flag)) {
|
|
108 try {
|
|
109 Thread.sleep(500);
|
|
110 } catch (InterruptedException e) {
|
|
111 e.printStackTrace();
|
|
112 }
|
|
113 }
|
|
114 return t1.getText();
|
|
115 }
|
|
116
|
|
117 public String getAddress() {
|
|
118 int i = 0;
|
|
119 while (!(flag)) {
|
|
120 if (i >= 50) {
|
3
|
121 /*
|
0
|
122 reportWindow();
|
|
123 visible();
|
|
124 break;
|
3
|
125 */
|
|
126 return "notFound";
|
0
|
127 }
|
|
128 try {
|
|
129 Thread.sleep(500);
|
|
130 } catch (InterruptedException e) {
|
|
131 e.printStackTrace();
|
|
132 }
|
|
133 i++;
|
|
134 }
|
|
135 return hostAddress;
|
|
136 // return t1.getText();
|
|
137 }
|
|
138
|
|
139 public String getPortOption() {
|
|
140 return t2.getText();
|
|
141 }
|
|
142
|
|
143 public String getPort() {
|
|
144 return port;
|
|
145 // return t2.getText();
|
|
146 }
|
|
147
|
|
148 public void actionPerformed(ActionEvent e) {
|
|
149 flag = true;
|
|
150 for (int t = 0; t < counter; t++) {
|
|
151 if (check[t].getState()) {
|
|
152 System.out.println(check[t].getLabel());
|
|
153 // if(int t =0)
|
|
154 setStatus(check[t].getLabel());
|
|
155 unVisible();
|
|
156 // else
|
|
157 // setStatus()
|
|
158 }
|
|
159 }
|
|
160 }
|
|
161
|
|
162 private void setStatus(String str) {
|
|
163 String[] temp = str.split(":");
|
|
164 if (temp.length == 2) {
|
|
165 hostAddress = temp[0];
|
|
166 port = temp[1];
|
|
167 } else {
|
|
168 port = temp[0];
|
|
169 System.out.println("port=" + port);
|
|
170 hostAddress = temp[3];
|
|
171 }
|
|
172 }
|
|
173
|
|
174 String splitString(String str) {
|
|
175 String[] split = str.split("\\*");
|
|
176 String comper;
|
|
177 if (split.length > 4) {
|
|
178 split[4] = null;
|
|
179 }
|
|
180 comper = split[1] + split[3];
|
|
181 if (firstFlag) {
|
|
182 temp.add(comper);
|
|
183 firstFlag = false;
|
|
184 return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
|
|
185 + split[3];
|
|
186 }
|
|
187 for (int t = 0; t < temp.size(); t++) {
|
|
188 if (!(comper.equals(temp.get(t)))) {
|
|
189 if (t == temp.size() - 1) {
|
|
190 temp.add(comper);
|
|
191 return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
|
|
192 + split[3];
|
|
193 }
|
|
194 } else {
|
|
195 break;
|
|
196 }
|
|
197 }
|
|
198 return null;
|
|
199 }
|
|
200
|
|
201 public void itemStateChanged(ItemEvent e) {
|
|
202 }
|
|
203 }
|