[英]How to return the new value of a public String from a private void JButton?
I have a public String in one class and is to be used by other classes. 我在一类中有一个公共String,供其他类使用。 The value of this String can only be acquired with the use of a JButton
. 只能使用JButton
来获取此String的值。 My code seems right but still I only get null
returned from the button. 我的代码似乎正确,但是我仍然只能从按钮返回null
。
Below is my class containing the public String variable and the code for the JButton
: 下面是我的类,其中包含公共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);
}
}
......
}
I'm using JFrame
Form by the way in Netbeans. 我正在Netbeans中使用JFrame
Form。 Is there any other way of returning the value of Seminar_Choosen
? 还有其他方法可以返回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);
}
}
Then 然后
JButton = new JButton(new Example(myString));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.