public class InputDialogTest{
public static void main(String[] args){
String inputString=JOptionPane.showInputDialog(null,"請輸入一個英文單詞","輸入",JOptionPane.QUESTION_MESSAGE);
while(true){
Object[] option={"轉換爲大寫","轉換成小寫","反轉顯示"};
Object item=JOptionPane.showInputDialog(null,"請選擇","輸入",JOptionPane.INFORMATION_MESSAGE,null,option,option[0]);
String itemString=(String)item;
if(itemString.equals("轉換爲大寫")){
String str=inputString.toUpperCase();
JOptionPane.showMessageDialog(null,str,"操作結果",JOptionPane.INFORMATION_MESSAGE);
}else if(itemString.equals("轉換成小寫")){
String str=inputString.toLowerCase();
JOptionPane.showMessageDialog(null,str,"操作結果",JOptionPane.INFORMATION_MESSAGE);
}else{
String str=new StringBuffer(inputString).reverse().toString();
JOptionPane.showMessageDialog(null,str,"操作結果",JOptionPane.INFORMATION_MESSAGE);
}
int reponse=JOptionPane.showConfirmDialog(null,"是否繼續呢","菜單",JOptionPane.YES_NO_OPTION);
if(reponse==JOptionPane.NO_OPTION){
break;
}
}
}
}