gpt4 book ai didi

java - 如何从私有(private) void JButton 返回公共(public)字符串的新值?

转载 作者:行者123 更新时间:2023-12-01 12:30:12 25 4
gpt4 key购买 nike

我在一个类中有一个公共(public)字符串,可供其他类使用。该字符串的值只能通过使用JButton 来获取。我的代码看起来是正确的,但我仍然只从按钮返回 null

下面是我的类,其中包含公共(public) String 变量和 JButton 的代码:

public class Seminar_Menu extends javax.swing.JFrame {
Connection conn = null;
ResultSet rs = null;
PreparedStatement ps = null;
// Public String mentioned in quesiton
public String Seminar_Choosen;
......

//Button Code
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
Conduct_Seminar consem = new Conduct_Seminar();
Seminar_Menu semen = new Seminar_Menu();

String message = "Conduct this seminar?";
String title = "Conduct";
int reply =
JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);

if (reply == JOptionPane.YES_OPTION)
{

Seminar_Choosen = Title_Field.getText();

consem.setVisible(true);
semen.setVisible(false);
}
}

......

}

我正在 Netbeans 中使用 JFrame Form。是否有其他方法返回 Seminar_Choosen 的值?

最佳答案

public class Example {
public static class myAction extends AbstractAction {
String val;
public myAction(String val) {
this.val = val;
}
public void ActionPerformed(ActionEvent ae) {
System.out.println("value: " + val);
}
}

然后

JButton = new JButton(new Example(myString));

关于java - 如何从私有(private) void JButton 返回公共(public)字符串的新值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25981230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com