Why do I get this MyClass$1.class

Hello,

I have the following simple class:

******************************

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class HelloJava2

extends JComponent implements MouseMotionListener {

// Coordinates for the message

int messageX = 125, messageY = 95;

String theMessage;

public HelloJava2(String message) {

theMessage = message;

addMouseMotionListener(this);

}

public void paintComponent(Graphics g) {

g.drawString(theMessage, messageX, messageY);

}

public void mouseDragged(MouseEvent e) {

// Save the mouse coordinates and paint the message.

messageX = e.getX( );

messageY = e.getY( );

repaint( );

}

public void mouseMoved(MouseEvent e) {}

public static void main(String[] args) {

JFrame f = new JFrame("HelloJava2");

// Make the application exit when the window is closed.

f.addWindowListener(new WindowAdapter( ) {

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

});

f.setSize(300, 300);

f.getContentPane( ).add(new HelloJava2("Hello, Java!"));

f.setVisible(true);

}

}

******************************

I don't understand what the file called HelloJava2$1.class comes from. There is only one class definition in the source so where does this xx$1.class file comes from?

Thanks in advance,

Balteo.

[1494 byte] By [balteo] at [2007-9-27 19:34:29]
# 1
This is the class file created from your anonymous WindowAdapter class:f.addWindowListener(new WindowAdapter( ) {public void windowClosing(WindowEvent we) { System.exit(0); }});
dllawson1 at 2007-7-6 22:38:40 > top of Java-index,Archived Forums,Java Programming...
# 2

If you wrote it like this:

f.addWindowListener(new MyWindowCloser());

class MyWindowCloser extends WindowAdapter {

public void windowClosing(WindowEvent we) {

System.exit(0);

}

}

then it would be more obvious where the file came from.

These are basicly the same except one can be referenced.

dllawson1 at 2007-7-6 22:38:40 > top of Java-index,Archived Forums,Java Programming...
# 3
Thanks...
balteo at 2007-7-6 22:38:40 > top of Java-index,Archived Forums,Java Programming...