大学生作业:项目的开始

本文展示了一个使用JavaSwing开发的拼图游戏窗口,包含游戏主界面、登录和注册窗口的框架。游戏窗口设置了菜单栏,包含了重新游戏、重新登录和关闭游戏等选项,图片拼图分布在不同的JLabel上。目前登录和注册窗口还未实现功能。
摘要由CSDN通过智能技术生成

学习了这么久的java,应该要有独创的项目了,之前做了一个商品管理系统,在控制台上实现的,感觉做的一般般,这次做了一个窗口,用来写一个游戏——拼图游戏,昨天花了些时间,请大家过目

package Game1;

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

public class GameFrame extends JFrame {
    public  GameFrame() {
        this.setSize(500,500 );

        this.setTitle("快乐拼图1:赞美我主");
        this.setAlwaysOnTop(true);
        //让界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(3);
        //创建菜单
        //创建整个大长条
         JMenuBar jMenuBar=new JMenuBar();
         //创建菜单上的选项
        JMenu function=new JMenu("功能选项");
        JMenu aboutUs=new JMenu("关于我们");
        
        //创建条目
        JMenuItem replay=new JMenuItem("重新游戏");
        JMenuItem reLogin=new JMenuItem("重新登录");
        JMenuItem close=new JMenuItem("关闭游戏");

        JMenuItem account=new JMenuItem("公众号");
        //把条目放进选项
        function.add(replay);
        function.add(reLogin);
        function.add(close);

        aboutUs.add(account);
        //把选项放进大长条
        jMenuBar.add(function);
        jMenuBar.add(aboutUs);
        //把大长条放进窗口
        this.setJMenuBar(jMenuBar);
       

        //初始化图片

        ImageIcon imageIcon=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_20230510195104.jpg");
        ImageIcon imageIcon1=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_202305101951041.jpg");
        ImageIcon imageIcon2=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_20230510195105.jpg");
        ImageIcon imageIcon3=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_202305101951051.jpg");
        ImageIcon imageIcon4=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_202305101951052.jpg");
        ImageIcon imageIcon5=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_20230510195106.jpg");
        ImageIcon imageIcon6=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_202305101951061.jpg");
        ImageIcon imageIcon7=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_202305101951062.jpg");
        ImageIcon imageIcon8=new ImageIcon("C:\\Users\\86188\\IdeaProjects\\java\\Game\\ui\\picture\\拼图\\动物\\微信图片_20230510195107.jpg");

        //加一个容器,把图片放在这个容器里
        JLabel jLabel=new JLabel(imageIcon);
        JLabel jLabel1=new JLabel(imageIcon1);
        JLabel jLabel2=new JLabel(imageIcon2);
        JLabel jLabel3=new JLabel(imageIcon3);
        JLabel jLabel4=new JLabel(imageIcon4);
        JLabel jLabel5=new JLabel(imageIcon5);
        JLabel jLabel6=new JLabel(imageIcon6);
        JLabel jLabel7=new JLabel(imageIcon7);
        JLabel jLabel8=new JLabel(imageIcon8);
        //指定图片位置
        Panel p=new Panel();
        jLabel.setBounds(0,0,166,166);
        jLabel1.setBounds(166,0,166,166);
        jLabel2.setBounds(332,0,166,166);
        jLabel3.setBounds(0,166,166,166);
       jLabel4.setBounds(166,166,166,166);
        jLabel5.setBounds(332,166,166,166);
       jLabel6.setBounds(0,332,166,166);
        jLabel7.setBounds(166,332,166,166);
        jLabel8.setBounds(332,332,166,166);

        p.add(jLabel);
        p.add(jLabel1);
        p.add(jLabel2);
        p.add(jLabel3);
        p.add(jLabel4);
        p.add(jLabel5);
        p.add(jLabel6);
        p.add(jLabel7);
        p.add(jLabel8);
        p.setLayout(null);
        //把容器放在窗口里面

        this.add(p);

`
以上是游戏的主窗口。

import javax.swing.*;
import java.awt.*;
import java.lang.module.FindException;

public class DengluFrame extends JFrame {
    public   DengluFrame(){
        this.setVisible(true);
        this.setSize(488,430);
        this.setDefaultCloseOperation(3);
        this.setTitle("登录");
        this.setLocationRelativeTo(null);
    }
}

这是登录窗口,还没开始做。

public class ZhuceFrame extends JFrame {
    public  ZhuceFrame(){
        this.setSize(488,500);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setTitle("注册");
        this.setLocationRelativeTo(null);
    }
}

这是注册窗口,同样的也还没开始。

public class App {
    public static void main(String[] args) {
        //表示程序的主入口
        //想开启谁的界面,就创建谁的对象
        new GameFrame();
        new ZhuceFrame();
        new DengluFrame();
    }
}

这是界面,想要开启谁,就创建谁的对象。
做的很粗糙,还请大家提一下指导意见,我也会在csdn这个平台上更新我的项目的进展

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值