Hello,
Situation:
I have a tree consists of files (the tree is similar to Windows Explorer). These files are pictures. When I double click them one by one, these files are opened in separate windows.
Problem:
I try to put all these opened windows into a linked list after I double click (to open) these files. The purpose of this is, I have a menu called "Close all opened windows". So when I click this menu, all opened windows will be closed at the same time.
How to get the references to these opened windows, so I can put them into a linked list?
My codes so far using MouseEvent (so far it works to open a file in a new window when double clicked):
Does anybody know how to do this?
Thanks!!
Andre
Situation:
I have a tree consists of files (the tree is similar to Windows Explorer). These files are pictures. When I double click them one by one, these files are opened in separate windows.
Problem:
I try to put all these opened windows into a linked list after I double click (to open) these files. The purpose of this is, I have a menu called "Close all opened windows". So when I click this menu, all opened windows will be closed at the same time.
How to get the references to these opened windows, so I can put them into a linked list?
My codes so far using MouseEvent (so far it works to open a file in a new window when double clicked):
Code:
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Window;
// Klasse, die auf Maus-Klicks reagiert.
public class TreeHandlerMaus extends MouseAdapter {
public void mouseClicked (MouseEvent e) {
JTree jt = (JTree)e.getComponent();
int selRow = jt.getRowForLocation(e.getX(), e.getY());
TreePath selPath = jt.getPathForLocation(e.getX(), e.getY());
if (selRow != -1) {
if(e.getClickCount() == 2) {
Knoten kn = (Knoten)selPath.getLastPathComponent();
if (kn instanceof Dokument) {
((Dokument)kn).ausgeben();
// HERE SHOULD BE THE CODES TO PUT THE OPENED WINDOWS INTO A LINKED LIST, RIGHT?
}
}
}
}
}
Does anybody know how to do this?
Thanks!!
Andre