从单独的 JForm 访问 JComboBox 数据

2022-01-24 00:00:00 netbeans java swing jframe jcombobox

我花了一些时间浏览 Stack Overflow 和互联网来寻找我的问题的答案,但我发现所有答案都很难理解,而且我很不确定它们是否与我的问题有关,所以我决定我需要在正确的环境中获得帮助.

I've spent a bit of time browsing Stack Overflow and the internet looking for the answer to my question, but I found all the answers hard to understand and I was quite unsure if any of them related to my problem, so I decided I needed help in the right context.

我正在创建一个程序,该程序将根据输入的特定类型的图形提供一系列解决方案.我真诚地努力从第一个 JFrame 中的 JComboBox 中获取数据,并在第二个中显示它.

I am creating a program that will give a series of solutions based on a particular type of graph inputted. I am sincerely struggling with taking the data from my JComboBox in the first JFrame, and displaying it in the second.

我有两个类,GraphEquationSolverGUI 和 DefineEquation.我正在使用 Netbeans IDE,GraphEquationSolverGUI 是我的项目".

I have two classes, GraphEquationSolverGUI and DefineEquation. I am using the Netbeans IDE and GraphEquationSolverGUI is my "project."

GraphEquationSolverGUI:

GraphEquationSolverGUI:

private void graphSelectionActionPerformed(java.awt.event.ActionEvent evt) {                                               
    String graphSelectionGUI = (String)graphSelection.getSelectedItem();
    //graphSelectedTextField.setText(graphSelectionGUI);
    DefineEquation graphSelectedObj = new DefineEquation(graphSelectionGUI);
    graphSelectedObj.addItem(graphSelectionGUI);

这是我希望选择将数据发送到另一个类的 JComboBox.JComboBox 称为graphSelection.您会注意到注释文本是我将 JTextField 设置为 JComboBox 的值,这是在此 JForm 内部,我自己用来测试以确保数据输入正确,它可以工作并且我可以显示数据在同一个 JFrame 中.下面的其他代码是我尝试创建一个对象并通过它传递数据,我对对象有点生疏,因为我有一段时间没有使用它们了,如果我让你哭了,对不起.

This is the JComboBox in which I want the selection to send data to another class. The JComboBox is called graphSelection. You will notice the the commented text is me setting a JTextField to the value of the JComboBox, this is inside of this JForm and was used by myself to test to make sure the data was being input right, it works and I can display the data in this same JFrame. The other code following is my attempt to create an object and pass the data through it, I'm a bit rusty with objects as I haven't worked with them for a while, sorry if I make you cry.

定义方程:

public DefineEquation(String graphSelected) {
    this.graphSelected = graphSelected;
} //If anyone cares here is my constructor for the object

public void addItem(String graphSelectedString1){
    DefineEquation graphSelectedObj = new DefineEquation(graphSelected);
    String graphSelectedStringMAIN = graphSelectedString1.toString();
    selectedGraph.setText(graphSelectedStringMAIN);
}

以上是我创建的将数据添加到名为 selectedGraph 的 JTextField 的方法.您会注意到我有 graphSelectedString1 和 graphSelectedStringMAIN ,其中我将一个字符串转换为一个显然是多余的字符串.我这样做是为了以防万一,这是多余的,对不起让你畏缩了.

The above is the method I created to add the data to a JTextField called selectedGraph. You will notice I have graphSelectedString1 and graphSelectedStringMAIN in which I convert a String to a String which is obviously redundant. I did this just in case, it is redundant, sorry for making you cringe.

我知道这可能很难理解,您可能会发现很难理解我在问什么.简单地说,我如何将数据从一个 JFrame JComboBox 传递到另一个 JFrame 中的 JTextField?我会使用对象吗?如果可以的话,请尝试引导我完成它,我很困惑.如果您想通读所有内容,我将在下面粘贴我的所有代码.

I understand that this may be hard to follow, and you may find it hard to understand what I am asking. So simply put, how would I pass data from one JFrame JComboBox to a JTextField in a separate JFrame? Would I use Objects? Please try to walk me through it if you can, I am very confused. I will paste all my code below if you wish to read through everything.

GraphEquationSolverGUI:

GraphEquationSolverGUI:

/*
* To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

/**
 *
 * @author MatthewAlanTroutman
 */

public class GraphEquationSolverGUI extends javax.swing.JFrame {

/**
 * Creates new form GraphEquationSolverGUI
 */

public GraphEquationSolverGUI() {
    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.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jSpinner1 = new javax.swing.JSpinner();
    welcome = new javax.swing.JLabel();
    programDescription = new javax.swing.JLabel();
    graphsOffered = new javax.swing.JLabel();
    linear = new javax.swing.JLabel();
    bilinear = new javax.swing.JLabel();
    quadratic = new javax.swing.JLabel();
    cubic = new javax.swing.JLabel();
    exponential = new javax.swing.JLabel();
    graphSelectionText = new javax.swing.JLabel();
    graphSelection = new javax.swing.JComboBox();
    help = new javax.swing.JButton();
    close = new javax.swing.JButton();
    next = new javax.swing.JButton();
    graphSelectedTextField = new javax.swing.JTextField();
    graphSelectedLabel = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("GraphEquationSolver");
    setBackground(new java.awt.Color(255, 255, 255));

    welcome.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
    welcome.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    welcome.setText("Welcome");
    welcome.setPreferredSize(new java.awt.Dimension(800, 100));

    programDescription.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
    programDescription.setText("You can use this program to find a variety of solutions for different types of graphs, please select a graph to begin");
    programDescription.setPreferredSize(new java.awt.Dimension(800, 75));

    graphsOffered.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
    graphsOffered.setText("Graphs we offer:");

    linear.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
    linear.setText("- Linear");

    bilinear.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
    bilinear.setText("- Bilinear");

    quadratic.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
    quadratic.setText("- Quadratic");

    cubic.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
    cubic.setText("- Cubic");

    exponential.setFont(new java.awt.Font("Lucida Grande", 0, 14)); // NOI18N
    exponential.setText("- Exponential");

    graphSelectionText.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
    graphSelectionText.setText("Please select your graph");

    graphSelection.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Linear", "Bilinear", "Quadratic", "Cubic", "Exponential" }));
    graphSelection.setToolTipText("");
    graphSelection.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            graphSelectionActionPerformed(evt);
        }
    });

    help.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
    help.setText("Help");

    close.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
    close.setText("Close");
    close.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            closeActionPerformed(evt);
        }
    });

    next.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
    next.setText("Next");
    next.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            nextActionPerformed(evt);
        }
    });

    graphSelectedTextField.setEditable(false);

    graphSelectedLabel.setFont(new java.awt.Font("Lucida Grande", 0, 18)); // NOI18N
    graphSelectedLabel.setText("Graph Selected");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(welcome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(240, 240, 240))
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(240, 240, 240)
                    .addComponent(programDescription, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createSequentialGroup()
                    .addGap(184, 184, 184)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(exponential)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(graphsOffered)
                                .addComponent(linear)
                                .addComponent(bilinear)
                                .addComponent(quadratic)
                                .addComponent(cubic))
                            .addGap(311, 311, 311)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(graphSelectionText, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(graphSelection, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(graphSelectedTextField)
                                .addComponent(graphSelectedLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))))
                .addGroup(layout.createSequentialGroup()
                    .addGap(231, 231, 231)
                    .addComponent(help, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(close, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(next, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(240, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(34, 34, 34)
            .addComponent(welcome, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(programDescription, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(73, 73, 73)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(graphsOffered)
                .addComponent(graphSelectionText))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(graphSelection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(linear)
                .addComponent(graphSelectedLabel))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(bilinear)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(quadratic))
                .addComponent(graphSelectedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(cubic)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(exponential)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(layout.createSequentialGroup()
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 219, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(help, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(close, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(next, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(169, 169, 169))))
    );

    graphSelection.getAccessibleContext().setAccessibleName("");
    help.getAccessibleContext().setAccessibleName("help");
    close.getAccessibleContext().setAccessibleName("close");

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

private void graphSelectionActionPerformed(java.awt.event.ActionEvent evt) {                                               
    String graphSelectionGUI = (String)graphSelection.getSelectedItem();
    graphSelectedTextField.setText(graphSelectionGUI);
    //DefineEquation graphSelectedObj = new DefineEquation(graphSelectionGUI);
    //graphSelectedObj.addItem(graphSelectionGUI);

}                                              

private void closeActionPerformed(java.awt.event.ActionEvent evt) {                                      
    System.exit(0);
}                                     

private void nextActionPerformed(java.awt.event.ActionEvent evt) {                                     
    this.setVisible(false);
    new DefineEquation().setVisible(true);
}                                    

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(GraphEquationSolverGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(GraphEquationSolverGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(GraphEquationSolverGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(GraphEquationSolverGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new GraphEquationSolverGUI().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JLabel bilinear;
private javax.swing.JButton close;
private javax.swing.JLabel cubic;
private javax.swing.JLabel exponential;
private javax.swing.JLabel graphSelectedLabel;
private javax.swing.JTextField graphSelectedTextField;
private javax.swing.JComboBox graphSelection;
private javax.swing.JLabel graphSelectionText;
private javax.swing.JLabel graphsOffered;
private javax.swing.JButton help;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JLabel linear;
private javax.swing.JButton next;
private javax.swing.JLabel programDescription;
private javax.swing.JLabel quadratic;
private javax.swing.JLabel welcome;
// End of variables declaration                   
}

定义方程:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

/**
 *
 * @author MatthewAlanTroutman
 */
public class DefineEquation extends javax.swing.JFrame {
//public class DefineEquation extends GraphEquationSolverGUI {
public String graphSelected;

/**
 * Creates new form DefineEquation
 */
public DefineEquation() {
    initComponents();
}
public DefineEquation(String graphSelected) {
    this.graphSelected = graphSelected;
}



/**
 * 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.
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    selectedGraph = new javax.swing.JTextField();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    selectedGraph.setEditable(false);
    selectedGraph.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            selectedGraphActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(435, 435, 435)
            .addComponent(selectedGraph, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(596, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGap(126, 126, 126)
            .addComponent(selectedGraph, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(646, Short.MAX_VALUE))
    );

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

private void selectedGraphActionPerformed(java.awt.event.ActionEvent evt) {                                              

}                                             
public void addItem(String graphSelectedString1){
    DefineEquation graphSelectedObj = new DefineEquation(graphSelected);
    String graphSelectedStringMAIN = graphSelectedString1.toString();
    selectedGraph.setText(graphSelectedStringMAIN);
}

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(DefineEquation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(DefineEquation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(DefineEquation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(DefineEquation.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new DefineEquation().setVisible(true);
        }

    });
}

// Variables declaration - do not modify                     
private javax.swing.JTextField selectedGraph;
// End of variables declaration                   
}

您会注意到我试图扩展"我的第一个 JFrame,但这导致第二个 JFrame窗口"以某种方式与第一个 JFrame窗口"结合在一起.

You will notice I tried to "extend" my first JFrame, but this resulted in the second JFrame "window" somehow combining with the first JFrame "window."

概念图:

编辑 1:这是最好的方法吗?如果是这样,我将如何移动数据?对象目前让我感到困惑,还有一些似乎无效的非静态和静态问题,因为我没有任何静态的东西.如果这不是最好的方法,我该怎么办?我要睡觉了,请评论你的建议和帮助,我不仅绝望,而且感到迷茫.

Edit 1: Is this the best way to go through with it? If so, how would I go about moving the data around? Objects are currently confusing me along with some non static and static problems which don't seem valid as I don't have anything static. If this is not the best way of doing it, what should I do? I'm going to bed, please comment with your suggestions and help, not only am I desperate, but I feel lost.

编辑 2:我正在尝试使用 m.cekiera 的答案,请在回答之前参考他的答案,因为这可能会有所帮助.

Edit 2: I am trying to work with what m.cekiera's answer was, refer to his answer before answering as it might be helpful.

仍然卡住并需要详细的帮助,很抱歉要求如此苛刻,但我无法解决这个问题.

Edit 3: Still stuck and talk in need of detailed help, sorry to be so demanding but I can't wrap my head around this.

编辑 4:我认为我找到了重大突破.我已经想出了如何解决这个问题,但我真的认为我需要了解这一点.无论如何,我有一个新课程和一个不同课程的新文本字段.我仍然有问题,我无法显示文本字段的值,但由于某种原因我可以输出相同的值.我想它更容易显示

Edit 4: I think I've found a significant breakthrough. I've figured out how to work around the issue, but I really think I need to understand this. Anyway, I've got a new class and a new text field for a different class. I still have the problem, I can't display a value of of the textfield, but for some reason I can output the same value. I guess it's easier shown

所以这是 SelectSolutionsQuadratic 类:

So this is the class SelectSolutionsQuadratic:

public void displayText(String textToSet) {
    displayQuadraticEquation.setText(textToSet);
    System.out.println(textToSet);
}

这是DefineEquationQuadratic:

And this is DefineEquationQuadratic:

private void nextActionPerformed(java.awt.event.ActionEvent evt) {                                     
    this.setVisible(false);
    new SelectSolutionsQuadratic().setVisible(true);
    SelectSolutionsQuadratic transferMe = new SelectSolutionsQuadratic();
    transferData = aQuadraticSpinner.getValue().toString() + " " + addSubQuadraticComboBox.getSelectedItem(); 
    transferMe.displayText(transferData);
}                     

所以基本上我只是很困惑为什么我可以将一个值从 DefineEquationQuadratic 发送到 SelectSolutionsQuadratic,然后用 System.out.println(); 输出它.但不将文本字段设置为该值

So basically I'm just confused why I can send a value from DefineEquationQuadratic to SelectSolutionsQuadratic, output it with System.out.println(); but NOT set the textfield to be that value

推荐答案

所以我真的很笨,创建了两个实例,一个我没有查看,另一个我正在查看但没有更改.基本上我所做的是在 graphSelectionActionPerformed 我做了:

So I was really dumb and had two instances created, one of which I was not viewing and the other of which I was but was not changing. Basically what I did was in graphSelectionActionPerformed I did:

this.graphSelectionGUI = (String)graphSelection.getSelectedItem();

然后在 nextActionPerformed 我做了:

Then in nextActionPerformed I did:

new DefineEquation_1(graphSelectionGUI).setVisible(true);

接下来,在另一个类 (DefineEquation) 中,我使用了我的构造函数并这样做了:

Following this, in the other class (DefineEquation), I took my constructor and did this:

public DefineEquation(String graphSelected) {
    this.graphSelected = graphSelected;
    initComponents();
    selectedGraph.setText(graphSelected);
}

最后我泪流满面,意识到我给你们带来了多大的麻烦,我是多么的愚蠢,赞美主!

And lastly I cried with tears realising how much trouble I gave you guys and how dumb I was, praise the lord!

很抱歉给大家添麻烦了,我的错.

Sorry for troubling everyone, my bad.

相关文章