Hi everyone,
I am trying to load images in the canvas but it seems nothing gets loaded at all but the program compiles without any errors. It is actually a simple image viewer and have tried almost everything. Anyway here is my program and i hope someone can help me see what i did wrong in my program and show me what i am doing wrong. My program is an application and not an applet.
My e-mail is freesoft_2000@yahoo.com
Here is my program
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class Images implements ActionListener, WindowListener
{
Frame fr = new Frame ("Frame");
Label Label1 = new Label("Label1 ");
Button Button1 = new Button("Button 1");
Canvas Canvas1 = new Canvas();
FileDialog fd = new FileDialog(fr,"Open", FileDialog.LOAD);
Image Image1;
void initialize ()
{
fr.setSize(500,500);
fr.setLocation(300,300);
fr.setBackground(Color.lightGray);
fr.setLayout(new FlowLayout());
fr.add(Label1);
fr.add(Button1);
Canvas1.setSize(1000,1000);
fr.add(Canvas1);
fr.addWindowListener(this);
Button1.addActionListener(this);
fr.show();
}
void imageload ()
{
fd.show();
if(fd.getFile() == null)
{
Label1.setText("You have not chosen any image files yet");
}
else
{
String d = (fd.getDirectory() + fd.getFile());
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image1 = toolkit.getImage(d);
}
}
public void paint(Graphics g)
{
g.drawImage(Image1, 0, 0, 1000, 1000, Canvas1);
}
public void windowClosing(WindowEvent e)
{
// Use fr.hide(); for subsequent forms in multi form applications
System.exit(0);
}
public void windowActivated(WindowEvent e)
{
}
public void windowClosed(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
}
public void windowIconified(WindowEvent e)
{
}
public void windowOpened(WindowEvent e)
{
}
public void actionPerformed(ActionEvent event)
{
Button b = (Button)event.getSource();
if(b == Button1)
{
imageload();
}
}
public static void main(String args[])
{
Images a = new Images();
a.initialize();
}
}
I apologize for the length of the program in advance
Thank You
Yours Sincerely
Richard West