Retroceder   Foros del Web > Programación para sitios web > Java y JSP

Respuesta
 
Herramientas Desplegado
Antiguo 05-jun-2008, 15:36   #1 (permalink)
camef ha deshabilitado el karma
 
Fecha de Ingreso: junio-2008
Mensajes: 4
Pregunta Enviar un Valor de un formulario a otro - Java

Bueno Gracias de Antemano.
Soy novato en Java y quisiera que me ayuden con lo siguiente please.
En un primer formulario se llena los datos q te pide como ejemplo codigo, nombre,
fecha y cada uno de esos datos se debe guardar en un arreglo y en el formulario 2 quiero volver a utilizar esos mismos arreglos ¿como hago para llamarlos al formulario 2?.

Bueno intente llamarlo Instanciando el formulario 1 en el formulario 2

Asi..

Form1 obj_f1 = new Form1();

obj.mivariabledelform1 // Pero la verdad es que su valor llega en 0 cuando es INT

Porfavor!!
camef está desconectado   Responder Citando
Antiguo 05-jun-2008, 23:38   #2 (permalink)
abulon ha deshabilitado el karma
 
Fecha de Ingreso: diciembre-2006
Mensajes: 94
Sonrisa Respuesta: Enviar un Valor de un formulario a otro - Java

Prueba esto espero y te sirva

Código PHP:

import java
.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import javax.swing.border.BevelBorder;


public class 
keyenter extends JFrame
{

JFrame t;
 private 
JList list;
 private 
JTextField caja=new JTextField();
 private 
JTextField text=new JTextField();
 private 
String returnValue;


   
keyenter()
   {

   
super("OK");

   
String ACTION_KEY "The Action";

   final 
JButton boton= new JButton("<html><center>ENTER<br>Window/Pressed");
   final 
JButton bot2=new JButton("<html><center>CONTROL C<br>Window/Pressed");
   final 
JButton k=new JButton("test");
   
JPanel pan=new JPanel();
   final 
JDialog ok;

   final 
JTextField text=new JTextField(10);

   
//pan.setLayout(null);

   
pan.add(text);


   
Container pane this.getContentPane();
   
pane.add(botonBorderLayout.SOUTH);
   
pane.add(pan,BorderLayout.CENTER);
   
pane.add(bot2,BorderLayout.NORTH);


  
AbstractAction pasaFoco = new AbstractAction()
  {

  public 
void actionPerformed(ActionEvent actionEvent)
  {
          
JButton source = (JButtonactionEvent.getSource();

          
System.out.println("Activated: " source.getText());

          if (
source==bot2)
         {

          
String retVal = new dialog(t,keyenter.this).getName();
                        
String temp "";
                        if(
retVal == null)
                           
temp "Cancelled";

                        else if(
retVal.equals(""))
                          
temp "nothing entered";

                        else
                        
temp retVal;
                        
text.setText(temp);
         }
      }

  };



bot2.addActionListener(new ActionListener()
{
    public 
void actionPerformed(ActionEvent ev)
    {


              
String retVal = new dialog(t,keyenter.this).getName();
              
String temp "";
              if(
retVal == null)
                 
temp "Cancelled";

              else if(
retVal.equals(""))
                
temp "nothing entered";

              else
              
temp retVal;
              
text.setText(temp);

    }

});


boton.addActionListener(new ActionListener()
{
    public 
void actionPerformed(ActionEvent e)
    {
        
String source=boton.getText();

       
System.out.println("Activated:"source);

    }

});



InputMap inputMap = new InputMap();

KeyStroke strok=KeyStroke.getKeyStroke(KeyEvent.VK_C,Event.CTRL_MASK,true);

inputMap=bot2.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
inputMap.put(strok,ACTION_KEY);

ActionMap actionBot=bot2.getActionMap();
actionBot.put(ACTION_KEY,pasaFoco);



   
KeyStroke stroke KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0,true);


   
inputMap boton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
   
inputMap.put(stroke,ACTION_KEY);

   
ActionMap actionMap boton.getActionMap();
   
actionMap.put(ACTION_KEYpasaFoco);


   
setSize(200,200);

   
setDefaultCloseOperation(EXIT_ON_CLOSE);
   
setVisible(true);
   
setResizable(false);

   }



public static 
void main(String [] args)
{
 new 
keyenter();
}



class 
dialog {


   public 
dialog(JFrame frkeyenter t)
   {

     
keyenter padre;
    
padre=t;

      final 
JButton k=new JButton("test");
      final 
JDialog ok=new JDialog(fr,true);
      
String val=ok.getName();

      final 
JTextField caja=new JTextField();
    
k.setEnabled(false);

      
String ar[]={"uno","dos","tres","four","five","six","seven","salir"};
     final 
JList list=new JList(ar);


      
JScrollPane js=new JScrollPane(list);



      
caja.setBounds(new Rectangle(10,10,120,20));
      
k.setBounds(new Rectangle(20,30,60,30));
      
k.setMnemonic(KeyEvent.VK_T);


    
JPanel p=new JPanel();
    
JPanel p2=new JPanel();



    list.
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.
setOpaque(true);



    list.
addListSelectionListener(new ListSelectionListener() {

      public 
void valueChanged(ListSelectionEvent evt)
      {
        if (
evt.getValueIsAdjusting()==false)
        {
              
//return;
           // System.out.println("Selected from " + evt.getFirstIndex() + " to " + evt.getLastIndex());

    //boolean anySelected = !list.isSelectionEmpty();
             
if (list.getSelectedIndex()==-1)
               {
                
k.setEnabled(false);
                }
            else
            {
                 
k.setEnabled(true);
                 
String name=list.getSelectedValue().toString();
                
caja.setText(name);
                
System.out.println(name);

             }
         }
       }

        });

list.
addKeyListener(new KeyAdapter()
{

 public 
void keyPressed(KeyEvent ev )
 {
     if (
ev.getKeyCode()==KeyEvent.VK_ENTER)
     {
         
returnValue=caja.getText();
         
ok.dispose();
     }

 }


}
);


list.
addMouseListener(new MouseAdapter()
{


public 
void mouseClicked(MouseEvent ev)
{

    if (
ev.getClickCount() == 2)
    {
            
System.out.println(" double click" );
            
returnValue=caja.getText();
            
ok.dispose();

         }


}

}
);

        
k.addActionListener(
            new 
ActionListener()
            {
                public 
void actionPerformed(ActionEvent e)
                {
                 
returnValue=caja.getText();
                 
ok.dispose();
                }

            });


       
ok.setLayout(new GridLayout(2,1));
     
ok.getRootPane().setBorder(new BevelBorder(BevelBorder.LOWERED));

     
ok.add(p);
     
ok.add(p2);

     
p.setLayout(null);
     
p.add(caja);
     
p.add(k);

     
p2.setLayout(new GridLayout(1,1));
     
p2.setPreferredSize(new java.awt.Dimension(40,80));
     
p2.add(js);


       
ok.setSize(200,180);
       
ok.setVisible(true);

   }




    public 
String getName()
    {
         return 
returnValue;
    }

  }



}
////fin de la clase keyenter 


Saludos
abulon está desconectado   Responder Citando
Respuesta
No hay votos aún.


Herramientas
Desplegado

Normas de Publicación
No puedes crear nuevos temas
No puedes responder temas
No puedes subir archivos adjuntos
No puedes editar tus mensajes

BB code is Activado
Caritas están Activado
[IMG] está Desactivado
Código HTML está Desactivado


La Zona horaria es GMT -6. Ahora son las 21:42.


Message Board Statistics

LinkBacks Enabled by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93