A
Avraham
Hello,
This is my newbe simplest program.
It compiles OK.
When I try to run it with NETBEENS I get error messages (see bellow),
When I run it in another IDE (JCreator) it runs. (only it won't close
the window. Wish I knew why..).
Please help on both issues.
Thanks, Avraham gutbir1 @ 013.net.il
------------------------------------
import java.awt.*;
import java.awt.event.*;
public class ButtonDemo extends Frame{
Button b;
public ButtonDemo(){ // constructor
super ();
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.setBackground(Color.green);
b=new Button("Press me and I will blush");
b.setSize(100,100); // did not work !
// for button action :
b.addActionListener(new MyButtonHandler());
this.add(b);
this.setSize(300,300);
// for window closing :
this.addWindowListener(new MyWindowListener());
//this.setResizable(false);
}
// inner class for button listener :
class MyButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
Button bb=(Button)e.getSource();
bb.setLabel("Thanks");
bb.setBackground(Color.yellow);
ButtonDemo.this.setBackground(Color.red); // relates to frame
}
}
// inner class for window listener :
class MyWindowListener extends WindowAdapter{
public void WindowClosing(WindowEvent e){
System.exit(0); // exit from application
System.out.println("heh");
}
}
public static void main(String[] args) {
ButtonDemo wind=new ButtonDemo();
wind.setVisible(true);
}
}
//----------------------------- end if program -----------------------
java.lang.NoClassDefFoundError: ButtonDemo/ButtonDemo (wrong name:
ButtonDemo)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
Exception in thread "main"
This is my newbe simplest program.
It compiles OK.
When I try to run it with NETBEENS I get error messages (see bellow),
When I run it in another IDE (JCreator) it runs. (only it won't close
the window. Wish I knew why..).
Please help on both issues.
Thanks, Avraham gutbir1 @ 013.net.il
------------------------------------
import java.awt.*;
import java.awt.event.*;
public class ButtonDemo extends Frame{
Button b;
public ButtonDemo(){ // constructor
super ();
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.setBackground(Color.green);
b=new Button("Press me and I will blush");
b.setSize(100,100); // did not work !
// for button action :
b.addActionListener(new MyButtonHandler());
this.add(b);
this.setSize(300,300);
// for window closing :
this.addWindowListener(new MyWindowListener());
//this.setResizable(false);
}
// inner class for button listener :
class MyButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent e){
Button bb=(Button)e.getSource();
bb.setLabel("Thanks");
bb.setBackground(Color.yellow);
ButtonDemo.this.setBackground(Color.red); // relates to frame
}
}
// inner class for window listener :
class MyWindowListener extends WindowAdapter{
public void WindowClosing(WindowEvent e){
System.exit(0); // exit from application
System.out.println("heh");
}
}
public static void main(String[] args) {
ButtonDemo wind=new ButtonDemo();
wind.setVisible(true);
}
}
//----------------------------- end if program -----------------------
java.lang.NoClassDefFoundError: ButtonDemo/ButtonDemo (wrong name:
ButtonDemo)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
Exception in thread "main"