Foros del Web » Programación para mayores de 30 ;) » Java »

como saco un dialogo desde un menu

Estas en el tema de como saco un dialogo desde un menu en el foro de Java en Foros del Web. Hola tengo un programita donde eligo tres sistema operativo que son win98,winxp y linux con un boton yo voy eligiendo el sistema operativo ok lo ...
  #1 (permalink)  
Antiguo 20/01/2006, 13:37
 
Fecha de Ingreso: febrero-2005
Mensajes: 867
Antigüedad: 19 años, 3 meses
Puntos: 3
Información como saco un dialogo desde un menu

Hola tengo un programita donde eligo tres sistema operativo que son

win98,winxp y linux con un boton yo voy eligiendo el sistema operativo ok lo que necesito hacer es en un menu tengo el item INFO cuando le doy a INFO debe de salirme un dialogo con la cantida de veces que se selecciono un sistema operativo osea en el diablogo debe de aparecer esto

window 98 -> 10
window xp -> 5
Linux -> 2

por lo pronto el codigo donde llama el dialogo es este

if(e.getSource() == m2Item1)
{
dialogo2 j2 = new dialogo2(this,Win98,WinXP,Linux);
j2.setBounds(100,100,400,200);
j2.show();

}

pero no se que poner donde en la class,,,,,,,, donde llama a dialogo2

alguna opinion
  #2 (permalink)  
Antiguo 20/01/2006, 14:38
Avatar de dogduck  
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 18 años, 4 meses
Puntos: 19
Se supone que dialogo2 es una clase , y por lo que veo del código , yo lo traduciria:

Si el método Obten Fuente de el objeto e coincide con el objeto m2Item1 entonces
{
Se crea el objeto j2 de la clase dialogo2 y se construye con los argumentos: la propia clase, el objeto Win98 , el objeto WinXP y el objeto linux;
A el objeto j2 le asigno unas dimensiones ...;
Muestro el objeto j2 ( show esta deprecated , se suele usar setVisible(true));
}

Yo por lo menos no me aclaro , me faltan datos ... ¿que clase instancia el objeto e? , ¿que clase es dialogo2?¿ De que contenedor hereda ?....
  #3 (permalink)  
Antiguo 20/01/2006, 16:43
 
Fecha de Ingreso: febrero-2005
Mensajes: 867
Antigüedad: 19 años, 3 meses
Puntos: 3
quieres que te tipe el codigo no tengo problema por lo pronto

el dialogo2 lo hereda de una segunda archivo.java que es lo que no se armar

te doy detalle
  #4 (permalink)  
Antiguo 20/01/2006, 16:48
 
Fecha de Ingreso: febrero-2005
Mensajes: 867
Antigüedad: 19 años, 3 meses
Puntos: 3
yo tengo esta aplicacion

