不要用绝对路径,你可以试试,将图片打成pic.jar(picture/1.gif....), 引入pic.jarimport javax.swing.*; import java.awt.*; import picture.*;public class TJSplitPane extends JApplet { static int HORIZSPLIT = JSplitPane.HORIZONTAL_SPLIT; static int VERTSPLIT = JSplitPane.VERTICAL_SPLIT; boolean continuousLayout = true; Icon icon1 = new ImageIcon("1.gif"); Icon icon2 = new ImageIcon("2.gif"); Icon icon3 = new ImageIcon("3.gif"); public void init() { // 1. Create a label to display icon1 and add it to a scroll pane. JLabel label1 = new JLabel(icon1); JScrollPane topLeftComp = new JScrollPane(label1);
// 2. Create another lable to display icon2 and add it to another scroll pane. JLabel label2 = new JLabel(icon2); JScrollPane bottomLeftComp = new JScrollPane(label2);
// 3. Create a third label to display icon3 and add it to one more scroll pane. JLabel label3 = new JLabel(icon3); JScrollPane rightComp = new JScrollPane(label3);
// 4. Add the scroll panes displaying icon1 and icon2 to a split pane. JSplitPane splitPane1 = new JSplitPane(VERTSPLIT, continuousLayout, topLeftComp, bottomLeftComp); splitPane1.setOneTouchExpandable(true); // Provide a collapse/expand widget. splitPane1.setDividerSize(2); // Divider size. splitPane1.setDividerLocation(0.5); // Initial location of the divider.
// 5. Add the previous split pane and the scroll pane displaying // icon3 to an outer split pane. JSplitPane splitPane2 = new JSplitPane(HORIZSPLIT, continuousLayout, splitPane1, // left comp rightComp); splitPane2.setOneTouchExpandable(true); // Provide a collapse/expand widget. splitPane2.setDividerLocation(0.4); // divider size splitPane2.setDividerSize(2); // Initial location of the divider.
// 6. Add the outer split pane to the content pane of the applet. getContentPane().add(splitPane2); } }
new ImageIcon("C:\\1.gif");也不行
引入pic.jarimport javax.swing.*;
import java.awt.*;
import picture.*;public class TJSplitPane extends JApplet {
static int HORIZSPLIT = JSplitPane.HORIZONTAL_SPLIT;
static int VERTSPLIT = JSplitPane.VERTICAL_SPLIT;
boolean continuousLayout = true;
Icon icon1 = new ImageIcon("1.gif");
Icon icon2 = new ImageIcon("2.gif");
Icon icon3 = new ImageIcon("3.gif"); public void init() {
// 1. Create a label to display icon1 and add it to a scroll pane.
JLabel label1 = new JLabel(icon1);
JScrollPane topLeftComp = new JScrollPane(label1);
// 2. Create another lable to display icon2 and add it to another scroll pane.
JLabel label2 = new JLabel(icon2);
JScrollPane bottomLeftComp = new JScrollPane(label2);
// 3. Create a third label to display icon3 and add it to one more scroll pane.
JLabel label3 = new JLabel(icon3);
JScrollPane rightComp = new JScrollPane(label3);
// 4. Add the scroll panes displaying icon1 and icon2 to a split pane.
JSplitPane splitPane1 = new JSplitPane(VERTSPLIT,
continuousLayout,
topLeftComp,
bottomLeftComp);
splitPane1.setOneTouchExpandable(true); // Provide a collapse/expand widget.
splitPane1.setDividerSize(2); // Divider size.
splitPane1.setDividerLocation(0.5); // Initial location of the divider.
// 5. Add the previous split pane and the scroll pane displaying
// icon3 to an outer split pane.
JSplitPane splitPane2 = new JSplitPane(HORIZSPLIT,
continuousLayout,
splitPane1, // left comp
rightComp);
splitPane2.setOneTouchExpandable(true); // Provide a collapse/expand widget.
splitPane2.setDividerLocation(0.4); // divider size
splitPane2.setDividerSize(2); // Initial location of the divider.
// 6. Add the outer split pane to the content pane of the applet.
getContentPane().add(splitPane2);
}
}
将图片放到 .java一起的image文件。
就可以了。