Daniele

Here is some code I put together showing the three forms of inner
classes, this may help you understand what is going wrong.  I also
think your code didn't work because the was a logical error, with
the events somewhere.

Robert Fitzsimons
[EMAIL PROTECTED]

// Test.java

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

public class Test extends Frame {
        private Checkbox cb;

        public Test() {
                Button b;
                this.setLayout(new FlowLayout());
                this.setSize(200, 200);
                // Anonymous innerclass
                this.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                                System.exit(0);
                        }
                });
                // Local innerclass
                class ActionAdapter implements ActionListener {
                        public void actionPerformed(ActionEvent e) {
                                TestDialog td;
                                if(!Test.this.cb.getState()) {
                                        td = new TestDialog(Test.this,
                                                e.getActionCommand());
                                } else {
                                        td = new ExTestDialog(Test.this,
                                                e.getActionCommand());
                                }
                                td.setVisible(true);
                        }
                }
                ActionAdapter aa = new ActionAdapter();
                for(int i = 1; i < 6; i++) {
                        this.add(b = new Button("Test " + i));
                        b.addActionListener(aa);
                }
                this.add(cb = new Checkbox("Modal"));
                this.setVisible(true);
        }

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

        // Innerclass
        protected class TestDialog extends Dialog {
                public TestDialog(Frame frame, String title) {
                        super(frame, title);
                        this.setSize(100, 100);
                        // Anonymous innerclass
                        this.addWindowListener(new WindowAdapter() {
                                public void windowClosing(WindowEvent e) {
                                        TestDialog.this.dispose();
                                }
                        });
                }
        }

        // Extended innerclass
        protected class ExTestDialog extends TestDialog {
                public ExTestDialog(Frame frame, String title) {
                        super(frame, title);
                        this.setModal(true);
                }
        }
}

Reply via email to