T
T
Time_Lords2014-05-22 23:28:14
Java
Time_Lords, 2014-05-22 23:28:14

JDialog not showing in browser?

There is this code:

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

class Hello extends JDialog {
  public Hello(JFrame jfr) {
    super(jfr, true);
    JButton ok = new JButton("ok");
    ok.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        setVisible(false);
      }	
    });
    setSize(100,100);
    pack();
    setVisible(true);
  }
}


public class test extends JApplet {

  public void init() {
    try {
      SwingUtilities.invokeAndWait(new Runnable () {
        public void run () {
          makeGui();
        }
      });
    }
    catch (Exception e) {
      System.out.println(e);
    }
  }

  public void makeGui () {
    setLayout(new FlowLayout());

    JButton tb = new JButton("test");
    add(tb);
    Hello hello = new Hello(null);
    setVisible(true);
  }
}


This applet is called from the html page of the view:
<!DOCTYPE html>
<html>
<body>
<applet code="test.class" width = 1000 height = 750>ehwlhewle </applet>
</body>
</html>


When I try to launch in the Firefox browser, I get just a white page, the Hello dialog box is not displayed. At the same time, dialog boxes called through JOptionPane.showMessageDialog work fine.

OS - Archlinux, Java - 1.8

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2014-05-23
@Time_Lords

1. You have not added anything to this dialog. Or rather, in its content pane . And don't forget the LayoutManager.
2. The call to setSize() is ignored because you called pack() after it.
Well, you don't need to call setVisible() in the constructor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question