1

ジャマイカからのご挨拶、

NetBeansJavaプロジェクトで問題が発生しています。MainJFrame.javaというGUIクラスとmain.javaという別のクラスの2つの別々のクラスがあります。

MainJFrameフォームには、jTextFieldとjbuttonがあります。jbuttonをクリックしてjtextfield値をmain.javaクラスに渡すにはどうすればよいですか?

ありがとう。

4

2 に答える 2

1

one possible solution would be to create a third class which handles the communication.
There you would have to register the main.java and pass it to MainJFrame.java.

For Example

public class handler {
    public static main myClass = new main;

    public static main getClass() {
        retunr myClass;
    }

}

Your JFrameMain should containt a new variable

private main mainClass = handler.getClass();

Your onClicklistener should now voi dthe method from your mainClass which gets the text.

mainClass.setText(textFromJText);

Hope i could help you.

于 2013-02-27T16:41:30.113 に答える
1
  1. MainJFrame クラスの Main クラスのインスタンスへの参照を保持します。
  2. ActionListenerJButton に を定義します。
  3. この ActionListener では、JTextField の値を取得します。JTextField.getText()
  4. そして、最初のステップでテキストをパラメーターとして保持したインスタンスで Main クラスのメソッドを呼び出します。
于 2013-02-27T16:41:49.270 に答える