[英]How to return a value from a text field from Jframe2 to Jframe1 in Netbeans
I have this code: 我有以下代码:
my main Frame: 我的主要框架:
public MainFrame() {
initComponents();
}
My other frame is initialized like this in my main frame: 我的其他框架在我的主框架中初始化如下:
private void agregarAlumnoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new AgregarAlumno().setVisible(true);
}
which opens the second frame: 这将打开第二帧:
public AgregarAlumno() {
initComponents();
}
I then will show a text box in the second frame to input something and i would like it for it to be used by my Main Frame, i know i can send a value to the second frame like this 然后,我将在第二个框架中显示一个文本框以输入一些内容,我希望它可以被我的主框架使用,我知道我可以像这样将值发送到第二个框架
new AgregarAlumno(valueX).setVisible(true);
and then on the Second Frame receive it building a constructer like this 然后在第二帧接收它来构建一个像这样的构造器
public AgregarAlumno(int valueX) {
initComponents();
}
and use it in the second Frame. 并在第二帧中使用它。 but how would i send back a value to the first Frame? 但是我该如何将值发送回第一帧?
Thanks. 谢谢。
// you can passvalue from one text field to other like this // this is just simple example //您可以像这样将值从一个文本字段传递到另一个文本字段//这只是简单的示例
public MainFrame() {
public void actionPerformed(ActionEvent ev){
FrameOne frameOne = new FrameOne(userField.getText(),passField.getText());
frameOne.setVisible(true);
}
}
public class FrameOne extends JFrame
{
private String user;
private String pass;
public FrameOne(String usr, String pas){
this.user=usr;
this.pass=pas;
//components
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.