大家看看这个程序请教为什么图片不出来的呢

R344java 2009-04-25 11:20:51
//package com.cn;

import javax.swing.*;
import java.awt.*;

public class MyMun {

/**
* @param args
*/
JLabel backlabel = null;
JFrame chuangkou = null;

public MyMun() {
chuangkou = new JFrame("企业管理系统");
// JPanel jpanel1=new JPanel();
// jpanel1.setBackground(Color.red);
backlabel = new JLabel();
backlabel.setVerticalAlignment(SwingConstants.TOP);
backlabel.setHorizontalAlignment(SwingConstants.CENTER);
uptupian();
JDesktopPane desktoppane = new JDesktopPane();
desktoppane.add(backlabel, new Integer(Integer.MIN_VALUE));
JPanel jpanel2 = new JPanel();
jpanel2.setBackground(Color.black);
//JPanel jpanel3 = new JPanel();
//jpanel3.setBackground(Color.blue);

Container conn = chuangkou.getContentPane();
conn.add(desktoppane);
// conn.add(jpanel1,BorderLayout.SOUTH);
conn.add(jpanel2, BorderLayout.NORTH);
//conn.add(jpanel3, BorderLayout.CENTER);
JMenuBar caidanlan = new JMenuBar();
// caidanlan.setBorderPainted(falsh);
JMenu caidan = new JMenu("基础信息管理");
JMenu caidan1 = new JMenu("进货管理");
JMenu caidan2 = new JMenu("销售管理");
JMenu caidan3 = new JMenu("查询统计");
JMenu caidan4 = new JMenu("库存管理");
JMenu caidan5 = new JMenu("系统管理");
caidanlan.add(caidan);
caidanlan.add(caidan1);
caidanlan.add(caidan2);
caidanlan.add(caidan3);
caidanlan.add(caidan4);
caidanlan.add(caidan5);
chuangkou.setJMenuBar(caidanlan);
chuangkou.setSize(800, 600);
chuangkou.setVisible(true);
}

public void uptupian() {
if (backlabel != null) {
int backw = MyMun.this.chuangkou.getWidth();
int backh = chuangkou.getHeight();
backlabel.setSize(backw, backh);
backlabel.setText("<html><body><image width='" + backw
+ "'height='" + (backh) + "'src="
+ MyMun.this.getClass().getResource("a.jpg")
+ "'></img></body></html>");
}

}
static {
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e)
{e.printStackTrace();}
}
public static void main(String[] args) {
// TODO Auto-generated method stub

new MyMun();
}

}
...全文
104 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunny936 2009-05-07
  • 打赏
  • 举报
回复

和7楼的回帖一样。
jinxfei 2009-04-26
  • 打赏
  • 举报
回复

package com.cn;

import javax.swing.*;
import java.awt.*;

public class MyMun {

/**
* @param args
*/
JLabel backlabel = null;

JFrame chuangkou = null;

public MyMun() {
chuangkou = new JFrame("企业管理系统");
// JPanel jpanel1=new JPanel();
// jpanel1.setBackground(Color.red);

uptupian();
//JDesktopPane desktoppane = new JDesktopPane();
//desktoppane.add(backlabel, new Integer(Integer.MIN_VALUE));
JPanel jpanel2 = new JPanel();
jpanel2.setBackground(Color.black);
// JPanel jpanel3 = new JPanel();
// jpanel3.setBackground(Color.blue);

Container conn = chuangkou.getContentPane();
conn.add(backlabel);
// conn.add(jpanel1,BorderLayout.SOUTH);
conn.add(jpanel2, BorderLayout.NORTH);
// conn.add(jpanel3, BorderLayout.CENTER);
JMenuBar caidanlan = new JMenuBar();
// caidanlan.setBorderPainted(falsh);
JMenu caidan = new JMenu("基础信息管理");
JMenu caidan1 = new JMenu("进货管理");
JMenu caidan2 = new JMenu("销售管理");
JMenu caidan3 = new JMenu("查询统计");
JMenu caidan4 = new JMenu("库存管理");
JMenu caidan5 = new JMenu("系统管理");
caidanlan.add(caidan);
caidanlan.add(caidan1);
caidanlan.add(caidan2);
caidanlan.add(caidan3);
caidanlan.add(caidan4);
caidanlan.add(caidan5);
chuangkou.setJMenuBar(caidanlan);
chuangkou.setSize(800, 600);
chuangkou.setVisible(true);
}

public void uptupian() {
int backw = MyMun.this.chuangkou.getWidth();
int backh = chuangkou.getHeight();

backlabel = new JLabel(" <html> <body> <image width='" + backw
+ "'height='" + (backh) + "'src="
+ MyMun.this.getClass().getResource("a.jpg")
+ "'> </img> </body> </html>");
backlabel.setVerticalAlignment(SwingConstants.TOP);
backlabel.setHorizontalAlignment(SwingConstants.CENTER);

if (backlabel != null) {
backlabel.setSize(backw, backh);
}

}

static {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
// TODO Auto-generated method stub

new MyMun();
}

}

GeekZFZ 2009-04-26
  • 打赏
  • 举报
回复
关注下
lishigui 2009-04-26
  • 打赏
  • 举报
回复
最后把desktoppane.add(backlabel, new Integer(Integer.MIN_VALUE)) 改为desktoppane.add(backlabel);
lishigui 2009-04-26
  • 打赏
  • 举报
回复
最单间的方法就是在:JDesktopPane desktoppane = new JDesktopPane(); 后面加desktoppane.setLayout(new FlowLayout());
R344java 2009-04-26
  • 打赏
  • 举报
回复
可以帮我改一下程序么,最上面的代码,我还是不知道那个地方错了
R344java 2009-04-26
  • 打赏
  • 举报
回复
好的
lishigui 2009-04-26
  • 打赏
  • 举报
回复
是JDesktopPane的问题,你要好好的看看JDesktopPane的API哦!!!

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