• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 535
  • Last Modified:

JFrame pop up from Applet

Hi,
I have an applet. Into this applet there is a button. When I press this button I want to pop up a new Jframe.
At the moment this don't happen. Where is the problem? (I also would like to set it modal(true) )

myJframe class
------------------------------------------

public class myFrame extends javax.swing.JFrame {
   
    public myFrame() {
        initComponents();
    }
   
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
       
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    }

   
   private javax.swing.JPanel jPanel1;
   
}


on release button action into the applet
-------------------------------------------------------

      myFrame frame = new myFrame();
      myFrame.show();
0
test75
Asked:
test75
  • 14
  • 13
2 Solutions
 
CEHJCommented:
Have you added the ActionListener (not apparent from code)
0
 
test75Author Commented:
yes, consider the action listener for that ok
but when I copied the code I wrote something wrong:
 myFrame.show();
 instead of frame.show();

jButton15.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                 myFrame frame = new myFrame();
                frame.show();
            }
  });
0
 
CEHJCommented:
Why would you add a MouseListener to the button instead of an ActionListener?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
jButton15.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
            new myFrame().show();
      }
});  
0
 
test75Author Commented:
I did so but the frame still don't appear.  

jButton15.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {
          new myFrame().show();
     }
});

I tried with this and the frame appear
new JFrame().show();

is there any problem with the class myFrame()?
0
 
CEHJCommented:
>>
I tried with this and the frame appear

new JFrame().show();
>>

There's no difference in the code i gave you. The only thing wrong is possibly you're not clicking on the button you think you are. It would help if you give your buttons more self-documenting names
0
 
test75Author Commented:
a specification:
the button which should pop up myFrame is not directly embeded into the applet, but it is into n interface which extends JPanel which is embedded into the applet.  
I don't know I than can affect myFrame behaviour.
0
 
test75Author Commented:
you mean that the problem is not into:

public class myFrame extends javax.swing.JFrame {
...
}
0
 
CEHJCommented:
>>but it is into n interface which extends JPanel

Shouldn't matter. Can you possibly post a link to your applet and any other code you're running?

>> you mean that the problem is not into:

No. That looks OK
0
 
test75Author Commented:
>> Can you possibly post a link to your applet.
Sorry but I can't (it is part of an entreprise reserved area)

What I don't understand, is that with that button I have no problem to handle any action
i.e. by changing new myFrame().show(); with new JFrame().show(); all work fine
so I will exclude any problem with that button and its related action.
0
 
CEHJCommented:
Maybe your sizing is wrong. Try

jButton15.addActionListener(new ActionListener() {
     public void actionPerformed(ActionEvent e) {
         myFrame f =  new myFrame();
         f.setSize(200, 200);
         f..show();
     }
});
0
 
CEHJCommented:
(typo last line there  two dots should be one)
0
 
test75Author Commented:
I still have the same problem...
If it was a problem of dimensions or if its is hidden I think I should at least see it as a new window on windows applications bar (I'am on windows platform)
0
 
CEHJCommented:
I'm not sure about your last supposition. Comment out

>>
      java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
>>

and recompile using the code i last posted without the typo
0
 
objectsCommented:
Problem must be in your myFrame class can you post it
0
 
test75Author Commented:
>> can you post it
It is posted at the top of the page
0
 
test75Author Commented:
>>
      java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
>>

I firstly used pack(); with the same result. nothing appears.
0
 
CEHJCommented:
Make sure you're running the code you think you are. Recompile:

>>
public myFrame() {
        initComponents();
    }
>>

thus

public myFrame() {
    System.out.println("myFrame() called");
    initComponents();
}
0
 
test75Author Commented:
>> Make sure you're running the code you think you are.
yes, the class run
i.e. MyFrame change the text of the button which launch MyFrame (parent.jButton15.setText("hi");)
0
 
CEHJCommented:
Are you running this in a browser? WHat happens in appletviewer?
0
 
test75Author Commented:
>>Are you running this in a browser?
yes in a browser.

I wrote this small applet as a test:
--------------------------------------------------------------------------------------
package test;
public class NewJApplet extends javax.swing.JApplet {
    public void init() {
      initComponents();
   }
    private void initComponents() {
        jButton1 = new javax.swing.JButton();
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, java.awt.BorderLayout.CENTER);
    }
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
       new NewJFrame().show();
    }
    private javax.swing.JButton jButton1;
}

-------------------------------------------------------------------------------------------
and the JFrame class

package test;
public class NewJFrame extends javax.swing.JFrame {
   
    public NewJFrame() {
        initComponents();
    }
    private void initComponents() {                          
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        pack();
    }                        
}

-------------------------------------------------------------------------
If I run it with appletviewer all works fine but if I run it into a browser the frame don't appear.
the browser use the plug-in Version 1.5.0 (build 1.5.0_02-b09)... maybe it has something to do...



0
 
CEHJCommented:
Well in that particular case, the frame has zero dimensions
0
 
test75Author Commented:
even so - the smae result - microsoft service pack 2?

public class NewJFrame extends javax.swing.JFrame {
    public NewJFrame() {
        initComponents();
    }
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jPanel1.setPreferredSize(new java.awt.Dimension(400, 400));
        jButton1.setText("jButton1");
        jPanel1.add(jButton1);
        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
        pack();
    }
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
}
0
 
CEHJCommented:
But you should still see something unless you're unobservant ;-) Make sure your browser is not blocking 'pop-up' windows
0
 
test75Author Commented:
>> Make sure your browser is not blocking 'pop-up' windows
no it's not blocked (I also tried with firefox)

-------------------------------------------------------------------------------
meanwhile I opted for another solution.
I give you the points for the time you invested, if you will find an answear let me know.

0
 
CEHJCommented:
I'm not happy taking all the points. Some are fine. If it's any consolation it doesn't work for me with plugin 1.5 either ;-)
0
 
test75Author Commented:
I will split the points. When I'll have some time I'll test that on other platforms (i.e. linux). In any case I think that Bill has something to do with that.
If this has to do with any security reason I don't kwon why this is allowed: new JFrame().show();  
0
 
CEHJCommented:
OK
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 14
  • 13
Tackle projects and never again get stuck behind a technical roadblock.
Join Now