comparison src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java @ 1:75b54fd9e73a

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