I am trying to display an image by clicking a button.
Can anyone tell me what is wrong with my code that it doesnt work.
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;
public class ImageLoading extends Frame implements ActionListener {
Image image;
Point origin = new Point(150, 150);
public ImageLoading(String title) {
super(title);
setSize(600, 600);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
System.exit(0);
}
});
setVisible(true);
Button l1 = new Button("search for:");
l1.setBounds(20,140,80,20);
add(l1);
l1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
System.out.println("Button Pressed");
try
{
image = Toolkit.getDefaultToolkit().getImage("1.gif");
}
catch(NullPointerException e)
{
}
}
public void paint(Graphics g) {
try{
g.drawImage(image, origin.x, origin.y, this);
}
catch(NullPointerException e)
{
}
}
public static void main(String[] args) {
ImageLoading imageLoading1 = new ImageLoading("Image Loading
Example");
}
}