Help about JInternalFrame......
Hello everybody...
i need help about JInternalFrame i know how to use it and how to create it but im facing a little problem is that i want to check that Internal frame already open or not and also want to know when we open another internal frame it open but behind already open frame how to bring it infront....ill be thankful for givin me solution.....
[367 byte] By [
zerocooola] at [2007-11-26 12:40:10]

# 4
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class forZerocool extends JFrame implements ActionListener{
JMenuBar menuBar;
JMenu menuOpen;
JMenuItem itemOF1, itemOF2, itemOF3, itemOF4;
JDesktopPane desk;
forZerocool(){
setDefaultCloseOperation(EXIT_ON_CLOSE);
desk=new JDesktopPane();
menuBar=new JMenuBar();
menuOpen=new JMenu("Open");
menuOpen.setMnemonic(KeyEvent.VK_O);
menuBar.add(menuOpen);
itemOF1=new JMenuItem("Open Frame1",KeyEvent.VK_1);
itemOF2=new JMenuItem("Open Frame2",KeyEvent.VK_2);
itemOF3=new JMenuItem("Open Frame3",KeyEvent.VK_3);
itemOF4=new JMenuItem("Open Frame4",KeyEvent.VK_4);
menuOpen.add(itemOF1);
menuOpen.add(itemOF2);
menuOpen.add(itemOF3);
menuOpen.add(itemOF4);
itemOF1.addActionListener(this);
itemOF2.addActionListener(this);
itemOF3.addActionListener(this);
itemOF4.addActionListener(this);
setJMenuBar(menuBar);
setContentPane(desk);
setSize(600,600);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
/*The important thing is you set Name to the internal frame using
the setName method so we can easily find it out later whether it any frame in that name already exists*/
if(ae.getActionCommand().equals("Open Frame1")){
System.out.println("hai");
System.out.println("total components on the desk ="+desk.getComponentCount());
if(desk.getComponentCount()>0){
for(int i=0;i<desk.getComponentCount();i++){
System.out.println("comp"+i+"="+desk.getComponent(i).getName());
if(desk.getComponent(i).getName().equals("IFrame1")){
JOptionPane jop=new JOptionPane();
jop.showMessageDialog(this,"Frame already exists -will come to front");
JInternalFrame jf=(JInternalFrame)desk.getComponent(i);
jf.toFront();
try {
jf.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
return;
}
}
}
JInternalFrame iframe1=new JInternalFrame("Frame1",true,true,true,true);
iframe1.setName("IFrame1");
iframe1.setSize(200,100);
iframe1.setLocation(10,10);
iframe1.setVisible(true);
iframe1.toFront();
desk.add(iframe1);
try {
iframe1.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
else if(ae.getActionCommand().equals("Open Frame2")){
System.out.println("hai");
JInternalFrame iframe2=new JInternalFrame("Frame2",true,true,true,true);
iframe2.setName("IFrame2");
iframe2.setSize(200,100);
iframe2.setLocation(20,40);
iframe2.setVisible(true);
iframe2.toFront();
desk.add(iframe2);
try {
iframe2.setSelected(true);
} catch (java.beans.PropertyVetoException e) {}
}
}
public static void main(String args[]){
new forZerocool().setVisible(true);
}
}
I am wondering, out of the maximum ten marks, how many marks this program is going to fetch from you?>