我试过这段代码,但它不起作用,而且代码中没有错误。这里的 next 指的是我的按钮。
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 file
或者text file
是String
。显然他们不会匹配。
您可以打印出来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();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句