Java对话框实现字符串反转,字符串大小写转换的程序实现

来源:互联网 发布:javascript拼图教程 编辑:程序博客网 时间:2024/06/05 02:57
import javax.swing.JOptionPane;


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;
}
}
}
}
0 0