I have a Java class named Jtable
. When I run this class it works fine but if I run this class 10 times then 10 new windows open and I do not want that, I want that if I run this java class any number of time it should close previous windows.
My code is given below:
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Jtable extends JFrame {
DefaultTableModel model;
JTable table;
String col[] = {"Name","Address","Phone","hi","","","","","",""};
public static void main(String args[]) {
new Jtable().start();
}
public void start() {
model = new DefaultTableModel(col,9);
table = new JTable(model) {
@Override
public boolean isCellEditable(int arg0, int arg1) {
return false;
}
};
JScrollPane pane = new JScrollPane(table);
pane.setBounds(50,100,700,400);
String s="hello";
table.setValueAt(s,0,1);
add(pane);
setVisible(true);
setSize(500,400);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
pane.setLayout(null);
}
}