[英]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 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();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.