I would like to know why this code does not send me data from one Jframe to another. I have two fields (textField), one (num1) in a Jframe called purchases and the other (p4) in another Jframe called invoice.
What I want is that I type any word in the shopping field called num1 and it appears in the other field (p4) of the other JFrame.
For that I execute the following code, in a button called invoice, as shown below. But it does not send the word.
What could be the problem?
private void BotonFacturaActionPerformed(java.awt.event.ActionEvent evt){
String dato; //variable que gusrda la informacion que se dijite el JTextField llamado num1
dato=num1.getText();//estoy capturando lo que se digite en el campo num1 y guardandolo en la variable dato
new Factura().setVisible(true);//la ventana que recibe los datos se abra
Factura.p4.setText(dato);//envia el dato a la variable de la factura
}
When I need to send information between windows, I usually modify the constructor of the JFrame by adding the parameter of the variable that I want to send.
Example. In my main window, event on button click:
Now, you can notice that when creating the childFrame instance, I am sending the variable "name" as a parameter to the constructor method. The other side looks like this.
In the other window, in the constructor method:
There are other ways to do this, you can also create your own "init" function and after instantiating the child window, you call its init method and pass it whatever variables are required.
in the Jframe purchase you have your text field and your button
inside the actionPerformed
the invoice Jframe has a static variable used to set that value in this form
in your constructor you do this