0

ユーザーからのリクエストが必要なアプリケーションを 1 つ作成しています。アプリの最初のバージョンでは、自分で 1 つの入力ウィンドウを作成しましたが、JOptionFrame から事前に成形されたツールであるため、showInputDialog を変更したほうがよいことがわかりました。現在、イベント トリガーに問題があります。以下のコードをチェックしてください。

検索画面:

public class SearchScreen extends EventSearch{
    ...
    public SearchScreen(){
        userQuery = (String) JOptionPane.showInputDialog("Type Keywords in english to be requested below:");    
    }
    ...
}

イベント検索:

public class EventSearch extends TabBuilder{

    public EventSearch() {

    }

    public void actionPerformed(ActionEvent Ev) {
        try {
            System.out.println("worked");
        } catch (IOException e1) {
            e1.printStackTrace(); //print failure
            JOptionPane.showMessageDialog(null, "FAIL");
        }
    };
}

タブビルダー:

public class TabBuilder implements ActionListener {
    .....
}

次に、showInputDialog を介してイベントを呼び出す方法を尋ねます。出来ますか?誰が聞き役になるの?前もって感謝します

4

1 に答える 1

0

私は自分自身の答えを見つけました-それは確かに、イベント検索クラスのコードを実行し、このような1つのアクションにトリガーを引っ張ることです。代わりに、次のことを行う方が良いです:

public SearchScreen(){

        userQuery = (String) JOptionPane.showInputDialog("Type Keywords in english to be requested below:");

            try {

                 //Your Action with the String  

            } catch (IOException e1) {

                e1.printStackTrace(); //print failure
                    JOptionPane.showMessageDialog(null, "FAILURE");
            }

    }
于 2013-07-15T10:04:36.000 に答える