[英]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.