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