Link to home
Start Free TrialLog in
Avatar of faster
faster

asked on

self != this ?

Below is an applet and the corresponding HTML, basically it will invoke a message box.  It works fine but in Netscape, the following message will be shown in java console:

java.awt.Dialog.__hideDialog(): self != this (self = null; this = MessageBox[dialog4,343,227,140x146,layout=java.awt.BorderLayout,modal,title=title])
result=1

Seems that it is a warning message, can anyone explain it and tell me how to avoid this message?


import java.applet.*;
import java.awt.*;
import java.awt.event.*;  


public class TestApplet extends Applet
{
      public void test()
      {
            MessageBox msg = new MessageBox("title", "hello?", "yes", "no");
            int r = msg.getResult();
            System.out.println("result="+r);
      }
}


class MessageBox extends Dialog implements ActionListener {
      Button button1;
      Button button2;
      int r = 0;
 
      public MessageBox(String title, String message, String choice1, String choice2)
      {
            super(new Frame(), title, true);
   
            setLayout(new BorderLayout(5, 5));
   
            Panel p = new Panel();
            p.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 10));
            p.add("Center", new Label (message));
            add("Center", p);
   
            p = new Panel();
            p.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 10));
            if (choice1 != null) {
                  p.add(button1 = new Button(choice1));
                  button1.addActionListener(this);
            }
            if (choice2 != null) {
                  p.add(button2 = new Button(choice2));
                  button2.addActionListener(this);
            }
            add("South", p);  

            pack();

            Dimension sz = getToolkit().getScreenSize();
            setLocation((sz.width - getBounds().width) / 2, (sz.height - getBounds().height) / 2);

            setVisible(true);
      }
                                     

      public void actionPerformed(ActionEvent event)      {
            if (event.getSource() == button1)      {
                  r = 1;
                  setVisible(false);
            } else if (event.getSource() == button2)      {
                  r = 2;
                  setVisible(false);
            }
      }

      public int getResult()
      {
            return r;
      }
}


HTML:

<HTML>
<HEAD><TITLE>Add Item</TITLE>
<SCRIPT>

function test()
{
      document.testapplet.test();
}
</SCRIPT>

</HEAD>
<BODY BACKGROUND=2.jpg>
<FORM>
<BR>
<INPUT TYPE=BUTTON VALUE="Submit" onClick="test()">

</FORM></CENTER>
<APPLET CODE="TestApplet.class" NAME="testapplet" WIDTH=0 HEIGHT=0>
</APPLET>

<!--START OF FOOTER-->
<HR>
</BODY></HTML>
Avatar of vladi21
vladi21

try make r static :)
Avatar of faster

ASKER

it does not matter
ASKER CERTIFIED SOLUTION
Avatar of vladi21
vladi21

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of faster

ASKER

According to the source, it seems that it will complain when the dialog box to be closed is not the top one.  Do you have any better idea?

Thanks.

yes something like this
and i think i release version of product all trace must be removed :)