내 프로그램을 작동시키는 데 문제가 있습니다. 나는 이것에 대해 꽤 기초적이고 처음 프로그램 인 경험이 많지 않다. 문제는 JOptionPane의 루프가 끝나지 않는다는 것이다. JOptionMenu가 나타나서 Add, Find 또는 모든 레코드를 표시하고 입력 내용에 관계없이 "좋은 하루 보내십시오"라고 말하면서 끝나지 않고 모든 레코드 추가, 찾기 또는 표시 JOtion 입력으로 돌아갑니다. 내 코딩이 조금 떨어져 있다고 가정하고 코드의 다른 부분에서 아마도 오류가 발생하지만,이 도움은 매우 놀랍고 크게 감격했습니다.Java JOption in loop
public static void main(String[] args) {
// variable declarations //
boolean loopagain=true;
// declare strArg as String //
String strArg;
String strMenu;
char strArgs;
// declare strMenu as String and Assign a string that creates a menue as follows:
* [A]dd record
* [F]ind record
* [S]how All records //
strMenu = " [A]dd record\n " +
" [F]ind record\n " +
" [S]how All records\n ";
if (args.length == 0){
while (loopagain) {
strArg = JOptionPane.showInputDialog(null, strMenu ,"Menu"
, JOptionPane.QUESTION_MESSAGE);
strArg = strMenu.toUpperCase();
strArgs = strArg.toUpperCase().charAt(0);
if (args.length > 0){
switch (strArgs) {
case 0:
if (strArgs == 'A')
addRec();
break;
case 1:
if (strArgs == 'F')
findRec();
break;
case 2:
if (strArgs == 'S')
showAll();
break;
default:
errMessage();
// end of switch //
}
// end of strArg test //
// otherwise, if no entry, run an errMessage() method // errMessage();
// end of loop //
break;
}
/** exit program with the MessageDialog "Have a Noce Day!" */
JOptionPane.showMessageDialog(null, "Have a Nice Day!");
// end of args test //
}
// end of main() method //
}
public static void errMessage() {
JOptionPane.showMessageDialog(null, "Invalid Menu Choice");
}
// create a method named loopquery()
// - that returns a boolean value
// - accepts no arguments
// - content:
// - declaration of a boolean variable initialized to false
// - an InputDialog that requests if you want to loopagain (y,n)and assigns the value to a string variable
// - converts the String variable to upper case
// - changes the value of the boolean variable to true if the string variable has a value of "Y"
// - returns the value of the boolean variable
//
public static void loopquery() {
String loopquery;
boolean loopagain;
loopagain=false;
loopquery = JOptionPane.showInputDialog(null, "Another table (y.n)",
"Again?", JOptionPane.QUESTION_MESSAGE);
loopquery = loopquery.toUpperCase();
}
public static void addRec() {
JOptionPane.showMessageDialog(null, "AddRec");
}
public static void findRec() {
String findrecs;
findrecs = JOptionPane.showInputDialog(null, "Request a record" ,"Record"
, JOptionPane.QUESTION_MESSAGE);
System.out.println("FindRec: " + findrecs);
}
,210} 은}
질문에있는 코드를 [MCVE] (http://stackoverflow.com/help/mcve)로 편집하십시오. – fxm
자바와 자바 스크립트는 자바 스크립트와 제목이 같은 것은 아닙니다. 자바 – deme72
자바 스크립트와 관련이 있습니까? 어쩌면 OP가 JAVA를 쓰고 싶어했을까요? – briosheje