Seguidores

MIS WEBS



martes, 3 de abril de 2018

Ejercicio con Layout Libre parte 5



CREAR TIPOS DE JOptionPane CON JAVA


¿Que hemos hecho en anteriores practicas del ejercicio?


En anteriores partes delejercicio creamos diferentes láminas y las pusimos a la escucha, cada una de las laminas y en concreto los JRadioButonJButton,JComboBox serán llamadas como objeto desde la lámina principal que utilizamos como nexo de unión. 

¿Que vamos a hacer ahora?



Una vez llamados los objetos  utilizaremos el método getActionCommand() para saber el comando seleccionados y valoráremos con un  if poder crear los diferentes tipos de mensaje.

  1. JOptionPane.showImputDialog
  1. JOptionPane.showMessageDialog
  1. JOptionPane.showConfirmDialog
  1. JOptionPane.ShowOptionDialog
Le pasaremos a cada uno de los constructores JOptionPane las diferentes variables previamente guardada para que según que comando haya pulsado el usuario cree un tipo de mensaje u otro.







class Marco_practicaCreadorDeMensajes extends JFrame {
      
       public Marco_practicaCreadorDeMensajes() {
            
             setTitle("CREADOR DE MENSAJES");
            
              PRINCIPAL = new Lamina_PrincipaldelMarco();
                     TipoBotones = new Lamina_TipoMensaje();
                     Seleccion = new Lamina_IconoSleccionado();
                     Confirmacion = new Lamina_TipoMensajeConfirmacion();
                     Menu = new Lamina_Menu_Superior();
                     BotonesAccion = new L_bott_creaMarcos();
            
             PRINCIPAL.setLayout(null);

//PONEMOS A LA ESCUCHA DEL EVENTO OYENTE RATÓN LAS LAMINAS DONDE LE INDICAMOS QUE AL HACER CLIC EN UNA LAMINA ESTA CAMBIE DE TAMAÑO//


                           TipoBotones.addMouseMotionListener(new oyente_raton());
                           Seleccion.addMouseMotionListener(new oyente_raton());
                           Confirmacion.addMouseListener(new oyente_raton());
                           BotonesAccion.addMouseListener(new oyente_raton());
                           TipoBotones.addMouseListener(new oyente_raton());
                           Seleccion.addMouseListener(new oyente_raton());
                           Confirmacion.addMouseListener(new oyente_raton());
                           BotonesAccion.addMouseListener(new oyente_raton());
                    PRINCIPAL.add(Menu);
                    PRINCIPAL.add(TipoBotones);
                    PRINCIPAL.add(Seleccion);
                    PRINCIPAL.add(Confirmacion);
                    PRINCIPAL.add(BotonesAccion);

/*utilizamos la nomenclatura del punto para poner a la escucha todos los objetos de las diferentes láminas.*/

                   
                  BotonesAccion.CrearMesaje.addActionListener(new elquetodoloescucha());
                  BotonesAccion.Cancelar.addActionListener(new elquetodoloescucha());
                  Seleccion.PORDEFECTO.addActionListener(new elquetodoloescucha());
                  Seleccion.SICANCELAR.addActionListener(new elquetodoloescucha());
                  Seleccion.SiNO.addActionListener(new elquetodoloescucha());
                  Seleccion.SINOCANCELAR.addActionListener(new elquetodoloescucha());
                  Confirmacion.ERROR.addActionListener(new elquetodoloescucha());
                  Confirmacion.NA.addActionListener(new elquetodoloescucha());
                  Confirmacion.PELIGRO.addActionListener(new elquetodoloescucha());
                  Confirmacion.INFORMACION.addActionListener(new elquetodoloescucha());
                  Confirmacion.PREGUNTA.addActionListener(new elquetodoloescucha());
                           //para poner a la escucha un item del comboTipoMensaje
                           TipoBotones.comboTipoMensaje.addItemListener(new elquetodoloescucha());
                          
                   
             add(PRINCIPAL);
            
            
       }
        private String String_TipMen;
        private int INT_tipMensaConr,Int_botDeJOption;
        private String NombesBotones[];
        
       class elquetodoloescucha implements ActionListener,ItemListener{



             public void actionPerformed(ActionEvent e2) {
                   
                    System.out.println(e2.getActionCommand());
            


/* UTILIZAREMOS UN IF EL DATO OBTENIDO POR EL COMANDO SELECCIONADO (getActionCommand()) PARA IR GUARDANDO EN CADA VARIABLE EL DATO DESEADO CADA VEZ QUE EL USUARIO ACCIONE UN COMANDO DE UNA DE LAS  LÁMINAS */ 

                   
      if           (      e2.getActionCommand()=="SI / NO") {Int_botDeJOption = 0;
}else if     (      e2.getActionCommand()=="SI / CANCELAR") {Int_botDeJOption = 1;
}else if     (      e2.getActionCommand()=="SI / NO / CANCELAR" ) {Int_botDeJOption = 2;
}else if     (e2.getActionCommand()=="ESTANDAR"Int_botDeJOption=JOptionPane.YES_OPTION;
                           /*•    Si ponemos 0 nos cargarán dos botones si/no
                                 Si ponemos 1 nos cargarán tres botones si/no/cancelar
                                 Si ponemos 2 apareceran dos botones aceptar/cancelar */
                   
                    }else if (e2.getActionCommand()=="ERROR") {                                                         INT_tipMensaConr=0;
                    }else if (e2.getActionCommand()=="INFORMACION") {                                                  INT_tipMensaConr=1;
                    }else if (e2.getActionCommand()=="PILIGRO") {                                                      INT_tipMensaConr=2;
                    }else if (e2.getActionCommand()=="PREGUNTA") {                                                      INT_tipMensaConr=3;
                    }else if (e2.getActionCommand()=="N/A") {                                                          INT_tipMensaConr=-1;
                    }
                                                     

   /*CUANDO TOQUEN EL BOTÓN ACEPTAR VALORARÁ LOS DATOS GUARDADOS PREVIAMENTE EN LAS VARIABLES Y CREARÁ UN TIPO U OTRO DE JOptionPane*/

                   
                    if (e2.getActionCommand() == "CREARMENSAJE" ) {

       if (String_TipMen == "MENSAJE AVISO") {
   JOptionPane.showMessageDialog(PRINCIPAL, "Mensaje", "JOtionPane",INT_tipMensaConr);

 }else if(String_TipMen == "MENSAJE DE ENTRADA DATOS") {
JOptionPane.showInputDialog(PRINCIPAL, "Mensaje", "JOtionPane",INT_tipMensaConr);

}else if(String_TipMen == "MENSAJE CONFIRMACION") {
 JOptionPane.showConfirmDialog(PRINCIPAL, "Mensaje", "JOtionPane",Int_botDeJOption ,INT_tipMensaConr);
}else if(String_TipMen == "MENSAJE OPCIONES") {
JOptionPane.showOptionDialog(PRINCIPAL, "Mensaje", "JOtionPane",Int_botDeJOption ,INT_tipMensaConr, new ImageIcon (""),new String[]{"1","2"},1);
                        }
                    }
             }
             public void itemStateChanged(ItemEvent e) {
                   
                    // ********  primero tenemos que escojer entre los dos que nos regeresa el Selecionado   **********  //////
            
                   
                     if(e.getStateChange() == ItemEvent.SELECTED){
                            
                            String_TipMen = (String) e.getItem();
                            System.out.println(String_TipMen);
                            
                            
                            
                     }    




                                                                                                                    


No hay comentarios:

Publicar un comentario

Buscar este blog

Sandisk y Western Digital