[英]How to return a value from a text field from Jframe2 to Jframe1 in Netbeans
我有以下代码:
我的主要框架:
public MainFrame() {
initComponents();
}
我的其他框架在我的主框架中初始化如下:
private void agregarAlumnoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
new AgregarAlumno().setVisible(true);
}
这将打开第二帧:
public AgregarAlumno() {
initComponents();
}
然后,我将在第二个框架中显示一个文本框以输入一些内容,我希望它可以被我的主框架使用,我知道我可以像这样将值发送到第二个框架
new AgregarAlumno(valueX).setVisible(true);
然后在第二帧接收它来构建一个像这样的构造器
public AgregarAlumno(int valueX) {
initComponents();
}
并在第二帧中使用它。 但是我该如何将值发送回第一帧?
谢谢。
//您可以像这样将值从一个文本字段传递到另一个文本字段//这只是简单的示例
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.