拼图小游戏的界面和菜单的搭建

package Puzzlegame.com.wxj.ui;

import javax.swing.*;

public class GameJframe extends JFrame {
//游戏主界面
public GameJframe(){
    //初始化界面
    initJFrame();

    //初始化菜单
    initJmenuBar();
    //让界面显示出来
   this.setVisible(true);
}

    private void initJmenuBar() {
        //创建整个菜单对象
        JMenuBar jMenuBar=new JMenuBar();
        //创建菜单上的两个选项的对象(功能 关于我们)
        JMenu functionJMenu=new JMenu("功能");
        JMenu aboutJMenu=new 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);
    }

    //初始化界面
    private void initJFrame() {
        //设置界面的宽高
        this.setSize(603,680);
        //设置界面的标题
        this.setTitle("拼图单机版 V1.0");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置游戏的关闭模式
        this.setDefaultCloseOperation(3);
    }
}
package Puzzlegame.com.wxj.ui;

import javax.swing.*;

public class LoginJframe extends JFrame {
//登录界面
    public LoginJframe(){
        this.setSize(488,430);
        //设置界面的标题
        this.setTitle("拼图 登录");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置游戏的关闭模式
        this.setDefaultCloseOperation(3);
        this.setVisible(true);
    }
}
package Puzzlegame.com.wxj.ui;

import javax.swing.*;

public class RegisterJframe extends JFrame {
//注册界面
    public RegisterJframe(){
        this.setSize(488,500);
        //设置界面的标题
        this.setTitle("拼图 注册");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置游戏的关闭模式
        this.setDefaultCloseOperation(3);
        this.setVisible(true);
    }
}
package Puzzlegame.com.wxj.ui;

public class App {
    public static void main(String[] args) {
        //程序的启动入口
  // new LoginJframe();
  // new RegisterJframe();
    new GameJframe();

    }
}

拼图小游戏的界面和菜单的搭建_第1张图片拼图小游戏的界面和菜单的搭建_第2张图片

你可能感兴趣的:(eclipse,intellij-idea)