MDI Java, Equipo #3

24
Control MDI Catedra: Programación Orientada a Objetos Catedrático: Ing. Oscar Pineda Integrantes: Francy Marcela Barahona Héctor José Rivera Alfonzo Vaquedano Choluteca, Choluteca 19 de noviembre del 2013

Transcript of MDI Java, Equipo #3

  • Control MDI

    Catedra:

    Programacin Orientada a Objetos

    Catedrtico:

    Ing. Oscar Pineda

    Integrantes:

    Francy Marcela Barahona

    Hctor Jos Rivera

    Alfonzo Vaquedano

    Choluteca, Choluteca 19 de noviembre del 2013

  • A continuacin hablaremos sobre la Interfaz Mltiple de Usuarios (MDI) en

    Java.

    El formulario MDI es bsicamente un contenedor de ventanas, en el cual

    podemos tener varias ventanas abiertas pero que pertenecen al escritorio

    virtual del MDI el cual es llamado Desktop Pane, estas ventanas son los

    frames internos o Internal Frames.

    Un ejemplo de MDI puede ser el programa de edicin grfica Photoshop, en el

    cual podemos tener abiertas varias imgenes para su edicin, teniendo en

    cuenta que dichas imgenes se abren en ventanas individuales que pertenecen

    al Desktop Pane.

  • Interfaz de Mltiples Documentos (MDI)

    Las Aplicaciones MDI (Interfaz de Mltiples Documentos) permiten mostrar

    varios documentos al mismo tiempo, cada uno de ellos en su propia ventana.

    Las aplicaciones MDI suelen tener un elemento de men Ventana con

    submens que permiten cambiar entre ventanas o documentos.

    Para crear Frames internos, tambin conocidos como "formularios MDI"

    (Interfaz de Mltiples Documentos) en NetBeans, debemos hacer uso de los

    objetos JInternalFrame lo cual veremos a continuacin.

    1) Requisitos

    a. NetBeans

    2) Creacin de un men principal (MDI)

    a. Primero crearemos un packages con el nombre de MENU.

    b. De acuerdo a nuestro programa NetBeans vamos a pasar a crear un

    Formulario de Interfaz Grfica MDI.

  • c. Luego que hemos seleccionado OTRO, nos dirigimos a la opcin

    Formulario de Interfaz Grfica de Swing /Formulario de muestra de

    Aplicacin MDI.

    d. Una vez seleccionado Formulario de muestra de Aplicacin MDI, le damos

    Siguiente, y luego escribiremos el nombre de nuestro formulario y por ultimo

    le damos clic en Terminar.

  • e. Cuando creamos un formulario MDI, por defecto nos muestra en siguiente

    diseo y men.

  • f. Modificamos nuestros MenuItem del Menu File(en lugar de open colocamos

    Ingresos y en lugar de Save, colocamos Consultas), para que nos quede de la

    siguiente forma.

    g. Una vez realizado esto, procederemos a crear nuestros formularios hijos

    (JInternalFrame Form).Clic derecho en nuestro proyecto/ Nuevo/Otro -

    JInternalFrame Form/Siguiente.

  • h. Colocamos de nombre "Ingresos" y clic en Terminar. Hacemos lo mismo

    para crear un segundo formulario .Para luego llamar desde nuestro formulario

    principal a nuestros formularios hijos. Vamos a hacer un pequeo diseo tanto

    en nuestro formulario. Como se muestra

    i. Ahora vamos a llamar desde nuestro formulario principal a nuestros

    formularios hijos. Clic derecho en nuestro Men tem llamado

  • Ingresos/Eventos/ Action/ actionPerformed. Esto nos llevara a la parte de

    cdigo de nuestro formulario principal.

    j. Estando dentro del evento de nuestro formulario, escribimos lo siguiente:

    Y hacemos lo mismo para llamar a los dems formularios.

    k. Para activar el cerrar, minimizar y maximizar de los formularios hijos,

    activar las siguientes opciones.

  • l. Volvemos a ejecutar y nos mostrara:

    Entonces nuestra interfaz estara culminado.

  • CDIGO EJERCICIO #1

    Cdigo de la clase MDI Principal:

    public class MDIPrincipal extends javax.swing.JFrame

    {

    public MDIPrincipal() {

    initComponents();

    }

    @SuppressWarnings("unchecked")

    private void initComponents() {

    private void

    jInternalCalcActionPerformed(java.awt.event.ActionEv

    ent evt) {

    jInternal1 calculadora = new jInternal1();

    desktopPane.add(calculadora);

    calculadora.show();

    calculadora.setClosable(true);

    calculadora.setMaximizable(true);

    calculadora.setLocation(500, 100);

    }

  • private void

    jCheckBoxMenuItem1ActionPerformed(java.awt.event.Act

    ionEvent evt) {

    System.exit(0);

    }

    public static void main(String args[]) {

    java.awt.EventQueue.invokeLater(new

    Runnable() {

    public void run() {

    new MDIPrincipal().setVisible(true);

    }

    });

    }

    // Variables declaration - do not modify

    private javax.swing.JDesktopPane desktopPane;

    private javax.swing.JMenu fileMenu;

    private javax.swing.JCheckBoxMenuItem

    jCheckBoxMenuItem1;

    private javax.swing.JCheckBoxMenuItem

    jInternalCalc;

    private javax.swing.JMenuBar menuBar;

    // End of variables declaration

    }

  • Cdigo del Internal Frame:

    /*

    * To change this template, choose Tools | Templates

    * and open the template in the editor.

    */

    /**

    *

    * @author Hector Rivera

    */

    public class jInternal1 extends

    javax.swing.JInternalFrame {

    /**

    * Creates new form jInternal1

    */

    public jInternal1() {

    initComponents();

    }

    /**

    * This method is called from within the

    constructor to initialize the form.

    * WARNING: Do NOT modify this code. The content

    of this method is always

    * regenerated by the Form Editor.

  • */

    @SuppressWarnings("unchecked")

    //

    private void initComponents() {

    jTFN1 = new javax.swing.JTextField();

    jTFN2 = new javax.swing.JTextField();

    jBTCalcular = new javax.swing.JButton();

    jLabel1 = new javax.swing.JLabel();

    jLabel2 = new javax.swing.JLabel();

    jTFSuma = new javax.swing.JTextField();

    jLabel3 = new javax.swing.JLabel();

    jBTCalcular.setText("Calcular");

    jBTCalcular.addActionListener(new

    java.awt.event.ActionListener() {

    public void

    actionPerformed(java.awt.event.ActionEvent evt) {

    jBTCalcularActionPerformed(evt);

    }

    });

    jLabel1.setText("Numero 1:");

    jLabel2.setText("Numero 2:");

  • jLabel3.setText("Resultado:");

    javax.swing.GroupLayout layout = new

    javax.swing.GroupLayout(getContentPane());

    getContentPane().setLayout(layout);

    layout.setHorizontalGroup(

    layout.createParallelGroup(javax.swing.GroupLayout.A

    lignment.LEADING)

    .addGroup(layout.createSequentialGroup()

    .addGap(153, 153, 153)

    .addComponent(jBTCalcular)

    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZ

    E, Short.MAX_VALUE))

    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING

    , layout.createSequentialGroup()

    .addContainerGap(103,

    Short.MAX_VALUE)

    .addGroup(layout.createParallelGroup(javax.swing.Gro

    upLayout.Alignment.LEADING)

    .addComponent(jLabel1)

    .addComponent(jLabel2)

    .addComponent(jLabel3))

    .addGap(35, 35, 35)

    .addGroup(layout.createParallelGroup(javax.swing.Gro

    upLayout.Alignment.LEADING, false)

  • .addComponent(jTFSuma,

    javax.swing.GroupLayout.DEFAULT_SIZE, 69,

    Short.MAX_VALUE)

    .addComponent(jTFN1)

    .addComponent(jTFN2))

    .addGap(135, 135, 135))

    );

    layout.setVerticalGroup(

    layout.createParallelGroup(javax.swing.GroupLayout.A

    lignment.LEADING)

    .addGroup(layout.createSequentialGroup()

    .addGap(63, 63, 63)

    .addGroup(layout.createParallelGroup(javax.swing.Gro

    upLayout.Alignment.BASELINE)

    .addComponent(jTFN1,

    javax.swing.GroupLayout.PREFERRED_SIZE,

    javax.swing.GroupLayout.DEFAULT_SIZE,

    javax.swing.GroupLayout.PREFERRED_SIZE)

    .addComponent(jLabel1))

    .addGap(37, 37, 37)

    .addGroup(layout.createParallelGroup(javax.swing.Gro

    upLayout.Alignment.BASELINE)

    .addComponent(jTFN2,

    javax.swing.GroupLayout.PREFERRED_SIZE,

    javax.swing.GroupLayout.DEFAULT_SIZE,

    javax.swing.GroupLayout.PREFERRED_SIZE)

    .addComponent(jLabel2))

  • .addPreferredGap(javax.swing.LayoutStyle.ComponentPl

    acement.RELATED, 29, Short.MAX_VALUE)

    .addGroup(layout.createParallelGroup(javax.swing.Gro

    upLayout.Alignment.BASELINE)

    .addComponent(jTFSuma,

    javax.swing.GroupLayout.PREFERRED_SIZE,

    javax.swing.GroupLayout.DEFAULT_SIZE,

    javax.swing.GroupLayout.PREFERRED_SIZE)

    .addComponent(jLabel3))

    .addPreferredGap(javax.swing.LayoutStyle.ComponentPl

    acement.UNRELATED)

    .addComponent(jBTCalcular)

    .addGap(55, 55, 55))

    );

    pack();

    }//

    private void

    jBTCalcularActionPerformed(java.awt.event.ActionEven

    t evt) {

    // TODO add your handling code here:

    double n1, n2, suma;

    n1 =

    Double.parseDouble(this.jTFN1.getText());

  • n2 =

    Double.parseDouble(this.jTFN2.getText());

    suma = n1 + n2;

    this.jTFSuma.setText(String.valueOf(suma));

    }

    // Variables declaration - do not modify

    private javax.swing.JButton jBTCalcular;

    private javax.swing.JLabel jLabel1;

    private javax.swing.JLabel jLabel2;

    private javax.swing.JLabel jLabel3;

    private javax.swing.JTextField jTFN1;

    private javax.swing.JTextField jTFN2;

    private javax.swing.JTextField jTFSuma;

    // End of variables declaration

    }

    EJERCICIO #2

    Cdigo de la clase MDI:

    public class ForMdi1 extends javax.swing.JFrame {

    /**

    * Creates new form ForMdi1

    */

    public ForMdi1() {

  • initComponents();

    }

    /**

    * This method is called from within the

    constructor to initialize the form.

    * WARNING: Do NOT modify this code. The content

    of this method is always

    * regenerated by the Form Editor.

    */

    @SuppressWarnings("unchecked")

    //

    private void initComponents() {

    desktopPane = new

    javax.swing.JDesktopPane();

    menuBar = new javax.swing.JMenuBar();

    jMenu1 = new javax.swing.JMenu();

    jMenuItem1 = new javax.swing.JMenuItem();

    jMenuItem2 = new javax.swing.JMenuItem();

    jMenu2 = new javax.swing.JMenu();

    jMenuItem3 = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants

    .EXIT_ON_CLOSE);

  • menuBar.setBackground(new java.awt.Color(51,

    51, 255));

    jMenu1.setText("Archivo");

    jMenuItem1.setText("Calculadora");

    jMenuItem1.addActionListener(new

    java.awt.event.ActionListener() {

    public void

    actionPerformed(java.awt.event.ActionEvent evt) {

    jMenuItem1ActionPerformed(evt);

    }

    });

    jMenu1.add(jMenuItem1);

    jMenuItem2.setText("Imagen");

    jMenuItem2.addActionListener(new

    java.awt.event.ActionListener() {

    public void

    actionPerformed(java.awt.event.ActionEvent evt) {

    jMenuItem2ActionPerformed(evt);

    }

    });

    jMenu1.add(jMenuItem2);

    menuBar.add(jMenu1);

  • jMenu2.setText("Salir");

    jMenuItem3.setText("Salir");

    jMenuItem3.addActionListener(new

    java.awt.event.ActionListener() {

    public void

    actionPerformed(java.awt.event.ActionEvent evt) {

    jMenuItem3ActionPerformed(evt);

    }

    });

    jMenu2.add(jMenuItem3);

    menuBar.add(jMenu2);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new

    javax.swing.GroupLayout(getContentPane());

    getContentPane().setLayout(layout);

    layout.setHorizontalGroup(

    layout.createParallelGroup(javax.swing.GroupLayout.A

    lignment.LEADING)

    .addComponent(desktopPane,

    javax.swing.GroupLayout.DEFAULT_SIZE, 400,

    Short.MAX_VALUE)

    );

    layout.setVerticalGroup(

  • layout.createParallelGroup(javax.swing.GroupLayout.A

    lignment.LEADING)

    .addComponent(desktopPane,

    javax.swing.GroupLayout.DEFAULT_SIZE, 279,

    Short.MAX_VALUE)

    );

    pack();

    }//

    private void

    jMenuItem2ActionPerformed(java.awt.event.ActionEvent

    evt) {

    // TODO add your handling code here:

    FormHijo1 fh1 = new FormHijo1();

    desktopPane.add(fh1);

    fh1.show();

    }

    private void

    jMenuItem3ActionPerformed(java.awt.event.ActionEvent

    evt) {

    // TODO add your handling code here:

    System.exit(0);

    }

  • private void

    jMenuItem1ActionPerformed(java.awt.event.ActionEvent

    evt) {

    // TODO add your handling code here:

    FormHijo2 fh2 = new FormHijo2();

    desktopPane.add(fh2);

    fh2.show();

    }

    /**

    * @param args the command line arguments

    */

    public static void main(String args[]) {

    /* Set the Nimbus look and feel */

    //

    /* If Nimbus (introduced in Java SE 6) is

    not available, stay with the default look and feel.

    * For details see

    http://download.oracle.com/javase/tutorial/uiswing/l

    ookandfeel/plaf.html

    */

    try {

    for

    (javax.swing.UIManager.LookAndFeelInfo info :

    javax.swing.UIManager.getInstalledLookAndFeels()) {

  • if ("Nimbus".equals(info.getName()))

    {

    javax.swing.UIManager.setLookAndFeel(info.getClassNa

    me());

    break;

    }

    }

    } catch (ClassNotFoundException ex) {

    java.util.logging.Logger.getLogger(ForMdi1.class.get

    Name()).log(java.util.logging.Level.SEVERE, null,

    ex);

    } catch (InstantiationException ex) {

    java.util.logging.Logger.getLogger(ForMdi1.class.get

    Name()).log(java.util.logging.Level.SEVERE, null,

    ex);

    } catch (IllegalAccessException ex) {

    java.util.logging.Logger.getLogger(ForMdi1.class.get

    Name()).log(java.util.logging.Level.SEVERE, null,

    ex);

    } catch

    (javax.swing.UnsupportedLookAndFeelException ex) {

    java.util.logging.Logger.getLogger(ForMdi1.class.get

    Name()).log(java.util.logging.Level.SEVERE, null,

    ex);

    }

    //

  • /* Create and display the form */

    java.awt.EventQueue.invokeLater(new

    Runnable() {

    public void run() {

    new ForMdi1().setVisible(true);

    }

    });

    }

    // Variables declaration - do not modify

    private javax.swing.JDesktopPane desktopPane;

    private javax.swing.JMenu jMenu1;

    private javax.swing.JMenu jMenu2;

    private javax.swing.JMenuItem jMenuItem1;

    private javax.swing.JMenuItem jMenuItem2;

    private javax.swing.JMenuItem jMenuItem3;

    private javax.swing.JMenuBar menuBar;

    // End of variables declaration

    }

    Cdigo del Internal Frame: