Unable to open JDialog from swing application when run from Applet

I have created a swing application, which runs fine when I run from desktop. The same application is now run from Applet.
class abc extends JApplet
{
 init()
{
 new Main()
}
}

Main class extends JFrame, it has JDialog opens for Login.
Now my problem is When I run Applet login dialog does not open up. I dont see any error in Applet console.

Any Thoughts?
harishalwalaAsked:
Who is Participating?
 
Pramod KumarConnect With a Mentor Commented:
Try this:


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

public class Login extends JApplet implements ActionListener
{
    JButton b;

  private Frame findParentFrame(){
    Container c = this;
    while(c != null){
      if (c instanceof Frame)
        return (Frame)c;

      c = c.getParent();
    }
    return (Frame)null;
  }

  public void init(){
    setLayout(new FlowLayout());
    b = new JButton("push me");
    b.addActionListener(this);
    add(b);
  }

  public void actionPerformed(ActionEvent e){
    Frame f = findParentFrame();
    if(f != null){
      JDialog d = new JDialog(f, "modalDialog", true);
      d.setLayout(new FlowLayout());
      d.add(new Label("hello"));
      d.pack();
      d.setLocation(300,100);
      d.show();
    }
  } 
}

Open in new window

0
 
for_yanCommented:
That may be due to some limitationm with the browser to open new windows - like pop-up blocking or something like that

Try in another browser.
0
 
harishalwalaAuthor Commented:
OK it works
0
 
harishalwalaAuthor Commented:
I got the way for finding solution, though this is not the actual solution I am looking for
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.