-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.2.0
-
x86
-
windows_95
Name: diC59631 Date: 07/27/98
compile source code below, and run the application:
javac *.java
java bugtest
Select Help/About... from the menu to view a modal dialog.
Press OK to close the modal dialog -- the application is now hung.
=== bugtest.java ===
import java.awt.*;
import java.awt.event.*;
public class bugtest extends Frame {
public bugtest(){
//{{INIT_CONTROLS
setLayout(null);
setVisible(false);
setSize(805,555);
setForeground(new Color(0));
setBackground(new Color(16777215));
setTitle("bugtest");
//}}
//{{INIT_MENUS
mainMenuBar = new java.awt.MenuBar();
fileMenu = new java.awt.Menu("File");
miExit = new java.awt.MenuItem("Exit");
fileMenu.add(miExit);
mainMenuBar.add(fileMenu);
helpMenu = new java.awt.Menu("Help");
mainMenuBar.setHelpMenu(helpMenu);
miAbout = new java.awt.MenuItem("About..");
helpMenu.add(miAbout);
mainMenuBar.add(helpMenu);
setMenuBar(mainMenuBar);
//}}
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
miAbout.addActionListener(lSymAction);
miExit.addActionListener(lSymAction);
//}}
}
public void show(){
super.show();
}
static public void main(String args[]){
bugtest myBug= new bugtest();
myBug.show();
}
//{{DECLARE_MENUS
java.awt.MenuBar mainMenuBar;
java.awt.Menu fileMenu;
java.awt.MenuItem miExit;
java.awt.Menu helpMenu;
java.awt.MenuItem miAbout;
//}}
//inner calss for Window Listener
class SymWindow extends java.awt.event.WindowAdapter{
public void windowClosing(java.awt.event.WindowEvent event){
Object object = event.getSource();
if (object == bugtest.this)
bugtest_WindowClosing(event);
}
}
public void closeWindow(){
setVisible(false); // hide(); // hide the Frame
dispose(); // free the system resources
System.exit(0); // close the application
}
void bugtest_WindowClosing(java.awt.event.WindowEvent event){
setVisible(false); // hide(); // hide the Frame
dispose(); // free the system resources
System.exit(0); // close the application
}
//inner class for Menu Action Listener
class SymAction implements java.awt.event.ActionListener{
public void actionPerformed(java.awt.event.ActionEvent event){
Object object = event.getSource();
if (object == miAbout)
miAbout_Action(event);
else if (object == miExit)
miExit_Action(event);
}
}
void miAbout_Action(java.awt.event.ActionEvent event){
(new AboutDialog(this, true)).show();
}
void miExit_Action(java.awt.event.ActionEvent event){
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent(this /* (java.awt.Window)getParent() */, WindowEvent.WINDOW_CLOSING));
}
}
=== end bugtest.java ===
=== DialogAbout.java ===
/*
A basic extension of the java.awt.Dialog class
*/
import java.awt.*;
public class AboutDialog extends Dialog {
public AboutDialog(Frame parent, boolean modal)
{
super(parent, modal);
// This code is automatically generated by Visual Cafe when you add
// components to the visual environment. It instantiates and initializes
// the components. To modify the code, only use code syntax that matches
// what Visual Cafe can generate, or Visual Cafe may be unable to back
// parse your Java file into its visual environment.
if (false) {
//{{INIT_CONTROLS
setLayout(null);
setVisible(false);
setSize(249,150);
label1 = new java.awt.Label("About bugtest");
label1.setBounds(40,35,166,21);
add(label1);
okButton = new java.awt.Button();
okButton.setLabel("OK");
okButton.setBounds(95,85,66,27);
add(okButton);
setTitle("bugtest : About");
//}}
} // else our initialization follows:
setLayout(null);
setVisible(false);
setSize(getInsets().left + getInsets().right + 249,getInsets().top + getInsets().bottom + 150);
label1 = new java.awt.Label("bugtest");
label1.setBounds(getInsets().left + 40,getInsets().top + 35,166,21);
add(label1);
okButton = new java.awt.Button();
okButton.setLabel("OK");
okButton.setBounds(getInsets().left + 95,getInsets().top + 85,66,27);
add(okButton);
setTitle("bugtest : About");
//{{REGISTER_LISTENERS
SymWindow aSymWindow = new SymWindow();
this.addWindowListener(aSymWindow);
SymAction lSymAction = new SymAction();
okButton.addActionListener(lSymAction);
//}}
}
public AboutDialog(Frame parent, String title, boolean modal)
{
this(parent, modal);
setTitle(title);
}
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
// Only do this once.
if (fComponentsAdjusted)
return;
// Adjust components according to the insets
setSize(getInsets().left + getInsets().right + getSize().width, getInsets().top + getInsets().bottom + getSize().height);
Component components[] = getComponents();
for (int i = 0; i < components.length; i++)
{
Point p = components[i].getLocation();
p.translate(getInsets().left, getInsets().top);
components[i].setLocation(p);
}
// Used for addNotify check.
fComponentsAdjusted = true;
}
public synchronized void show()
{
Rectangle bounds = getParent().getBounds();
Rectangle abounds = getBounds();
setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
bounds.y + (bounds.height - abounds.height)/2);
super.show();
}
//{{DECLARE_CONTROLS
java.awt.Label label1;
java.awt.Button okButton;
//}}
// Used for addNotify redundency check.
boolean fComponentsAdjusted = false;
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == AboutDialog.this)
AboutDialog_WindowClosing(event);
}
}
void AboutDialog_WindowClosing(java.awt.event.WindowEvent event)
{
dispose();
}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event)
{
Object object = event.getSource();
if (object == okButton)
okButton_Clicked(event);
}
}
void okButton_Clicked(java.awt.event.ActionEvent event)
{
dispose();
}
}
=== end DialogAbout.java ===
(Review ID: 35713)
======================================================================
daniel.indrigo@Canada 1998-07-28
The customer added that removing the synchronized keyword from the show method in AboutDialog makes the problem go away.
======================================================================
- duplicates
-
JDK-4150178 Using synchronized with show() causes hang after dimissing a modal dialog.
-
- Closed
-