class Aplicacion1 extends Frame implements ActionListener, ItemListener {
Label label1;
Label label2;
Label label3;
Label label4;
Label label5;
Label label6;
Label label7;
Label label8;
Label label9;
Label label10;
Label nroTel;
TextField textfield1;
TextField textfield2;
Choice choice1;
Choice choice2;
Button button1;
Button button2;
MenuBar mb;
Menu m;
MenuItem mi;

Aplicacion1 ()
{
setLayout (null);
mb = new MenuBar ();
setMenuBar (mb);

m = new Menu ("Opciones");
mb.add (m);

mi = new MenuItem ("Acerca de...");
mi.addActionListener (this);
m.add (mi);

//setBackground(Color.yellow);

label1 = new Label ("Usuario");
label1.setBounds (24, 52, 91, 10); //24,32,91,10

label2 = new Label ("Clave");
label2.setBounds (24, 84, 91, 20);

label3 = new Label ("Proveedor");
label3.setBounds (312, 52, 91, 20);

label4 = new Label ("Telefono:");
label4.setBounds (312, 124, 91, 20);

nroTel = new Label ("");
nroTel.setBounds (410, 124, 91, 20);

label5 = new Label ("Resultado:");
label5.setBounds (224, 212, 91, 20);

label6 = new Label ("");
label6.setBounds (312, 212, 91, 20);

label7 = new Label ("Intentos:");
label7.setBounds (224, 244, 91, 20);

label8 = new Label ("0");
label8.setBounds (312, 244, 91, 20);

label9 = new Label ("Velocidad de");
label9.setBounds (24, 154, 91, 20);//(24, 164, 91, 20);

label10 = new Label ("Transferencia");
label10.setBounds (24, 174, 91, 20);//(24, 164, 91, 20);

textfield1 = new TextField ("");
textfield1.setBounds (120, 52, 90, 25);

textfield2 = new TextField ("");
textfield2.setBounds (120, 84, 90, 25);

choice1 = new Choice ();
choice1.addItemListener (this);
choice1.setBounds (312, 76, 80, 25);
choice1.add ("AOL");
choice1.add ("Tutopia");

choice2 = new Choice ();
choice2.setBounds (24, 200, 80, 25);//(24, 188, 80, 25);
choice2.add ("16");
choice2.add ("32");
choice2.add ("64");
choice2.add ("128");

button1 = new Button ("Conectar");
button1.setBounds (312, 156, 75, 25);
button1.addActionListener (this);

button2 = new Button ("Salir");
button2.setBounds (390,300,75, 25);
button2.addActionListener (this);

add (label1);
add (label2);
add (label3);
add (label4);
add (label5);
add (label6);
add (label7);
add (label8);
add (label9);
add (label10);
add (nroTel);
add (textfield1);
add (textfield2);
add (choice1);
add (choice2);
add (button1);
add (button2);
}



public void actionPerformed (ActionEvent e)
{
if(e.getSource () == button2)
{
System.exit(0);
}
if (e.getSource () == button1)
{
String s1 = textfield1.getText (); // Extraer datos
String s2 = textfield2.getText ();
String s3 = choice1.getSelectedItem ();
String s4 = choice2.getSelectedItem ();
if (s1.equalsIgnoreCase ("Aol") && s2.equals ("11111") && s3.equals ("AOL"))
{
label6.setText ("Correcto");
}
else
{
if (s1.equalsIgnoreCase ("Tutopia") && s2.equals ("55555") && s3.equalsIgnoreCase ("Tutopia") && Integer.parseInt (s4) < 33)
{
label6.setText ("Correcto");
}
else
{
label6.setText ("Incorrecto"); // Poner datos
}
}

String x1 = label8.getText();
int y1 = Integer.parseInt(x1);
y1 ++ ;
label8.setText(String.valueOf(y1));
}

if(e.getSource() == mi)
{
Aplicacion2 a2 = new Aplicacion2(this,choice1.getSelectedItem(),choice2 .getSelectedItem());
a2.setBounds(100,100,400,200);
a2.show();
}
}



y la otra aplicacion2 es de otro archivo .java que es este

public class Aplicacion2 extends Dialog implements ActionListener {
Label label1;
Label label2;
Label label3;
Label label4;
Button button1;

Aplicacion2(Frame f,String proveedor,String velocidad)
{
super(f);
setModal(true);
setResizable(true);
setLayout(null);

label1 = new Label("Proveedor:");
label1.setBounds(95,40,91,20);

label2 = new Label(proveedor);
label2.setBounds(246,40,91,20);

label3 = new Label("Velocidad:");
label3.setBounds(95,88,91,20);

label4 = new Label(velocidad);
label4.setBounds(246,88,91,20);

button1 = new Button("OK");
button1.setBounds(185,136,32,32);
button1.addActionListener(this);

add(label1);
add(label2);
add(label3);
add(label4);
add(button1);
}

public void actionPerformed(ActionEvent e)
{
if(e.getSource() == button1)

dispose();

}

}

donde esta llamada llama a aplicacion2 y crea el dialogo mostrandome los datos que estan selecionado en los choice

if(e.getSource() == mi)
{
Aplicacion2 a2 = new Aplicacion2(this,choice1.getSelectedItem(),choice2 .getSelectedItem());
a2.setBounds(100,100,400,200);
a2.show();
}

hasta aqui me sale bien porque estoy recogiendo un dato de los choice pero no se como recojer dato de un acumulador que es en este caso las cantidad de veces que se seleciono un sistema operativo ???

saludo
  #5 (permalink)  
Antiguo 20/01/2006, 22:21
Avatar de dogduck  
Fecha de Ingreso: enero-2006
Ubicación: ¿Atlantida, Hesperides, Islas afortunadas?
Mensajes: 2.231
Antigüedad: 18 años, 4 meses
Puntos: 19
a mi se me ocurre lo siguiente :

//Creo unos contadores
public Integer w98=0,wxp=0,linux=0;

//Tengo un choice
choice1 = new java.awt.Choice();
choice1.add("Elige Sistema Operativo");
choice1.add("Windows 98");
choice1.add("Windows XP");
choice1.add("Linux");

//Evento al cambiar de estado un elemento del choice
private void choice1ItemStateChanged(java.awt.event.ItemEvent evt) {
if (choice1.getSelectedItem()=="Windows 98") {w98++;}
if (choice1.getSelectedItem()=="Windows XP") {wxp++;}
if (choice1.getSelectedItem()=="Linux") {linux++;}
}

Lo he probado con el siguiente ejemplo implementado en NetBeans
Código:
/*
 * Ejemplo.java
 *
 * Created on 21 de enero de 2006, 4:53
 */

package general;

/**
 *
 * @author  DogDuck
 */
public class Ejemplo extends javax.swing.JFrame {
    public Integer w98=0,wxp=0,linux=0;
    /** Creates new form Ejemplo */
    public Ejemplo() {
        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.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        choice1 = new java.awt.Choice();
        choice1.add("Elige Sistema Operativo");
        choice1.add("Windows 98");
        choice1.add("Windows XP");
        choice1.add("Linux");
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();

        getContentPane().setLayout(null);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        choice1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                choice1ItemStateChanged(evt);
            }
        });

        getContentPane().add(choice1);
        choice1.setBounds(30, 30, 210, 20);

        jLabel1.setText("w98");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(40, 80, 30, 14);

        jLabel2.setText("wxp");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(40, 110, 30, 14);

        jLabel3.setText("linux");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(40, 140, 30, 14);

        jTextField1.setText("0");
        getContentPane().add(jTextField1);
        jTextField1.setBounds(90, 80, 12, 20);

        jTextField2.setText("0");
        getContentPane().add(jTextField2);
        jTextField2.setBounds(90, 110, 12, 20);

        jTextField3.setText("0");
        getContentPane().add(jTextField3);
        jTextField3.setBounds(90, 140, 12, 20);

        pack();
    }// </editor-fold>

    private void choice1ItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
        if (choice1.getSelectedItem()=="Windows 98") {w98++;jTextField1.setText(w98.toString());}
        if (choice1.getSelectedItem()=="Windows XP") {wxp++;jTextField2.setText(wxp.toString());}
        if (choice1.getSelectedItem()=="Linux") {linux++;jTextField3.setText(linux.toString());}
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Ejemplo().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify
    private java.awt.Choice choice1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration
    
}
Espero te valga de algo

