我在一个类中有一个公共String,并且将被其他类使用。只能使用JButton
获取此String的值。我的代码似乎没错,但我只能从按钮返回null
。
下面是我的类,其中包含公共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
的价值?
答案 0 :(得分:1)
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));