繁体   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