无限循环? - 出现终止按钮

时间:2013-11-28 10:13:35

标签: java eclipse button terminate

关闭GUI后,我的程序仍在运行。我需要使用"终止"日食中的红色按钮。发生了什么?

只有两个班级

主要课程:

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。我用了#34; reader.close()&#34;所以我不知道什么是错的

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

1 个答案:

答案 0 :(得分:3)

你需要告诉你的JDialog关闭它时它应该做什么,否则它只会隐藏并且程序会继续运行。查看javadoc

JDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);