mostrar otra ventana

2
Mostrar otra ventana (JDialog) al pulsar botón. Usando Netbeans7.0 se agregan en el nuevo proyecto dos ventanas. La ventana princ tipo jFrame con un boton dentro y la ventana secundaria de tipo jDialog. Ventana principal (JFrame): package dosventanas; public class ventanaPrincipal extends javax.swing.JFrame { public ventanaPrincipal() { initComponents(); !"uppress#arnings($unc%ecked$) & 'enerated Code *ui va codigo generado por +etbeans (ventana , boton). private void -oton ostrarJ/ialog0 ctionPer1ormed(java.awt.event. ction2vent evt) { new ventana2(this, true).setVisible(true); public static void main("tring args34) { java.awt.2vent5ueue.invoke6ater(new 7unnable() { public void run() { new ventanaPrincipal().set8isible(true); ); 8ariables declaration 9 do not modi1, private javax.swing.J-utton -oton ostrarJ/ialog0; 2nd o1 variables declaration Ventana secundaria (JDialog): package dosventanas; public class ventana: extends javax.swing.J/ialog { public ventana:(java.awt.Frame parent boolean modal) { super(parent modal); initComponents(); !"uppress#arnings($unc%ecked$) & 'enerated code *ui va codigo generado por +etbeans (ventana:) public static void main("tring args34) { java.awt.2vent5ueue.invoke6ater(new 7unnable() { public void run() { ventana: dialog < new ventana:(new javax.swing.JFrame() true); dialog.add#indow6istener(new java.awt.event.#indow dapter() { public void windowClosing(java.awt.event.#indow2vent e) { ",stem.exit(=); ); dialog.set8isible(true); ); 8ariables declaration 9 do not modi1, 2nd o1 variables declaration

Upload: waltza

Post on 05-Oct-2015

215 views

Category:

Documents


0 download

DESCRIPTION

Java Frames

TRANSCRIPT

Mostrar otra ventana (JDialog) al pulsar botn.

Usando Netbeans7.0 se agregan en el nuevo proyecto dos ventanas. La ventana principal tipo jFrame con un boton dentro y la ventana secundaria de tipo jDialog.

Ventana principal (JFrame):package dosventanas;public class ventanaPrincipal extends javax.swing.JFrame {public ventanaPrincipal() {initComponents();}@SuppressWarnings("unchecked")+ Generated Code //Aqui va codigo generado por Netbeans (ventana y boton).

private void BotonMostrarJDialog1ActionPerformed(java.awt.event.ActionEvent evt) {new ventana2(this, true).setVisible(true);}

public static void main(String args[]) {java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {new ventanaPrincipal().setVisible(true);}});}// Variables declaration - do not modifyprivate javax.swing.JButton BotonMostrarJDialog1;// End of variables declaration}

Ventana secundaria (JDialog):package dosventanas;public class ventana2 extends javax.swing.JDialog {public ventana2(java.awt.Frame parent, boolean modal) {super(parent, modal);initComponents();}

@SuppressWarnings("unchecked")+ Generated code //Aqui va codigo generado por Netbeans (ventana2)

public static void main(String args[]) {java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {ventana2 dialog = new ventana2(new javax.swing.JFrame(), true);dialog.addWindowListener(new java.awt.event.WindowAdapter() {

public void windowClosing(java.awt.event.WindowEvent e) {System.exit(0);}});dialog.setVisible(true);}});}// Variables declaration - do not modify// End of variables declaration}

Resultado: Nota1: En este ejemplo la ventana principal queda inhabilitada hasta que no se cierre la ventana secundaria (jDialog). Las ventanas de tipo jDialog tienen la pecurialidad de que al abrirse bloquean el resto (por seguridad).

Nota2: En netbeans7.0 (por defecto) no aparece en la lista el paquete "jDialog Form". Para ello, clic con botn izquierdo sobre icono paquete del proyecto y en el menu que aparece seguir el siguiente camino:- New - Other - Swing GUI FORMS - jDialog form. [Next] -