Última edición por dogduck; 20/01/2006 a las 22:32
  #6 (permalink)  
Antiguo 21/01/2006, 09:26
 
Fecha de Ingreso: febrero-2005
Mensajes: 867
Antigüedad: 19 años, 3 meses
Puntos: 3
Hola si habia pensado antes en seleccionar el sistema operativo con un choice seria mucha mas facil pero en este caso necesito seleccionar el sistema operativo con un boton que sube y baja con una flecha que ya lo hice esa parte el acumulador ya esta de cada uno lo que no se como mostrar eso en el dialogo que me muestre las cantidades de cada sistema operativo que fue seleccionado aver alguna forma de hacerlo asi,,

saludo
  #7 (permalink)  
Antiguo 21/01/2006, 09:41
 
Fecha de Ingreso: febrero-2005
Mensajes: 867
Antigüedad: 19 años, 3 meses
Puntos: 3
public class Sistemas extends Frame implements ActionListener {
Label label1;
Label label2;
Label label3;
Label label4;
Label label5;
Label label6;
Label label7;
Label bar;
TextField textfield1;
TextField textfield2;
Choice choice1;
Button button1;
Button button2;
Button button3;
int x;



MenuBar barra;
Menu m1;
MenuItem m1Item1;


int Win98;
int WinXP;
int Linux;


Sistemas()
{
x=0;
Win98=0;
WinXP=0;
Linux=0;
setLayout(null);
barra = new MenuBar ();
setMenuBar (barra);
m1 = new Menu ("Sistema Operativo");
barra.add (m1);
m1Item1 = new MenuItem (" INFO");
m1.addActionListener(this);
m1.add (m2Item1);


label1 = new Label("Nombre de Usuario",Label.CENTER);
label1.setBounds(32,56,120,24);
label2 = new Label("Clave",Label.CENTER);
label2.setBounds(32,112,91,20);
label3 = new Label("Window 98",Label.CENTER);
label3.setBounds(144,180,91,20);
label4 = new Label("Window XP",Label.CENTER);
label4.setBounds(144,240,91,20);
label5 = new Label("Linux",Label.CENTER);
label5.setBounds(144,298,91,20);
label6 = new Label("Tipo de Usuario",Label.CENTER);
label6.setBounds(332,48,91,20);
label7 = new Label("Correcto/Incorrecto",Label.CENTER);
label7.setBounds(330,272,110,20);
bar = new Label("0");
bar.setBounds(100,190,40,120);
//bar.setBackground (Color.red);
//bar.setForeground (Color.red);
textfield1 = new TextField("");
textfield1.setBounds(152,56,90,25);
textfield2 = new TextField("");
textfield2.setBounds(152,104,90,25);
choice1 = new Choice();
choice1.setBounds(320,88,112,24);
button1 = new Button("^");
button1.setBounds(40,208,32,24);
button2 = new Button("v");
button2.setBounds(40,256,32,24);
button3 = new Button("Conectar");
button3.setBounds(344,216,75,25);

choice1.add("--------");
choice1.add("Administrador");
choice1.add("Juanita la loca");
choice1.add("Localhost");

add(label1);
add(label2);
add(label3);
add(label4);
add(label5);
add(label6);
add(label7);
add(bar);
add(textfield1);
add(textfield2);
add(choice1);
add(button1);
add(button2);
add(button3);

button1.addActionListener (this);
button2.addActionListener (this);
button3.addActionListener (this);

m1Item1.addActionListener (this);
m1Item3.addActionListener (this);

CerrarVentana fin = new CerrarVentana();
addWindowListener(fin);

EscucharTeclado te = new EscucharTeclado ();
addKeyListener (te);

button1.addKeyListener(te);
button2.addKeyListener(te);
button3.addKeyListener(te);

}

public void actionPerformed (ActionEvent e)
{
if ( e.getSource()==button3)
{
String s1=textfield1.getText();
String s2=textfield2.getText();
String s3=choice1.getSelectedItem();

if(s1.equalsIgnoreCase("xxxx")&& s2.equalsIgnoreCase("xxxx") && s3.equals("Administrador") )
{
label7.setText("Correcto");
}
else
{
label7.setText("Incorrecto");
}
}
if (e.getSource () == button1)
{
if (x < 30)
{
x=x+20;
Linux++;
Win98++;
WinXP++;
label2.setText(String.valueOf(Win98));
bar.setText (String.valueOf (x));
repaint ();
}
}

if (e.getSource () == button2)
{

if (x > 0)
{
x=x-20;

bar.setText (String.valueOf (x));
repaint ();
}
}


if(e.getSource() == m1Item1)
{
Sistemas2 j2 = new Sistemas2(this,Win98,WinXP,Linux);
j2.setBounds(100,100,400,200);
j2.show();

}

if( e.getSource()== buttonA)

System.exit(1);

}

public void paint (Graphics g)
{

g.drawLine (90 , 312 -x*3 , 130 , 312 - x *3 );

}

public class CerrarVentana extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
d.show();
}
}

public class EscucharTeclado extends KeyAdapter
{
public void keyPressed (KeyEvent k)
{
if (k.getKeyText (k.getKeyCode ()).equals ("Escape"))
System.exit (0);

}

}



ahora de donde llamo a Sistemas2

if(e.getSource() == m1Item1)
{
Sistemas2 j2 = new Sistemas(this,Win98,WinXP,Linux); // aqui es donde me da el error deberia de recojerme los valores del acumulador
j2.setBounds(100,100,400,200);
j2.show();

}
  #8 (permalink)  
Antiguo 24/01/2006, 10:28
 
Fecha de Ingreso: febrero-2005
Mensajes: 867
Antigüedad: 19 años, 3 meses
Puntos: 3
???????????????????????????????????????????
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 12:43.