Ladrillo.java
Categorías: CategoryJava | CategoryProgramacion |
1 /**
2 *@author Elkin Andrey Garzón Alarcón...Geek Master
3 *@author Ingrid Lorena Guerrero Mayorga...
4 *@author Jefferson Fabian Idarraga Idarraga Pinilla...
5 */
6 package pinguinogg;
7 import java.awt.BorderLayout;
8
9 import java.awt.Checkbox;
10 import java.awt.GridLayout;
11 import java.awt.Label;
12 import java.awt.TextField;
13 import java.awt.event.ActionEvent;
14 import java.awt.event.ActionListener;
15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.io.InputStream;
19
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22
23 import javax.swing.JButton;
24 import javax.swing.JFrame;
25 import javax.swing.JOptionPane;
26 import javax.swing.JTextField;
27 import org.omg.CORBA.PUBLIC_MEMBER;
28 import sun.audio.AudioPlayer;
29 import sun.audio.AudioStream;
30 ;
31 import javax.swing.JPanel;
32
33 public class Formulario extends JFrame {
34
35 /*
36 * creacion del formulario
37 */
38 private Configuracion configuracion;
39 private Cronometro cronometro;
40 private Thread hiloCronometro;
41 JTextField tiempo = new JTextField();
42 JTextField ip = new JTextField();
43 Checkbox sonido = new Checkbox();
44 JButton guardar = new JButton("Guardar");
45 JButton cancelar = new JButton("Cancelar");
46
47
48
49
50 public Formulario(Configuracion configuracion,Cronometro c) {
51 /*
52 * ubicacion de los botones en el formulario
53 */
54 super("Configuracion");
55 this.hiloCronometro = new Thread(c);
56 setLayout(new BorderLayout());
57 add("North", new Label("Configuracion"));
58 setSize(500,300);
59 setVisible(true);
60 JPanel central = new JPanel();
61 central.setLayout(new GridLayout(8, 2));
62 //direccion IP
63 central.add(new Label("DireccionIP"));
64
65 central.add((ip));
66
67 //cronometro
68 central.add(new Label("Cronometro"));
69 central.add(tiempo);
70
71 //sonido
72 central.add(new Label("Sonido"));
73 Checkbox checkBoxSonido = new Checkbox("Si");
74 central.add(checkBoxSonido);
75 central.add(new Label(" "));
76 central.add(new Checkbox("No"));
77 //puntaje
78 central.add(new Label("Puntaje"));
79 central.add(new TextField());
80 central.add(guardar);
81 central.add(cancelar);
82 //central.add(Iniciar);
83
84 add("Center", central);
85
86 /*
87 * codificacion del boton cancelar
88 */
89
90 //button cancelar....
91 cancelar.addActionListener(new ActionListener() {
92
93 public void actionPerformed(ActionEvent e) {
94
95 setVisible(false);
96 }
97 });
98
99 /*
100 * codificacion del boton guardar
101 */
102 //button guardar
103 guardar.addActionListener(new ActionListener() {
104
105
106 public void actionPerformed(ActionEvent e) {
107
108
109 Configuraciones.ip = (ip.getText());
110 Configuraciones.cronometro = Integer.parseInt(tiempo.getText());
111 Configuraciones.sonido = sonido.getState();
112
113 if (Configuraciones.sonido == true) {
114 try {
115 InputStream in = new FileInputStream("fondo.mid");
116 AudioStream as;
117 try {
118 as = new AudioStream(in);
119 AudioPlayer.player.start(as);
120 } catch (IOException ex) {
121 Logger.getLogger(Formulario.class.getName()).log(Level.SEVERE, null, ex);
122 }
123
124
125 } catch (FileNotFoundException ex) {
126 Logger.getLogger(EscuchaMouse.class.getName()).log(Level.SEVERE, null, ex);
127 } catch (IOException ex) {
128 Logger.getLogger(EscuchaMouse.class.getName()).log(Level.SEVERE, null, ex);
129 }
130 }
131 if (Configuraciones.sonido == false) {
132 JOptionPane.showMessageDialog(null, "sonido no habilitado");
133 }
134 hiloCronometro.start();
135 JOptionPane.showMessageDialog(null, "Datos guardados correctamente");
136 setVisible(true);
137 }
138 });
139
140
141 }
142
143
144 }
