Friday, 25 March 2011

web ex10:-


SOURCE CODE:

testFile.java:

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
public class testFile extends Applet implements ActionListener
{
Button b;
Image img;
char ch='N';
Label l = new Label();
Graphics g;
String xx;
private Frame findParentFrame()
{
Container c = this;
while(c != null)
{
if (c instanceof Frame)
return (Frame)c;
c = c.getParent();
}
return (Frame)null;
}
public void init()
{
setLayout(new FlowLayout());
b = new Button("Click here to set image");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
Frame f = findParentFrame();
if(f != null)
{
FileDialog d = new FileDialog(f);
d.show();
xx = d.getFile();
xx="Blue hills.jpg";
ch='Y';
img = Toolkit.getDefaultToolkit().createImage(xx);
l.setText(xx);
l.setBounds(10,15,100,20);
add(l);
repaint();
}}
public void paint(Graphics g)
{
if(ch=='Y')
g.drawImage(img, 0, 0, null);
}}



testFile.html:

<applet code="testFile.java" height=600 width=600>
</applet>

No comments:

Post a Comment