I am trying to write a application using LWUIT where I want a image to be displayed on click of a button. I have the following code. But I get an exception if the button is clicked twice. Please help me display the image without giving any exception.
final Form f = new Form("Static TAF");
Button TrackMe = new Button("TrackMe");
Image TrackMeicon = null;
TrackMeicon = Image.createImage("/hello/follow.jpeg");
final Label TrackMeLabel = new Label(TrackMeicon);
TrackMe.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
System.out.println("Removing the previous Images");
f.addComponent(TrackMeLabel);
}
});
Please Help
When you are clicking the button for the first time, image is added to the form. When you are clicking for the second time, that image already exists in the form. So, it will throw
"Component already exists"
exception.Your action listener should be