急!在线等!-java 界面的图出不来,拉一下框架就出了!
急!-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();
}
}