编了个简单的界面,可是图片显示不出来,路径和文件没绝对没有错误。麻烦大家看看哪出了问题!
public class Welcome extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public Welcome(){
JFrame welcome = new JFrame("系统");
welcome.setResizable(false);
Container container = welcome.getContentPane();
container.setLayout(null);
/*
* 管理员用户登录
*/
JMenuBar mbadmin = new JMenuBar();
mbadmin.setLayout(new FlowLayout(FlowLayout.LEFT));
mbadmin.setBounds(0, 0, 700, 30);
JMenu mnadmin = new JMenu("管理员入口");
JMenuItem mis = new JMenuItem("甲");
JMenuItem mih = new JMenuItem("乙");
JMenuItem miq = new JMenuItem("丙");
JMenuItem mix = new JMenuItem("丁");
mnadmin.add(mis);
mnadmin.add(mih);
mnadmin.add(miq);
mnadmin.add(mix);
mbadmin.add(mnadmin);
mbadmin.setOpaque(true);
/*
* 欢迎界面
*/
Icon cnimage = new ImageIcon("D:\\Documents\\Downloads\\getimage.jpg");
JLabel lbwelcome = new JLabel(cnimage,JLabel.CENTER);
JPanel pnwelcome = new JPanel();
pnwelcome.add(lbwelcome);
pnwelcome.setBounds(0, 100, 700, 300);
JButton btgoon = new JButton("继续");
JPanel pngoon = new JPanel();
pngoon.setLayout(new FlowLayout());
pngoon.add(btgoon);
pngoon.setBounds(0, 400, 700, 50);
container.add(mbadmin);
container.add(lbwelcome);
container.add(pngoon);
welcome.setBounds(250, 100, 700, 500);
welcome.show();
welcome.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}
------解决方案--------------------
路径有问题吧,我用过相对路径分隔符是“/”,你可以试试~~
------解决方案--------------------