0
關閉GUI後,我的程序仍在運行。我需要在eclipse中使用「終止」紅色按鈕。發生了什麼?無限while循環? - 終止按鈕出現
只有兩個班
主類:
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
public class zTestCombo2 extends JDialog // implements ActionListener
{
private JList<String> leftlist;
public zTestCombo2 (JFrame owner) // creates layout
{
setSize(1250,800);
setLayout(null);
setVisible(true);
zReader2.getValue();
leftlist = new JList<String>(zReader2.apps());
add(new JScrollPane(leftlist));
leftlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
JScrollPane scrollList = new JScrollPane(leftlist);
scrollList.setBounds(50,250,150,300);
add(scrollList);
}
public static void main(String[] args)
{
zTestCombo2 two = new zTestCombo2(null);
}}
和讀者,這主要類使用。我用「reader.close()」,所以我不明白什麼是錯
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class zReader2{
static ArrayList<String> lines = new ArrayList<String>();
static String[] lineArray ;
static int rowsnumber;
public static void getValue()
{
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("txt/zapp.txt"));
String line;
while((line = reader.readLine()) !=null){
lines.add(line);
rowsnumber++;
}
reader.close();
lineArray = new String[rowsnumber];
lines.toArray(lineArray);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getRow(int row){
return lines.get(row-1);
}
public static int getRowsNumber(){
return rowsnumber;
}
public static String[] apps(){
return lineArray;
}
}
如果我得到它的權利,你的問題看起來幾乎相同http://stackoverflow.com/questions/7191330/closing-a-java-program-properly-when-jdialog-is-the-main -window我會用Itay Maman給出的答案來做。 –