FormConfi.java
Categorías: CategoryJava | CategoryProgramacion |
1 package savetheearthsk;
2
3 import com.sun.corba.se.impl.orbutil.concurrent.Sync;
4 import java.awt.BorderLayout;
5
6 import java.awt.Checkbox;
7 import java.awt.Choice;
8
9 import java.awt.GridLayout;
10 import java.awt.Label;
11 import java.awt.Panel;
12 import java.awt.event.ActionEvent;
13 import java.awt.event.ActionListener;
14 import java.awt.event.MouseAdapter;
15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.FileOutputStream;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.ObjectOutputStream;
21 import java.util.ArrayList;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import javax.swing.ButtonGroup;
25 import javax.swing.JButton;
26 import javax.swing.JColorChooser;
27 import javax.swing.JComboBox;
28 import javax.swing.JFrame;
29 import javax.swing.JOptionPane;
30 import javax.swing.JRadioButton;
31 import javax.swing.JTextField;
32 import org.omg.Messaging.SYNC_WITH_TRANSPORT;
33 import sun.audio.AudioPlayer;
34 import sun.audio.AudioStream;
35 import java.lang.Object;
36
37 /**
38 *
39 * @author lina maria bermudez
40 * @author mario nicolas arcila
41 */
42
43 /**
44 * Esta clase es la que tiene el formulario en la cual se encuentran todas las configuraciones
45 */
46
47
48 public class FormConfi extends JFrame{
49
50 JColorChooser color1 = new JColorChooser();
51 JColorChooser color2 = new JColorChooser();
52 JColorChooser color3 = new JColorChooser();
53 Choice pruebaCombito = new Choice();
54 private Configuraciones configuraciones;
55 private Cronometro cronometro;
56 private Thread hiloCronometro;
57 JTextField tiempito = new JTextField();
58 JTextField numip = new JTextField();
59 Checkbox sonido = new Checkbox();
60 JButton colores = new JButton("Colores");
61 JButton guardar = new JButton("Guardar");
62 JButton limpiar = new JButton("Limpiar");
63 JButton cancelar = new JButton("cancelar");
64 ButtonGroup controles = new ButtonGroup();
65 JComboBox combito = new JComboBox();
66 Calaveragg1 calavera;
67 JRadioButton mouse = new JRadioButton("mouse");
68 JRadioButton teclado = new JRadioButton("Teclado");
69 private Pared pared;
70 private ArrayList listaCalaveras = new ArrayList<Calaveragg1>();
71
72 public FormConfi(final Thread hiloCronometro, final ArrayList<Calaveragg1> listaCalaveras, final Configuraciones configuraciones) {
73
74 super(" Contactos ");
75
76
77
78
79
80 this.configuraciones = configuraciones;
81 this.listaCalaveras = listaCalaveras;
82 this.hiloCronometro = hiloCronometro;
83 this.setBounds(500, 300, 500, 250);
84
85 numip.setBounds(0, 0, 100, 25);
86 tiempito.setBounds(0, 0, 100, 25);
87
88
89
90
91 this.setLayout(new BorderLayout(5, 5));
92 this.add(new Label("Configuracion"), BorderLayout.NORTH);
93
94 Panel panelsito = new Panel();
95 this.add(panelsito, BorderLayout.CENTER);
96 panelsito.setLayout(new GridLayout(1, 4));
97
98
99
100
101 Panel izquierdito = new Panel();
102
103 izquierdito.setLayout(new GridLayout(5, 2));
104
105 //ip
106
107
108 izquierdito.add(new Label("Direccion IP"));
109 izquierdito.add(numip);
110 numip.setText(configuraciones.ip);
111
112 //Sonido
113 izquierdito.add(new Label("Sonido fondo"));
114 izquierdito.add(sonido);
115 sonido.setState(configuraciones.sonido);
116
117
118
119
120
121
122
123
124
125
126
127 //Control
128 izquierdito.add(new Label("Control"));
129 Panel controls = new Panel();
130
131 controles.add(mouse);
132 controles.add(teclado);
133 controls.add(mouse);
134 controls.add(teclado);
135 izquierdito.add(controls);
136
137
138 //cronometro
139
140
141 izquierdito.add(new Label("Tiempo"));
142 izquierdito.add(tiempito);
143 tiempito.setText("" + configuraciones.cronometro);
144
145 panelsito.add(izquierdito);
146
147
148
149
150
151 //abajo
152 Panel abajo = new Panel();
153 abajo.add(guardar);
154 abajo.add(limpiar);
155 abajo.add(cancelar);
156 abajo.add(colores);
157
158
159 this.add(abajo, BorderLayout.SOUTH);
160
161
162
163
164
165
166
167 colores.addActionListener(new ActionListener() {
168 /**
169 * Este abre la ventana de colores
170 */
171
172 public void actionPerformed(ActionEvent e) {
173
174 FormColores formColores = new FormColores(listaCalaveras, configuraciones);
175 formColores.setVisible(true);
176
177 }
178 });
179 /**
180 * Este deja todos los valores en 0s
181 */
182
183 limpiar.addActionListener(new ActionListener() {
184
185 public void actionPerformed(ActionEvent e) {
186 numip.setText("");
187 sonido.setState(false);
188 tiempito.setText("");
189 controles.clearSelection();
190
191 }
192 });
193 /**
194 * Este ocualta la ventana de configuraciones
195 */
196 cancelar.addActionListener(new ActionListener() {
197
198 public void actionPerformed(ActionEvent e) {
199
200 setVisible(false);
201 }
202 });
203
204 /**
205 * Este guarda las configuracioens ajustadas y las ubica en la clase configuraciones
206 */
207 guardar.addActionListener(new ActionListener() {
208
209 synchronized public void actionPerformed(ActionEvent e) {
210 if (mouse.isSelected() == true) {
211 configuraciones.mouse = true;
212 configuraciones.teclado = false;
213 JOptionPane.showMessageDialog(null, "Jejeje selecciono el mouse");
214 }
215 if (teclado.isSelected() == true) {
216 configuraciones.teclado = true;
217 configuraciones.mouse = false;
218 JOptionPane.showMessageDialog(null, "Jejeje selecciono el Teclado");
219 }
220
221 configuraciones.ip = (numip.getText());
222 configuraciones.cronometro = Integer.parseInt(tiempito.getText());
223 configuraciones.sonido = sonido.getState();
224
225
226
227 try {
228
229 InputStream in = new FileInputStream("BT.mid");
230 AudioStream as;
231 as = new AudioStream(in);
232 AudioPlayer ap ;
233
234
235
236
237 configuraciones.sonido = sonido.getState();
238 if (configuraciones.sonido == true) {
239 System.err.println("start");
240 AudioPlayer.player.start(as);
241
242 } else {
243
244 System.err.println("stoptito");
245 AudioPlayer.player.stop(as);
246
247 // AudioPlayer.player.shutdown();
248
249 }
250
251 } catch (FileNotFoundException ex) {
252 Logger.getLogger(EscuchaMouse.class.getName()).log(Level.SEVERE, null, ex);
253 } catch (IOException ex) {
254 Logger.getLogger(EscuchaMouse.class.getName()).log(Level.SEVERE, null, ex);
255 }
256
257
258
259 System.err.println("configuraciones.cronometro = " + configuraciones.cronometro);
260
261
262
263
264
265
266
267
268
269
270
271 try {
272 ObjectOutputStream confi = new ObjectOutputStream(new FileOutputStream(configuraciones.nomArchConf));//"confi.dat"));
273 confi.writeObject(configuraciones);
274 confi.close();
275 System.err.println("configuraciones.cronometro = " + configuraciones.cronometro);
276 } catch (FileNotFoundException f) {
277 System.err.println("no existe el archivo");
278 Logger.getLogger(FormConfi.class.getName()).log(Level.SEVERE, null, f);
279 } catch (IOException ex) {
280 Logger.getLogger(FormConfi.class.getName()).log(Level.SEVERE, null, ex);
281 }
282
283 JOptionPane.showMessageDialog(null, "Datos guardados correctamente");
284 setVisible(
285 false);
286
287 }
288 });
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309 }
310 }
