簡體   English   中英

我想從組合框中選擇一個項目,然后單擊按鈕時根據所選項目打開另一個框架

[英]i want select an item from the combo box and open another frame according to the selected item when I click a button

我嘗試了這段代碼,但是它不起作用,並且代碼中沒有錯誤。在這里,下一個是我的按鈕。

 private void nextActionPerformed(java.awt.event.ActionEvent evt) {                                     

        String value=(String)select.getSelectedItem();//select is my combo box
        if("image file".equals(value)){

            ImageCrypto im=new ImageCrypto();
            im.setVisible(true);
            this.dispose();

        }else if("text file".equals(value)){
            TextCrypto im=new TextCrypto();
            im.setVisible(true);
            this.dispose();
        }

    }         

value包含數字,並且image filetext fileString 顯然,它們不匹配。

您可以打印出該value並檢查該值是什么。 之后,僅進行比較。

private void nextActionPerformed(java.awt.event.ActionEvent evt) {                                     

        String value=(String)select.getSelectedItem(); 
        System.out.println(value); // example you get abc
        if("abc".equals(value)){  // change to abc

            ImageCrypto im=new ImageCrypto();
            im.setVisible(true);
            this.dispose();

        }else if("text file".equals(value)){
            TextCrypto im=new TextCrypto();
            im.setVisible(true);
            this.dispose();
        }

    }         

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM