After closing the GUI, my program is still running. I need to use "terminate" red button in eclipse. What's happening?
There are only two classes
main class:
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);
}}
and the Reader, which main class uses. I used "reader.close()" so i don't get whats wrong
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;
}
}
You need to tell your JDialog what it should do when you close it, otherwise it will just hide and the program keeps running. Check the javadoc.
JDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);