简体   繁体   中英

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

I tried this code but it is not working, And there are no errors in the code.In here next means my 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();
        }

    }         

I expect value contains number, and image file or text file is String . Obviously they won't matched.

You can print out the value and check what does the value is. After that only do the comparison.

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();
        }

    }         

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM