网络自学黑马,图片加载不出来
代码如下,
package pingtugame;
import javax.swing.*;
public class puzzleJFrame extends JFrame {
//主程序代码
public puzzleJFrame()
{
//初始化界面
initJFrame();
//初始化菜单
initJMenuBar();
//初始化图片
initimage();
//设置界面显示
setVisible(true);
}
private void initimage() {
//创建图片对象
ImageIcon Icon = new ImageIcon("C:/Users/86135/Desktop/JAVA/test/src/pingtugame/1.JPG");
//创建管理容器
JLabel Imagelable = new JLabel(Icon);
//图片对象添加到管理容器中
this.add(Imagelable);
}
private void initJMenuBar() {
//设置主菜单
JMenuBar JMenuBar1 = new JMenuBar();
//设置分菜单
JMenu Function = new JMenu("功能");//基础功能
JMenu aboutction = new JMenu("关于");//关于功能
//功能
JMenuItem replayitem = new JMenuItem("重新开始");
//小功能菜单名
JMenuItem reLoginitem = new JMenuItem("重新登录");
JMenuItem closeitem = new JMenuItem("关闭游戏");
//关于我们
JMenuItem officeitem = new JMenuItem("公众号");
//添加到目录(about)
aboutction.add(officeitem);
//添加到目录中(Function)
Function.add(replayitem);
Function.add(reLoginitem);
Function.add(closeitem);
//添加到主菜单(JB)
JMenuBar1.add(Function);
JMenuBar1.add(aboutction);
//设置主菜单
this.setJMenuBar(JMenuBar1);
}
private void initJFrame() {
//设置界面大小
this.setSize(603,680);
//设置程序标题
this.setTitle("puzzle game Single");
//设置界面始终置顶
this.setAlwaysOnTop(true);
//设置界面居中
this.setLocationRelativeTo(null);
//设置关闭模式
this.setDefaultCloseOperation(2);
this.setLayout(null);
}
}
main方法:
package pingtugame;
public class APPdate {
public static void main(String[] args) {
//主程序入口
// new LoginJFrame();
// new ResgisterJFrame();
new puzzleJFrame();
}
}