comparison src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java @ 12:12c3a73be47f

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