Java学习笔记_Day8
拼图游戏设计主界面JFrame 最外层的窗体JMenuBar 最上面的菜单JLabel 管理图片和文字的容器有登录界面注册界面游戏界面游戏主界面初始化界面private void initJframe() { //宽高 this.setSize(603,680); this.setTitle(拼图游戏); //置顶 this.setAlwaysOnTop(true); //居中 this.setLocationRelativeTo(null); //关闭 this.setDefaultCloseOperation(3); }初始化菜单private void initJMenuBar() { //整个的菜单对象 JMenuBar jMenuBar new JMenuBar(); //创建菜单上两个选项的对象 JMenu functionJMenunew JMenu(功能); JMenu aboutJMenunew JMenu(关于我们); //创建下面的条目对象 JMenuItem replayItem new JMenuItem(重新游戏); JMenuItem reloginItem new JMenuItem(重新登录); JMenuItem closeItem new JMenuItem(关闭游戏); JMenuItem accountItem new JMenuItem(公众号); functionJMenu.add(replayItem); functionJMenu.add(reloginItem); functionJMenu.add(closeItem); aboutJMenu.add(accountItem); jMenuBar.add(functionJMenu); jMenuBar.add(aboutJMenu); //给整个界面设计菜单 this.setJMenuBar(jMenuBar); }创建界面的时候对界面的内容初始化new GameJframe();public GameJframe() { //初始化 initJframe(); //初始化菜单 initJMenuBar(); // 可见 this.setVisible(true); }效果