comparison src/treeVnc/TextBoxClient.java @ 0:756bfaf731f3

create new repository
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 21 Feb 2012 04:10:12 +0900
parents
children 3b341997141a
comparison
equal deleted inserted replaced
-1:000000000000 0:756bfaf731f3
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 */
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 reportWindow();
123 visible();
124 break;
125 }
126 try {
127 Thread.sleep(500);
128 } catch (InterruptedException e) {
129 e.printStackTrace();
130 }
131 i++;
132 }
133 return hostAddress;
134 // return t1.getText();
135 }
136
137 public String getPortOption() {
138 return t2.getText();
139 }
140
141 public String getPort() {
142 return port;
143 // return t2.getText();
144 }
145
146 public void actionPerformed(ActionEvent e) {
147 flag = true;
148 for (int t = 0; t < counter; t++) {
149 if (check[t].getState()) {
150 System.out.println(check[t].getLabel());
151 // if(int t =0)
152 setStatus(check[t].getLabel());
153 unVisible();
154 // else
155 // setStatus()
156 }
157 }
158 }
159
160 private void setStatus(String str) {
161 String[] temp = str.split(":");
162 if (temp.length == 2) {
163 hostAddress = temp[0];
164 port = temp[1];
165 } else {
166 port = temp[0];
167 System.out.println("port=" + port);
168 hostAddress = temp[3];
169 }
170 }
171
172 String splitString(String str) {
173 String[] split = str.split("\\*");
174 String comper;
175 if (split.length > 4) {
176 split[4] = null;
177 }
178 comper = split[1] + split[3];
179 if (firstFlag) {
180 temp.add(comper);
181 firstFlag = false;
182 return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
183 + split[3];
184 }
185 for (int t = 0; t < temp.size(); t++) {
186 if (!(comper.equals(temp.get(t)))) {
187 if (t == temp.size() - 1) {
188 temp.add(comper);
189 return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
190 + split[3];
191 }
192 } else {
193 break;
194 }
195 }
196 return null;
197 }
198
199 public void itemStateChanged(ItemEvent e) {
200 }
201 }