Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WindowEvent in MouseEvent ??

Status
Not open for further replies.

aas1611

Programmer
Dec 14, 2001
184
DE
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):
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
 
Here is my solution.Suppose your main frame is called MainFrame,and your picture frame is called ViewerFrame. First of all, you need to add a static ArrayList to collect all of opened ViewerFrames:
public static ArrayList ViewerCollection;
and a method to add a menu item:
public void addMenuItem(String name){
//add a new menu item
}
Next, you need to have a static method to add a menu item.
ViewverFrame v1 = new ViewerFrame();
MainFrame.ViewerCollection.add(v1);
addMenuItem(v1.name); //could be a document name
When you want to close all the ViewerFrame down, you just need to call
((ViewerFrame)ViewerCollection.get(n)).setVisible(false);

It is only my opinion.

Thank you,

Chinese Java Faq Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top