• Post Reply Bookmark Topic Watch Topic
  • New Topic

Can you find a bug??

 
Paul McKenna
Ugly Redneck
Ranch Hand
Posts: 1006
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at the program below and then the error, I am confused .... are you??

Program:
--------
import java.awt.*;
import java.awt.event.*;
class myMouseAdapter extends MouseAdapter
{
MyButton b;
public myMouseAdapter(MyButton b1)
{
this.b = b1;
}
public void mousePressed(MouseEvent me)
{
b.setPressed(true);
b.repaint();
}
public void mouseReleased(MouseEvent me)
{
b.setPressed(false);
b.repaint();
}
}


public class MyButton extends Canvas
{
private boolean pressed;
myMouseAdapter ma = new myMouseAdapter(this);
public MyButton()
{
pressed = false;
setSize(100,50);
addMouseListener(ma);
}
public boolean getPressed()
{
return pressed;
}
public void setPressed(boolean flag)
{
this.pressed = flag;
}
public void paint(Graphics g)
{
Color blue = new Color(0,0,255);
Color white = new Color(255,255,255);
if (pressed)
{
g.setColor(blue);
g.fillRect(10,10,80,60);
}
else
{
g.setColor(white);
g.fillRect(10,10,80,60);
g.setColor(blue);
g.fillRect(11,11,79,59);
}
}
}

Error:
------
WARNING: Could not instantiate bean "MyButton" from JAR "D:\BDK1.1\jars\mybutton.jar"
We located the class "MyButton" OK
The class provides a public zero-arg constructor
But were unable to create an instance of the class because we
got an exception while doing Class.newInstance() :
java.lang.NoSuchMethodError: myMouseAdapter: method <init>(LMyButton V not found
The stack backtrace at the time of this exception is
java.lang.NoSuchMethodError: myMouseAdapter: method <init>(LMyButton V not found
at MyButton.<init>(MyButton.java:28)
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:241)
at sun.beanbox.JarInfo.diagnoseInstantiationException(JarInfo.java:308)
at sun.beanbox.JarInfo.getInstance(JarInfo.java:155)
at sun.beanbox.ToolBoxPanel.mousePressed(ToolBox.java:343)
at java.awt.Component.processMouseEvent(Component.java:3157)
at java.awt.Component.processEvent(Component.java:2999)
at java.awt.Container.processEvent(Container.java:990)
at java.awt.Component.dispatchEventImpl(Component.java:2394)
at java.awt.Container.dispatchEventImpl(Container.java:1035)
at java.awt.Component.dispatchEvent(Component.java:2307)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:287)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:92)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:83)
 
Joe Guzzardo
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic belongs in the AWT forum
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!