?
Solved

how to select and close the window in multiple window environment

Posted on 2003-03-31
10
Medium Priority
?
145 Views
Last Modified: 2010-03-31
i have written a program in which i am opening multiple window for different input files, know i want to close some of the selected windows, how to select and close the window. currently i am storing the window in some array or list, latter i am comparing the title with the selected item and deleting the matching window.
 can any body help me alternate method so that i can avoid storing it in array or list.
0
Comment
Question by:Virupaksha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 8237811
why not using Maps:
HashMap map = new HashMap();

map.put("title1", window1);
map.put("title2", window2);
map.put("title3", window3);
...
window = (Window) map.get(title2);
0
 

Author Comment

by:Virupaksha
ID: 8237826
i think if i use HashMap the memory will be same because i am using LinkedList.
   i am expecting some alternate which does not need to store or put window
0
 
LVL 35

Expert Comment

by:TimYates
ID: 8238183
There is know way (afaik) to enumerate child windows, like you can in Windows...

Venci75's answer is the fastest way I know of doing it
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Accepted Solution

by:
Gursel earned 375 total points
ID: 8238634
Well, there is a way.. Frame.getFrames() method returns
all frames created by the application...



0
 
LVL 35

Expert Comment

by:TimYates
ID: 8238983
oooh :-)  Cool :-)

Does it return dialogs and stuff too?

*wanders off to check the API*

>_<
0
 

Author Comment

by:Virupaksha
ID: 8244696
hello Gursel,
i got one thing to clarify, i used Frame.getFrames() but that returns static array,suppose if i call getFrames next time it shows the frames which i disposed which is a problem.
0
 

Expert Comment

by:Gursel
ID: 8244834
Hi Virupaksha,

There should be no reference to the frame that you dispose.. Disposing a frame only release native resources that is used by that frame.. And what is more, you have to call System.gc() after disposing.. Then Frame.getFrames() method returns all non-disposed frames.
0
 

Author Comment

by:Virupaksha
ID: 8245104
hi Gursel,
i tried with System.gc() it is still showing disposed windows.
0
 

Expert Comment

by:Gursel
ID: 8245631
Hi,

  Try the example . It works..



package deneme;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class Frame3 extends JFrame {
    JButton btnCreate = new JButton();
    JButton btnDispose = new JButton();
    JButton btnShow = new JButton();
    JTextArea txaResult = new JTextArea();
    Frame f1;
    public Frame3() {
        try {
            jbInit();
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        Frame3 frame3 = new Frame3();
        frame3.setBounds(100,100,500,500);

        frame3.setTitle("Frame0");
        frame3.show();
    }
    private void jbInit() throws Exception {
        btnCreate.setBounds(new Rectangle(35, 65, 79, 27));
        btnCreate.setText("Create");
        btnCreate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                btnCreate_actionPerformed(e);
            }
        });
        this.getContentPane().setLayout(null);
        btnDispose.setBounds(new Rectangle(127, 62, 103, 27));
        btnDispose.setText("Dispose");
        btnDispose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                btnDispose_actionPerformed(e);
            }
        });
        btnShow.setBounds(new Rectangle(240, 62, 126, 27));
        btnShow.setToolTipText("");
        btnShow.setText("Show Frames");
        btnShow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                btnShow_actionPerformed(e);
            }
        });
        txaResult.setToolTipText("");
        txaResult.setBounds(new Rectangle(34, 120, 304, 118));
        this.getContentPane().add(txaResult, null);
        this.getContentPane().add(btnDispose, null);
        this.getContentPane().add(btnShow, null);
        this.getContentPane().add(btnCreate, null);
    }

    void btnCreate_actionPerformed(ActionEvent e) {
        f1 = new Frame1();
        f1.setTitle("Frame1");
        f1.show();
    }

    void btnDispose_actionPerformed(ActionEvent e) {
        if (f1!= null)
            f1.dispose();
        f1=null;
       
    }

    void btnShow_actionPerformed(ActionEvent e) {
        System.gc();
        txaResult.setText(null);
        for (int i=0;i<Frame.getFrames().length;i++) {
            txaResult.setText(txaResult.getText()+"title " +i+"th frame is "+Frame.getFrames()[i].getTitle()+"\n");

        }
    }
}




0
 

Author Comment

by:Virupaksha
ID: 8251249
hi Gursel,
it's fine,it's working.
thanks once again.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question