combining into a single class

Discussion in 'Java' started by _.-=, Jul 30, 2003.

  1. _.-=

    _.-= Guest

    Hi!

    I know that there is definitely something wrong with this code but I'm
    trying to get both the class that creates a frame as well as the class that
    implements the WindowListener into one single class so the compiled code
    results in a single .class file. Could anyone help me out with this?

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

    class SymbiWin {

    public static void main(String args[]) {
    SymbiWin s1 = new SymbiWin();
    }

    SymbiWin() {
    Frame win1 = new Frame("win1");
    Label lab1 = new Label("lab1");
    win1.add(lab1);
    win1.addWindowListener(this);
    win1.pack();
    win1.show();
    }

    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }

    }
    _.-=, Jul 30, 2003
    #1
    1. Advertising

  2. "_.-=<[ { E v E r E a d y } ]>=-._" <> writes:

    You class shouldn't compile unless you change

    > class SymbiWin {


    into

    class SymbiWin extends WindowAdapter {
    Tor Iver Wilhelmsen, Jul 30, 2003
    #2
    1. Advertising

  3. _.-=

    Roedy Green Guest

    On Wed, 30 Jul 2003 20:02:06 +0400, "_.-=<[ { E v E r E a d y }
    ]>=-._" <> wrote or quoted :

    > WindowListener


    you can either implement the WindowListener interface in the main
    class, or you can create an anonymous WindowAdapter.

    See http://mindprod.com/jgloss/event11.html

    for sample code.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jul 30, 2003
    #3
  4. _.-=

    Roedy Green Guest

    On 30 Jul 2003 18:47:48 +0200, Tor Iver Wilhelmsen
    <> wrote or quoted :

    >class SymbiWin extends WindowAdapter {


    That is a strange thing to write since SymbWin is not logically a
    special kind of WindowAdapter. Normally it would be "implements
    WindowListener", or using an anonymous WindowAdapter.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Jul 30, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard
    Replies:
    2
    Views:
    576
    informant
    Feb 10, 2004
  2. girays
    Replies:
    5
    Views:
    346
    girays
    Apr 24, 2008
  3. Andy B
    Replies:
    1
    Views:
    295
    Evan Camilleri
    Jul 29, 2008
  4. Paul
    Replies:
    5
    Views:
    121
    Peter Szinek
    Apr 13, 2007
  5. ela
    Replies:
    12
    Views:
    334
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page