J
Jenny
Hi,
I need an applet loads and displays an image which is stored on server
side.
My applet works fine if I open the html file in my browser by "Open
File", but it doesn't load the image if my browser accesses it by URL
(such as http://127.0.0.1/test.html).
I think it is the problem of assigning the image file path, I am
frustrated by this problem. Can anyone help me? Thanks a lot.
This is the way my applet loads an image file:
private DisplayJAI display = null;
private PlanarImage image = null;
private JScrollPane scroll = null;
// assign fileName with absolute file path
String fileName="/var/www/localhost/htdocs/shape/006_2.jpg";
// I need JAI for image proccessing later
image = JAI.create("fileload", fileName);
scroll = new JScrollPane();
display = new DisplayJAI(image);
scroll.setViewportView(display);
This is my entire code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import com.sun.media.jai.widget.DisplayJAI;
import java.io.File;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
public class AppletROI extends JApplet {
private JButton
bFlower = new JButton("Flower"),
bLeaf = new JButton("Leaf"),
bFruit = new JButton("Fruit"),
bReset = new JButton("Reset ROI");
private ActionListener bl = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = ((JButton)e.getSource()).getText();
}
};
private DisplayJAI display = null;
private PlanarImage image = null;
private JScrollPane scroll = null;
String fileName="/var/www/localhost/htdocs/shape/006_2.jpg";
public void init() {
image = JAI.create("fileload", fileName);
scroll = new JScrollPane();
display = new DisplayJAI(image);
scroll.setViewportView(display);
bFlower.addActionListener(bl);
bLeaf.addActionListener(bl);
bFruit.addActionListener(bl);
bReset.addActionListener(bl);
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
JPanel cpFlower = new JPanel();
cpFlower.setLayout(new BorderLayout());
JPanel cpLeaf = new JPanel();
cpLeaf.setLayout(new BorderLayout());
JPanel cpFruit = new JPanel();
cpFruit.setLayout(new BorderLayout());
cpFlower.add(BorderLayout.NORTH, bFlower);
cpLeaf.add(BorderLayout.NORTH, bLeaf);
cpFruit.add(BorderLayout.NORTH, bFruit);
JPanel cpButtons = new JPanel();
cpButtons.setLayout(new FlowLayout());
cpButtons.add(cpFlower);
cpButtons.add(cpLeaf);
cpButtons.add(cpFruit);
cpButtons.add(bReset);
cp.add(BorderLayout.SOUTH, cpButtons);
cp.add(BorderLayout.CENTER, scroll);
}
}
I need an applet loads and displays an image which is stored on server
side.
My applet works fine if I open the html file in my browser by "Open
File", but it doesn't load the image if my browser accesses it by URL
(such as http://127.0.0.1/test.html).
I think it is the problem of assigning the image file path, I am
frustrated by this problem. Can anyone help me? Thanks a lot.
This is the way my applet loads an image file:
private DisplayJAI display = null;
private PlanarImage image = null;
private JScrollPane scroll = null;
// assign fileName with absolute file path
String fileName="/var/www/localhost/htdocs/shape/006_2.jpg";
// I need JAI for image proccessing later
image = JAI.create("fileload", fileName);
scroll = new JScrollPane();
display = new DisplayJAI(image);
scroll.setViewportView(display);
This is my entire code:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import com.sun.media.jai.widget.DisplayJAI;
import java.io.File;
import javax.media.jai.JAI;
import javax.media.jai.PlanarImage;
public class AppletROI extends JApplet {
private JButton
bFlower = new JButton("Flower"),
bLeaf = new JButton("Leaf"),
bFruit = new JButton("Fruit"),
bReset = new JButton("Reset ROI");
private ActionListener bl = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = ((JButton)e.getSource()).getText();
}
};
private DisplayJAI display = null;
private PlanarImage image = null;
private JScrollPane scroll = null;
String fileName="/var/www/localhost/htdocs/shape/006_2.jpg";
public void init() {
image = JAI.create("fileload", fileName);
scroll = new JScrollPane();
display = new DisplayJAI(image);
scroll.setViewportView(display);
bFlower.addActionListener(bl);
bLeaf.addActionListener(bl);
bFruit.addActionListener(bl);
bReset.addActionListener(bl);
Container cp = getContentPane();
cp.setLayout(new BorderLayout());
JPanel cpFlower = new JPanel();
cpFlower.setLayout(new BorderLayout());
JPanel cpLeaf = new JPanel();
cpLeaf.setLayout(new BorderLayout());
JPanel cpFruit = new JPanel();
cpFruit.setLayout(new BorderLayout());
cpFlower.add(BorderLayout.NORTH, bFlower);
cpLeaf.add(BorderLayout.NORTH, bLeaf);
cpFruit.add(BorderLayout.NORTH, bFruit);
JPanel cpButtons = new JPanel();
cpButtons.setLayout(new FlowLayout());
cpButtons.add(cpFlower);
cpButtons.add(cpLeaf);
cpButtons.add(cpFruit);
cpButtons.add(bReset);
cp.add(BorderLayout.SOUTH, cpButtons);
cp.add(BorderLayout.CENTER, scroll);
}
}