?
Solved

self != this ?

Posted on 1999-11-05
5
Medium Priority
?
338 Views
Last Modified: 2012-05-04
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>
0
Comment
Question by:faster
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:vladi21
ID: 2185674
try make r static :)
0
 
LVL 7

Author Comment

by:faster
ID: 2185764
it does not matter
0
 
LVL 7

Accepted Solution

by:
vladi21 earned 400 total points
ID: 2185841
Its just trace :)

from Netscape\Communicator\Program\Java\Classes\java40.jar

// Decompiled by Jad v1.5.7. Copyright 1997-99 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3)
// Source File Name:   Dialog.java

package java.awt;

import java.awt.peer.ComponentPeer;
import java.awt.peer.DialogPeer;
import java.io.PrintStream;
import java.util.Enumeration;
import java.util.Vector;
import sun.awt.SunToolkit;

// Referenced classes of package java.awt:
//            Window, Frame, Container, Toolkit,
//            Dimension, Component

public class Dialog extends Window
{

    public Dialog(Frame frame)
    {
        this(frame, "", false);
    }

    public Dialog(Frame frame, boolean flag)
    {
        this(frame, "", flag);
    }

    public Dialog(Frame frame, String s)
    {
        this(frame, s, false);
    }

    public Dialog(Frame frame, String s, boolean flag)
    {
        super(frame);
        resizable = true;
        if(frame == null)
        {
            throw new IllegalArgumentException("null parent frame");
        }
        else
        {
            name = "dialog" + nameCounter++;
            title = s;
            modal = flag;
            return;
        }
    }

    public void addNotify()
    {
        if(peer == null)
            peer = getToolkit().createDialog(this);
        super.addNotify();
    }

    public boolean isModal()
    {
        return modal;
    }

    public void setModal(boolean flag)
    {
        modal = flag;
    }

    public String getTitle()
    {
        return title;
    }

    public synchronized void setTitle(String s)
    {
        title = s;
        DialogPeer dialogpeer = (DialogPeer)peer;
        if(dialogpeer != null)
            dialogpeer.setTitle(s);
    }

    public void show()
    {
        super.show();
    }

    protected void __showDialog()
    {
        synchronized(Component.LOCK)
        {
            if(parent != null && parent.getPeer() == null)
                parent.addNotify();
            if(peer == null)
            {
                addNotify();
                Dimension dimension = getMinimumSize();
                if(dimension.width > width || dimension.height > height)
                    setSize(dimension);
            }
            validate();
        }
        if(visible)
        {
            toFront();
            return;
        }
        visible = true;
        if(isModal())
        {
            Window awindow[] = SunToolkit.getTopLevelWindows();
            if(awindow == null)
            {
                Frame frame = (Frame)getParent();
                int j = frame.ownedWindows.size() + 1;
                awindow = new Window[j];
                frame.ownedWindows.copyInto(awindow);
                awindow[j - 1] = frame;
            }
            m_disabledWindows = new Vector(awindow.length);
            for(int i = 0; i < awindow.length; i++)
            {
                Window window = awindow[i];
                if(window != this && window.isVisible() && window.isEnabled())
                {
                    m_disabledWindows.addElement(window);
                    window.enabled = false;
                    window.getPeer().setEnabled(false);
                }
            }

            m_previousModalDialog = SunToolkit.swapTopModalDialog(this);
        }
        peer.show();
    }

    void __hideDialog()
    {
        if(!visible)
            return;
        if(isModal())
        {
            if(m_disabledWindows == null)
                return;
            Dialog dialog = SunToolkit.swapTopModalDialog(m_previousModalDialog);
            if(dialog != this)
                System.out.println("java.awt.Dialog.__hideDialog(): self != this (self = " + dialog + "; this = " + this + ")");
            if(m_previousModalDialog != null)
                m_previousModalDialog.toFront();
            Window window;
            for(Enumeration enumeration = m_disabledWindows.elements(); enumeration.hasMoreElements(); window.getPeer().setEnabled(true))
            {
                window = (Window)enumeration.nextElement();
                window.enabled = true;
            }

        }
    }

    public boolean isResizable()
    {
        return resizable;
    }

    public synchronized void setResizable(boolean flag)
    {
        resizable = flag;
        DialogPeer dialogpeer = (DialogPeer)peer;
        if(dialogpeer != null)
            dialogpeer.setResizable(flag);
    }

    protected String paramString()
    {
        String s = super.paramString() + (modal ? ",modal" : ",modeless");
        if(title != null)
            s = s + ",title=" + title;
        return s;
    }

    boolean resizable;
    boolean modal;
    String title;
    private static final String base = "dialog";
    private static int nameCounter;
    private static final long serialVersionUID = 0x522b5ba60a3fb00dL;
    private Vector m_disabledWindows;
    private Dialog m_previousModalDialog;
}


0
 
LVL 7

Author Comment

by:faster
ID: 2186440
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.

0
 
LVL 7

Expert Comment

by:vladi21
ID: 2186520
yes something like this
and i think i release version of product all trace must be removed :)
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month4 days, 20 hours left to enroll

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question