急!在线等!-java 界面的图出不来,拉一下框架就出了!

haoyanbinok 2007-12-20 12:42:55
急!-java 界面的图出不来,拉一下框架就出了!

我的程序是这样的,你可用一个命名为main.gif图放同一目录下试试,
能运行就是不出图,拉一下框架就出了,是不大小没的设好啊??
高手看看!不胜感激!!
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class JF_mian {

JFrame jf;
//JPanel jp1;
JLabel j1;


private JMenuBar JMenuBar1=new JMenuBar();
private JMenu jm1=new JMenu();
private JMenu jm2=new JMenu();
private JMenu jm3=new JMenu();
private JMenu jm4=new JMenu();
private JMenuItem jtm1=new JMenuItem();
private JMenuItem jtm2=new JMenuItem();
private JMenuItem jtm3=new JMenuItem();
private JMenuItem jtm4=new JMenuItem();
private JMenuItem jtm5=new JMenuItem();

/*定义JF_mian()方法*/
public JF_mian() {
jf=new JFrame();
JPanel jp1=new JPanel();
jp1.setLayout(new FlowLayout());

jf.setLayout(new BorderLayout());

// jf.add(jp1,BorderLayout.CENTER);

/*ContentPane = (JPanel)this.getContentPane();
ContentPane.setLayout(null);
this.setTitle("学生信息管理系统");
this.setSize(400,300);*/


jf.setTitle("学生管理系统");
jf.setSize(900,600);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

/**********在菜单jm1上添加上2个子菜单*********/
jm1.setText("[学生管理]");
jtm1.setText("[学生信息]");
//jtm1.addActionListener(this);
jtm2.setText("[学生信息]");
//jtm2.addActionListener(this);
//jtm3.setText("[学生信息]");
//jtm3.addActionListener(this);

jm2.setText("【年级设置】");
jtm3.setText("【年级信息】");

jm3.setText("【年级设置】");
jtm4.setText("【年级信息】");

jm4.setText("【年级设置】");
jtm5.setText("【年级信息】");

//setJMenuBar(jMenuBar1);
jm1.add(jtm1);
jm1.add(jtm2);
jm2.add(jtm3);
jm3.add(jtm4);
jm4.add(jtm5);

JMenuBar1.add(jm1);
JMenuBar1.add(jm2);
JMenuBar1.add(jm3);
JMenuBar1.add(jm4);
JLabel jl;
ImageIcon icon = new ImageIcon("main.jpg");
jl= new JLabel(icon);
//jl.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
//jl.setBounds(0,0,700,500);
jp1.add(jl);
jf.add(JMenuBar1,BorderLayout.NORTH);

jf.add(jp1,BorderLayout.CENTER);
//loadBackgroundImage();
}

public static void main (String[] args) {
new JF_mian();


}

}
...全文
75 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
永远的明日 2007-12-21
  • 打赏
  • 举报
回复
同意楼上
craky 2007-12-20
  • 打赏
  • 举报
回复
jf.setVisible(true);

放到最后一行执行!!!
emperor_java 2007-12-20
  • 打赏
  • 举报
回复
LZ你把
jf.add(JMenuBar1,BorderLayout.NORTH);
改成
jf.setJMenuBar(JMenuBar1);
就可以了.
我没有加入图片进去试,你运行下下面的代码.

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

public class JF_mian {

JFrame jf;
//JPanel jp1;
JLabel j1;


private JMenuBar JMenuBar1=new JMenuBar();
private JMenu jm1=new JMenu();
private JMenu jm2=new JMenu();
private JMenu jm3=new JMenu();
private JMenu jm4=new JMenu();
private JMenuItem jtm1=new JMenuItem();
private JMenuItem jtm2=new JMenuItem();
private JMenuItem jtm3=new JMenuItem();
private JMenuItem jtm4=new JMenuItem();
private JMenuItem jtm5=new JMenuItem();

/*定义JF_mian()方法*/
public JF_mian() {
jf=new JFrame();
JPanel jp1=new JPanel();
jp1.setLayout(new FlowLayout());
// jf.add(jp1,BorderLayout.CENTER);
/*ContentPane = (JPanel)this.getContentPane();
ContentPane.setLayout(null);
this.setTitle("学生信息管理系统");
this.setSize(400,300);*/
/**********在菜单jm1上添加上2个子菜单*********/
jm1.setText("[学生管理]");
jtm1.setText("[学生信息]");
//jtm1.addActionListener(this);
jtm2.setText("[学生信息]");
//jtm2.addActionListener(this);
//jtm3.setText("[学生信息]");
//jtm3.addActionListener(this);

jm2.setText("【年级设置】");
jtm3.setText("【年级信息】");

jm3.setText("【年级设置】");
jtm4.setText("【年级信息】");

jm4.setText("【年级设置】");
jtm5.setText("【年级信息】");

//setJMenuBar(jMenuBar1);
jm1.add(jtm1);
jm1.add(jtm2);
jm2.add(jtm3);
jm3.add(jtm4);
jm4.add(jtm5);

JMenuBar1.add(jm1);
JMenuBar1.add(jm2);
JMenuBar1.add(jm3);
JMenuBar1.add(jm4);
JLabel jl;
ImageIcon icon = new ImageIcon("main.jpg");
jl= new JLabel(icon);
//jl.setBounds(0,0,icon.getIconWidth(),icon.getIconHeight());
//jl.setBounds(0,0,700,500);
jp1.add(jl);
//jf.add(JMenuBar1,BorderLayout.NORTH);
jf.setJMenuBar(JMenuBar1);
jf.add(jp1,BorderLayout.CENTER);
jf.setLayout(new BorderLayout());
jf.setTitle("学生管理系统");
jf.setSize(900,600);
jf.setVisible(true);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//loadBackgroundImage();
}

public static void main (String[] args) {
new JF_mian();


}

}

62,623

社区成员

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

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