为什么第一个代码有效
public class SortingWords {
//global variables
public static int count = 0;
public static void main(String [ ] commandlineArguments){
String[ ] array = readFileReturnWords(commandlineArguments[0]);
sortAndPrintArray(array, commandlineArguments[0]);
if (commandlineArguments.length != 1) {
System.out.println("Please enter the INPUT file name as the 1st commandline argument.");
System.out.println("Please enter exactly one (1) commandline arguments.");
// Immediately terminates program
System.exit(1);
}// end of if
// if no commandline argument errors, continue program
String inputFile = commandlineArguments[0];
}
/**
* readFileReturnWords - Used To Read from File & Store Each Word in Array
*
* @param inputFile is the name of the file
*/
public static String [] readFileReturnWords(String inputFile){
//create array
//read one word at a time from file and store in array
//return the array
//error checking for commandline input
//make an array of Strings
final Integer MAX = 100;
String array[] = new String [MAX];
String element = "";
// read items from file & store in array
//connects to file
File file = new File(inputFile);
Scanner scanFile = null;
try {
scanFile = new Scanner(file);
}
catch (FileNotFoundException exception) {
// Print error message.
System.out.print("ERROR: File not found for " + inputFile);
}
// if made connection to file, read from file
if (scanFile != null) {
String firstLineOfFile = "";
firstLineOfFile = scanFile.nextLine();
// keeps looping if file has more lines..
while (scanFile.hasNextLine()) {
// get a line of text..
String line = scanFile.nextLine();
// divides each line by commas
Scanner lineInput = new Scanner(line).useDelimiter("\\s*");
element = lineInput.next();
array.add(element);
count ++;
}
}
System.out.println("Alphabetical (ASCII) listing of words in file: ");
System.out.println("Index Element");
for(int i=0;i<MAX;i++){
System.out.print("Index = " );
System.out.printf("%-7d", i);
System.out.print(", Element = ");
System.out.println(array[i]);
}
return array;
}
但是这第二个代码并没有显示mw窗口
MessageBox.Show("No Applicants\nFirst Add applicants with dataentryaccount");
MainWindow mw = new MainWindow();
mw.Show();
this.Close();
虽然在逐行调试时会执行所有这些行。
答案 0 :(得分:1)
当前执行块的EventHandler or procedure
有更多代码要执行
您尚未调用return
来停止执行当前过程。
Close()
只是另一个不会立即删除表单的函数。所以它继续执行当前代码。
请查看this答案了解详情。