Bueno este es mi problema:
tengo un applet el cual quiero que en un boton haga que muestre una ventana para registro de usuario ,esto lo tengo en otro applet mi duda es como hacer esto ,si lo deberia hacer desde otro applet,lo trate de hacer desde un jInternalFrame pero no logre que lo mostrara .estuve buscando si un applet podría abrir otro applet y no encontré nada claro , después pensé que este sea abierto desde otra ventana pero se me complico un poco ya que soy novato y esta es la primera vez que pido ayuda en un foro asi que les agradecería una mano gracias.
tengo un applet el cual quiero que en un boton haga que muestre una ventana para registro de usuario ,esto lo tengo en otro applet mi duda es como hacer esto ,si lo deberia hacer desde otro applet,lo trate de hacer desde un jInternalFrame pero no logre que lo mostrara .estuve buscando si un applet podría abrir otro applet y no encontré nada claro , después pensé que este sea abierto desde otra ventana pero se me complico un poco ya que soy novato y esta es la primera vez que pido ayuda en un foro asi que les agradecería una mano gracias.
Código:
1 /*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6 /*
7 * Prueba.java
8 *
9 * Created on 17/04/2011, 01:42:09 PM
10 */
11
12 package appleet;
13
14 import java.awt.Graphics;
15 import java.io.BufferedReader;
16 import java.io.FileReader;
17 import java.io.IOException;
18 import javax.swing.JOptionPane;
19
20
21 /**
22 *
23 * @author Jose
24 */
25
26 public class Prueba extends javax.swing.JApplet {
27
28
29
30 public boolean comprobar() {
31
32
33
34 String user = jTextField1.getText();
35 char passarreglo[]= jPasswordField1.getPassword();
36 for (int i = 0; i<passarreglo.length; i++) {
37 char c = passarreglo[i];
38 if (!Character.isLetterOrDigit(c))
39 return false;
40 }
41
42 String pass=new String(passarreglo);
43
44 if (user.equals(doc[0]) && pass.equals(doc[1])) {
45 return true;
46 } else {
47 return false;
48 }
49 }
50
51 /** Initializes the applet Prueba */
52 public void init() {
53 try {
54 java.awt.EventQueue.invokeAndWait(new Runnable() {
55 public void run() {
56 initComponents();
57 }
58 });
59 } catch (Exception ex) {
60 ex.printStackTrace();
61 }
62 }
63
64
65
66 /** This method is called from within the init() method to
67 * initialize the form.
68 * WARNING: Do NOT modify this code. The content of this method is
69 * always regenerated by the Form Editor.
70 */
71 @SuppressWarnings("unchecked")
72 // <editor-fold defaultstate="collapsed" desc="Generated Code">
73 private void initComponents() {
74
75 panel1 = new java.awt.Panel();
76 jComboBox1 = new javax.swing.JComboBox();
77 list1 = new java.awt.List();
78 textArea1 = new java.awt.TextArea();
79 label1 = new java.awt.Label();
80 jButton1 = new javax.swing.JButton();
81 jLabel1 = new javax.swing.JLabel();
82 list2 = new java.awt.List();
83 jLabel2 = new javax.swing.JLabel();
84 jLabel3 = new javax.swing.JLabel();
85 jLabel4 = new javax.swing.JLabel();
86 jButton3 = new javax.swing.JButton();
87 jButton4 = new javax.swing.JButton();
88 jLabel5 = new javax.swing.JLabel();
89 button1 = new java.awt.Button();
90 list3 = new java.awt.List();
91 jInternalFrame1 = new javax.swing.JInternalFrame();
92 jTextField1 = new javax.swing.JTextField("@dominio.com");
93 jLabel6 = new javax.swing.JLabel();
94 jLabel7 = new javax.swing.JLabel();
95 jPasswordField1 = new javax.swing.JPasswordField();
96 jButton2 = new javax.swing.JButton();
97 jLabel8 = new javax.swing.JLabel();
98
99 javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
100 panel1.setLayout(panel1Layout);
101 panel1Layout.setHorizontalGroup(
102 panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
103 .addGap(0, 100, Short.MAX_VALUE)
104 );
105 panel1Layout.setVerticalGroup(
106 panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
107 .addGap(0, 100, Short.MAX_VALUE)
108 );
109
110 jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Accesorios", "Almacenamiento", "Bocinas", "Cables", "Cámaras", "Computadoras", "Diademas y Microfonos", "Energía", "Gabinetes", "Herramientas y Limpieza", "Impresoras", "Memorias", "Mochilas y Maletines", "Monitores", "Muebles para Oficina", "Procesadores", "Quemadoras", "Ratones", "Redes", "Scanners", "Seguridad", "Servicios/Reparaciones", "Servidores", "Software", "Tarjetas de Sonido", "Tarjetas Madre", "Teclados", "Televisiones", "Ventiladores", "Video", "Videojuegos", "VideoProyectores" }));
111 jComboBox1.addActionListener(new java.awt.event.ActionListener() {
112 public void actionPerformed(java.awt.event.ActionEvent evt) {
113 jComboBox1ActionPerformed(evt);
114 }
115 });
116
117 list1.addItemListener(new java.awt.event.ItemListener() {
118 public void itemStateChanged(java.awt.event.ItemEvent evt) {
119 list1ItemStateChanged(evt);
120 }
121 });
122
123 textArea1.setEditable(false);
124
125 label1.setText("Descripcion");
126
127 jButton1.setText("Agregar a la lista de compras");
128 jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
129 public void mouseClicked(java.awt.event.MouseEvent evt) {
130 jButton1MouseClicked(evt);
131 }
132 });
133
134 jLabel1.setText("Lista de compras");
135
136 jLabel2.setText("Total= $");
137
138 jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14));
139 jLabel4.setText("x");
140
141 jButton3.setFont(new java.awt.Font("Tahoma", 0, 14));
142 jButton3.setText("<");
143 jButton3.addActionListener(new java.awt.event.ActionListener() {
144 public void actionPerformed(java.awt.event.ActionEvent evt) {
145 jButton3ActionPerformed(evt);
146 }
147 });
148
149 jButton4.setFont(new java.awt.Font("Tahoma", 0, 14));
150 jButton4.setText(">");
151 jButton4.addActionListener(new java.awt.event.ActionListener() {
152 public void actionPerformed(java.awt.event.ActionEvent evt) {
153 jButton4ActionPerformed(evt);
154 }
155 });
156
157 jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14));
158 jLabel5.setText("1");
159
160 button1.setEnabled(false);
161 button1.setLabel("Eliminar");
162 button1.addMouseListener(new java.awt.event.MouseAdapter() {
163 public void mouseClicked(java.awt.event.MouseEvent evt) {
164 button1MouseClicked(evt);
165 }
166 });
167
168 list3.setEnabled(false);
169
170 jLabel6.setText("Ingrese sus datos para poder ingresar.");
171
172 jLabel7.setText("Contraseña");
173
174 jButton2.setText("Entrar");
175 jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
176 public void mouseClicked(java.awt.event.MouseEvent evt) {
177 jButton2MouseClicked(evt);
178 }
179 });
180
181 jLabel8.setText("Correo electronico");
182
183 javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
184 jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
185 jInternalFrame1Layout.setHorizontalGroup(
186 jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187 .addGroup(jInternalFrame1Layout.createSequentialGroup()
188 .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
189 .addGroup(jInternalFrame1Layout.createSequentialGroup()
190 .addGap(53, 53, 53)
191 .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192 .addComponent(jLabel8)
193 .addComponent(jLabel7)
194 .addComponent(jButton2))
195 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
196 .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
197 .addComponent(jPasswordField1, 0, 0, Short.MAX_VALUE)
198 .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)))
199 .addGroup(jInternalFrame1Layout.createSequentialGroup()
200 .addGap(43, 43, 43)
201 .addComponent(jLabel6)))
202 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
203 );
204 jInternalFrame1Layout.setVerticalGroup(
205 jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
206 .addGroup(jInternalFrame1Layout.createSequentialGroup()
207 .addGap(25, 25, 25)
208 .addComponent(jLabel6)
209 .addGap(31, 31, 31)
210 .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
211 .addComponent(jLabel8)
212 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
213 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
214 .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
215 .addComponent(jLabel7)
216 .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
217 .addGap(18, 18, 18)
218 .addComponent(jButton2)
219 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
220 );
221
222 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
223 getContentPane().setLayout(layout);
224 layout.setHorizontalGroup(
225 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226 .addGroup(layout.createSequentialGroup()
227 .addContainerGap()
228 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229 .addGroup(layout.createSequentialGroup()
230 .addComponent(jButton1)
231 .addGap(18, 18, 18)
232 .addComponent(jLabel4)
233 .addGap(28, 28, 28)
234 .addComponent(jButton3)
235 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
236 .addComponent(jLabel5)
237 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
238 .addComponent(jButton4))
239 .addGroup(layout.createSequentialGroup()
240 .addComponent(jLabel2)
241 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
242 .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
243 .addGroup(layout.createSequentialGroup()
244 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
245 .addComponent(jLabel1)
246 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
247 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
248 .addGroup(layout.createSequentialGroup()
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 .addGroup(layout.createSequentialGroup()
251 .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
252 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 301, Short.MAX_VALUE))
253 .addGroup(layout.createSequentialGroup()
254 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
255 .addGroup(layout.createSequentialGroup()
256 .addComponent(list2, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
257 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 49, Short.MAX_VALUE)
258 .addComponent(list3, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
259 .addComponent(textArea1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
260 .addComponent(list1, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))
261 .addGap(113, 113, 113)))
262 .addGap(106, 106, 106)))
263 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
264 .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)))
265 .addContainerGap())
266 );
267 layout.setVerticalGroup(
268 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269 .addGroup(layout.createSequentialGroup()
270 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271 .addGroup(layout.createSequentialGroup()
272 .addGap(21, 21, 21)
273 .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
275 .addComponent(list1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
276 .addGap(18, 18, 18)
277 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
278 .addComponent(jButton1)
279 .addComponent(jLabel4)
280 .addComponent(jButton3)
281 .addComponent(jLabel5)
282 .addComponent(jButton4))
283 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
284 .addComponent(label1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
285 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
286 .addComponent(textArea1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
287 .addGap(20, 20, 20)
288 .addComponent(jLabel1)
289 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
290 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
291 .addComponent(list3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
292 .addComponent(list2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
293 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
294 .addComponent(button1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
296 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
297 .addComponent(jLabel2)
298 .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
299 .addGroup(layout.createSequentialGroup()
300 .addGap(404, 404, 404)
301 .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)))
302 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
303 );
304 }// </editor-fold>
305
306 private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
307
308 try {
309
310 a=0;
311 BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\Jose\\Documents\\NetBeansProjects\\appleet\\Usuarios\\"+jTextField1.getText()+"\\"+"contraseña.txt"));
312 String texto = "";
313 while((texto= reader.readLine())!= null){
314 doc[a]=texto;
315 a++;
316 }
317 System.out.print(doc[0]);
318 System.out.print(doc[1]);
319 reader.close();
320 } catch (IOException e) {
321 a=0;
322 }
323
324
325
326 if (comprobar()) {
327 JOptionPane.showMessageDialog(
328 this, "Bienvenido");
329 } else {
330 JOptionPane.showMessageDialog(
331 this, "Usuario o pass no valido");
332 }
333
334
335 }
336
337 private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
338 list1.clear();
339 String seleccion= (String) jComboBox1.getSelectedItem();
340 try{
341 String texto="";
342 BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\Jose\\Documents\\NetBeansProjects\\appleet\\Categorias\\"+seleccion+".txt"));
343 while(( texto= br.readLine())!= null){
344 list1.add(texto);
345 }}
346
347 catch(IOException ioe){}
348 }
349
350 private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
351
352 String seleccion2= (String) jComboBox1.getSelectedItem();
353 String seleccion= list1.getSelectedItem();
354
355
356
357 try{
358 String ultimo="";String precio="";
359 BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\Jose\\Documents\\NetBeansProjects\\appleet\\Descripciones\\"+seleccion2+"\\descripcion "+seleccion+".txt"));
360 while (ultimo != null) {
361 precio = ultimo;
362 ultimo = br.readLine();
363 }br.close();
364 list2.add(seleccion+"("+c+")");
365
366 resta=Double.parseDouble(precio)*c;
367 list3.add(String.valueOf(resta));
368
369 resultado=(Double.parseDouble(precio)*c)+resultado;
370 jLabel3.setText(String.valueOf(resultado));
371 }catch(IOException ioe){}
372
373 c=1;
374 jLabel5.setText(String.valueOf(c));
375 button1.setEnabled(true);
376 }
377
378 private void button1MouseClicked(java.awt.event.MouseEvent evt) {
379 int seleccion= list2.getSelectedIndex();
380 int num=list2.getItemCount();
381
382 if((list2.getSelectedItem()!=null)&&(num!=0)){
383 resultado=resultado-Double.parseDouble(list3.getItem(seleccion));
384 list2.delItem(seleccion);
385
386 list3.delItem(seleccion);
387
388
389 jLabel3.setText(String.valueOf(resultado));
390
391 } else {
392 JOptionPane.showMessageDialog(rootPane, "Seleccione un articulo para eliminar");
393 }
394 }
395
396 private void list1ItemStateChanged(java.awt.event.ItemEvent evt) {
397 textArea1.setText("");
398 String seleccion= list1.getSelectedItem();
399 String seleccion2= (String) jComboBox1.getSelectedItem();
400 String descripcion="";
401 try{
402 String texto="";
403 BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\Jose\\Documents\\NetBeansProjects\\appleet\\Descripciones\\"+seleccion2+"\\descripcion "+seleccion+".txt"));
404 while(( texto= br.readLine())!= null){
405 descripcion=descripcion+"\n"+texto;
406 }} catch(IOException ioe){}
407 textArea1.setText( descripcion);
408 }
409
410 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
411 c--;
412 if(c!=0){
413 jLabel5.setText(String.valueOf(c));
414 } else{
415 c=1;
416 jLabel5.setText(String.valueOf(c));
417 jButton3.setEnabled(false);
418
419 }
420 }
421
422 private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
423 jButton3.setEnabled(true);
424 c++;
425 jLabel5.setText(String.valueOf(c));
426 }
427
428 double resultado=0;
429 int i=0,c=1;
430 double resta= 0;
431 int a=0;
432 String []doc=new String[2];
433
434 // Variables declaration - do not modify
435 private java.awt.Button button1;
436 private javax.swing.JButton jButton1;
437 private javax.swing.JButton jButton2;
438 private javax.swing.JButton jButton3;
439 private javax.swing.JButton jButton4;
440 private javax.swing.JComboBox jComboBox1;
441 private javax.swing.JInternalFrame jInternalFrame1;
442 private javax.swing.JLabel jLabel1;
443 private javax.swing.JLabel jLabel2;
444 private javax.swing.JLabel jLabel3;
445 private javax.swing.JLabel jLabel4;
446 private javax.swing.JLabel jLabel5;
447 private javax.swing.JLabel jLabel6;
448 private javax.swing.JLabel jLabel7;
449 private javax.swing.JLabel jLabel8;
450 private javax.swing.JPasswordField jPasswordField1;
451 private javax.swing.JTextField jTextField1;
452 private java.awt.Label label1;
453 private java.awt.List list1;
454 private java.awt.List list2;
455 private java.awt.List list3;
456 private java.awt.Panel panel1;
457 private java.awt.TextArea textArea1;
458 // End of variables declaration
459 }
460
461