comparison src/myVncClient/TextBox.java @ 1:8f9bf4708785

add files
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Mon, 12 Dec 2011 12:34:03 +0900
parents
children 56251926d766
comparison
equal deleted inserted replaced
0:b8ef1727f626 1:8f9bf4708785
1 package myVncClient;
2
3 import javax.swing.*;
4 import java.awt.*;
5 import java.awt.event.*;
6 import java.util.ArrayList;
7
8 public class TextBox extends JFrame implements ActionListener {
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;
15 private double height;
16 private JLabel label;
17 private boolean flag;
18 ArrayList<String> temp = new ArrayList<String>();
19 private int counter=0;
20 private Checkbox[] check = new Checkbox[20];
21 private boolean firstFlag=true;
22 private String hostAddress;
23 private String port;
24
25
26 public void ipRegister() {
27 setSize();
28 setText();
29 visible();
30 }
31
32
33 public TextBox() {
34 setTitle("Informatin Connection Address");
35 setResizable(false);
36 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
37 }
38
39
40 private void setSize() {
41 Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
42 width = (d.getWidth() / 2);
43 height = (d.getHeight() / 2);
44 }
45
46 void visible() {
47 Point point = new Point();
48 point.setLocation(width - 250, height - 80);
49 setLocation(point.getLocation());
50 pack();
51 setVisible(true);
52 }
53
54 private void setText() {
55 t1 = new TextField("Address", 30);
56 t2 = new TextField("5999", 5);
57 panel.add(t1);
58 panel.add(t2);
59 panel.add(button);
60 button.addActionListener(this);
61 label = new JLabel();
62 Container contentPane = getContentPane();
63 contentPane.add(panel, BorderLayout.CENTER);
64 contentPane.add(label, BorderLayout.SOUTH);
65 }
66
67 void checkBox(String str) {
68 CheckboxGroup ch = new CheckboxGroup();
69 check[counter] = new Checkbox(str,ch,false);
70 check[counter].setBackground(new Color(0,153,255));
71 panel.add(check[counter]);
72 panel.setLayout(new GridLayout(counter+2, 0));
73 counter++;
74 }
75
76 void setButton(){
77 panel.add(button);
78 panel.setBackground(Color.blue);
79 button.addActionListener(this);
80 Container contentPane = getContentPane();
81 contentPane.add(panel, BorderLayout.CENTER);
82 }
83
84 String splitString(String str) {
85 String[] split = str.split("\\*");;
86 String comper;
87 if(split.length>4) {
88 split[4] = null;
89 }
90 comper = split[1]+split[3];
91 if(firstFlag) {
92 temp.add(comper);
93 firstFlag = false;
94 return "port:"+split[0]+":host:"+split[1]+":proxy:"+split[3];
95 }
96 for(int t=0;t<temp.size();t++){
97 if(!(comper.equals(temp.get(t)))){
98 if(t == temp.size()-1){
99 temp.add(comper);
100 return "port:"+split[0]+":host:"+split[1]+":proxy:"+split[3];
101 }
102 } else {
103 break;
104 }
105 }
106 return null;
107 }
108
109
110 public String getAddress() {
111 while(!(flag)) {
112 try {
113 Thread.sleep(500);
114 } catch (InterruptedException e) {
115 e.printStackTrace();
116 }
117 }
118 return hostAddress;
119 //return t1.getText();
120 }
121
122 public String getPort() {
123 return port;
124 //return t2.getText();
125 }
126
127 public void actionPerformed(ActionEvent e) {
128 flag = true;
129 for(int t=0;t<counter;t++) {
130 if(check[t].getState()){
131 System.out.println(check[t].getLabel());
132 setStatus(check[t].getLabel());
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 }