Java Reference
In-Depth Information
public void actionPerformed(ActionEvent event)
{
repaint();
}
public String getImageName()
{
return imageName;
}
public void setImageName(String name)
{
//Simple assignment for this property…
imageName = name;
}
public int getDelay()
{
return delay;
}
public void setDelay(int delayIn)
{
delay = delayIn;
//Also need to reset Timer delay for
//this property…
animTimer.setDelay(delay);
}
public Dimension getPreferredSize()
{
return new Dimension(140,120);
}
}
Using a manifest called AnimManifest2.mf and JAR fi le called Animation2.jar ,
the command to package the above bean into a JAR fi le is:
jar cmf AnimManifest2.mf Animation2.jar animBeans\
AnimBean2.class
10.3
Making Beans Respond to Events
We can add some sophistication to our bean by introducing buttons that will allow
the user to have greater control over the operation of the bean. As an example of
this, we shall introduce buttons into our animation bean that will allow the user
to stop and restart the animation whenever he/she wishes. In order to support this
additional functionality, we shall have to introduce methods stopAnimation and
Search WWH ::




Custom Search