I have some fairly simple code derived from code generated
by JBuilder 2.  I've stripped it down to make it easier to
see the problem.

The problem is that JBuilder generated code for an About type
dialog and when I run the code on Linux the dialog window
just flashes on the screen and then disappears.  In hunting
for the problem I found I could make the dialog window work
by just commenting out the setModal(true) call.  I think the
code should work as it is and did try a slightly older version
on my Windows 95 JDK 1.1.6 and it worked there so it seems to
be Linux specific.

Here are the source code files:

LinuxRetail.java:

import java.awt.*;
import java.util.*;

public class LinuxRetail {

    public LinuxRetail() {
        LinuxRetailFrame frame = new LinuxRetailFrame();
        frame.validate();

        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = frame.getSize();
        if (frameSize.height > screenSize.height)
            frameSize.height = screenSize.height;
        if (frameSize.width > screenSize.width)
            frameSize.width = screenSize.width;
        frame.setLocation((screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        new LinuxRetail();
    }
}


LinuxRetailFrame.java:

import java.util.*;
import java.awt.*;
import java.awt.event.*;

public class LinuxRetailFrame extends Frame {
    BorderLayout borderLayout1 = new BorderLayout();
    MenuBar menuBar1 = new MenuBar();
    Menu menuFile = new Menu();
    MenuItem menuFileExit = new MenuItem();
    Menu menuHelp = new Menu();
    MenuItem menuHelpAbout = new MenuItem();

    public LinuxRetailFrame() {
        try  {
            jbInit();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception  {
        this.setLayout(borderLayout1);
        this.setSize(new Dimension(400, 300));
        this.setTitle("LinuxRetail");

        menuFile.setLabel("File");
        menuFileExit.setLabel("Exit");
        menuFileExit.addActionListener(new ActionListener()  {
            public void actionPerformed(ActionEvent e) {
                fileExit_actionPerformed(e);
            }
        });

        menuHelp.setLabel("Help");
        menuHelpAbout.setLabel("About");
        menuHelpAbout.addActionListener(new ActionListener()  {
            public void actionPerformed(ActionEvent e) {
                helpAbout_actionPerformed(e);
            }
        });

        menuFile.add(menuFileExit);
        menuHelp.add(menuHelpAbout);
        menuBar1.add(menuFile);
        menuBar1.add(menuHelp);
        this.setMenuBar(menuBar1);
    }

    public void fileExit_actionPerformed(ActionEvent e) {
        System.exit(0);
    }

    public void helpAbout_actionPerformed(ActionEvent e) {
        LinuxRetailFrame_AboutBox dlg = new LinuxRetailFrame_AboutBox(this);
        dlg.setModal(true);
        dlg.show();
    }
}

And finally LinuxRetailFrame_AboutBox.java:

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.java.swing.*;

public class LinuxRetailFrame_AboutBox extends Dialog implements
ActionListener{
    Panel panel1 = new Panel();
    JButton button1 = new JButton();
    BorderLayout borderLayout1 = new BorderLayout();

    public LinuxRetailFrame_AboutBox(Frame parent) {
        super(parent);
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try  {
            jbInit();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        pack();
    }

    private void jbInit() throws Exception  {
        this.setTitle("About");
        setResizable(false);
        panel1.setLayout(borderLayout1);
        button1.setText("OK");
        button1.addActionListener(this);
        panel1.add(button1, BorderLayout.CENTER);
        this.add(panel1, null);
    }

    protected void processWindowEvent(WindowEvent e) {
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            dispose();
        }
        super.processWindowEvent(e);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == button1) {
            dispose();
        }
    }
}

Hopefully someone can help me track this bug down!

-- 
Brad Pepers
Linux Canada Inc.            Home of Linux products in Canada!
http://www.linuxcanada.com   Proud supporter of Cyclades, Red
[EMAIL PROTECTED]         Hat, and Caldera.

Reply via email to