编程语言用 Java 开发一个打飞机小游戏(附完整源码)

2023-11-18

编程语言用 Java 开发一个打飞机小游戏(附完整源码)

上图

写在前面

技术源于分享,所以今天抽空把自己之前用java做过的小游戏整理贴出来给大家参考学习。java确实不适合写桌面应用,这里只是通过这个游戏让大家理解oop面向对象编程的过程,纯属娱乐。代码写的很简单,也很容易理解,并且注释写的很清楚了,还有问题,自己私下去补课学习。

完整代码

敌飞机

import java.util.Random;


 敌飞机: 是飞行物,也是敌人

public class Airplane extends FlyingObject implements Enemy {
    private int speed = 3;  //移动步骤

    /** 初始化数据 */
    public Airplane(){
        this.image = ShootGame.airplane;
        width = image.getWidth();
        height = image.getHeight();
        y = -height;          
        Random rand = new Random();
        x = rand.nextInt(ShootGame.WIDTH - width);
    }

    /** 获取分数 */
    @Override
    public int getScore() {  
        return 5;
    }

    /** //越界处理 */
    @Override
    public     boolean outOfBounds() {   
        return y>ShootGame.HEIGHT;
    }

    /** 移动 */
    @Override
    public void step() {   
        y += speed;
    }
}

分数奖励

/** 
 * 奖励 
 */  
public interface Award {  
    int DOUBLE_FIRE = 0;  //双倍火力  
    int LIFE = 1;   //1条命  
    /** 获得奖励类型(上面的0或1) */  
    int getType();  
}

蜜蜂

import java.util.Random;  

/** 蜜蜂 */  
public class Bee extends FlyingObject implements Award{  
    private int xSpeed = 1;   //x坐标移动速度  
    private int ySpeed = 2;   //y坐标移动速度  
    private int awardType;    //奖励类型  

    /** 初始化数据 */  
    public Bee(){  
        this.image = ShootGame.bee;  
        width = image.getWidth();  
        height = image.getHeight();  
        y = -height;  
        Random rand = new Random();  
        x = rand.nextInt(ShootGame.WIDTH - width);  
        awardType = rand.nextInt(2);   //初始化时给奖励  
    }  

    /** 获得奖励类型 */  
    public int getType(){  
        return awardType;  
    }  

    /** 越界处理 */  
    @Override  
    public boolean outOfBounds() {  
        return y>ShootGame.HEIGHT;  
    }  

    /** 移动,可斜着飞 */  
    @Override  
    public void step() {        
        x += xSpeed;  
        y += ySpeed;  
        if(x > ShootGame.WIDTH-width){    
            xSpeed = -1;  
        }  
        if(x < 0){  
            xSpeed = 1;  
        }  
    }  
}

子弹类:是飞行物体

/** 
 * 子弹类:是飞行物 
 */  
public class Bullet extends FlyingObject {  
    private int speed = 3;  //移动的速度  

    /** 初始化数据 */  
    public Bullet(int x,int y){  
        this.x = x;  
        this.y = y;  
        this.image = ShootGame.bullet;  
    }  

    /** 移动 */  
    @Override  
    public void step(){     
        y-=speed;  
    }  

    /** 越界处理 */  
    @Override  
    public boolean outOfBounds() {  
        return y<-height;  
    }  

}

敌人的分数

/** 
 * 敌人,可以有分数 
 */  
public interface Enemy {  
    /** 敌人的分数  */  
    int getScore();  
}

飞行物(敌机,蜜蜂,子弹,英雄机)

import java.awt.image.BufferedImage;  

/** 
 * 飞行物(敌机,蜜蜂,子弹,英雄机) 
 */  
public abstract class FlyingObject {  
    protected int x;    //x坐标  
    protected int y;    //y坐标  
    protected int width;    //宽  
    protected int height;   //高  
    protected BufferedImage image;   //图片  

    public int getX() {  
        return x;  
    }  

    public void setX(int x) {  
        this.x = x;  
    }  

    public int getY() {  
        return y;  
    }  

    public void setY(int y) {  
        this.y = y;  
    }  

    public int getWidth() {  
        return width;  
    }  

    public void setWidth(int width) {  
        this.width = width;  
    }  

    public int getHeight() {  
        return height;  
    }  

    public void setHeight(int height) {  
        this.height = height;  
    }  

    public BufferedImage getImage() {  
        return image;  
    }  

    public void setImage(BufferedImage image) {  
        this.image = image;  
    }  

    /** 
     * 检查是否出界 
     * @return true 出界与否 
     */  
    public abstract boolean outOfBounds();  

    /** 
     * 飞行物移动一步 
     */  
    public abstract void step();  

    /** 
     * 检查当前飞行物体是否被子弹(x,y)击(shoot)中 
     * @param Bullet 子弹对象 
     * @return true表示被击中了 
     */  
    public boolean shootBy(Bullet bullet){  
        int x = bullet.x;  //子弹横坐标  
        int y = bullet.y;  //子弹纵坐标  
        return this.x

英雄机

import java.awt.image.BufferedImage;  

/** 
 * 英雄机:是飞行物  
 */  
public class Hero extends FlyingObject{  

    private BufferedImage[] images = {};  //英雄机图片  
    private int index = 0;                //英雄机图片切换索引  

    private int doubleFire;   //双倍火力  
    private int life;   //命  

    /** 初始化数据 */  
    public Hero(){  
        life = 3;   //初始3条命  
        doubleFire = 0;   //初始火力为0  
        images = new BufferedImage[]{ShootGame.hero0, ShootGame.hero1}; //英雄机图片数组  
        image = ShootGame.hero0;   //初始为hero0图片  
        width = image.getWidth();  
        height = image.getHeight();  
        x = 150;  
        y = 400;  
    }  

    /** 获取双倍火力 */  
    public int isDoubleFire() {  
        return doubleFire;  
    }  

    /** 设置双倍火力 */  
    public void setDoubleFire(int doubleFire) {  
        this.doubleFire = doubleFire;  
    }  

    /** 增加火力 */  
    public void addDoubleFire(){  
        doubleFire = 40;  
    }  

    /** 增命 */  
    public void addLife(){  //增命  
        life++;  
    }  

    /** 减命 */  
    public void subtractLife(){   //减命  
        life--;  
    }  

    /** 获取命 */  
    public int getLife(){  
        return life;  
    }  

    /** 当前物体移动了一下,相对距离,x,y鼠标位置  */  
    public void moveTo(int x,int y){     
        this.x = x - width/2;  
        this.y = y - height/2;  
    }  

    /** 越界处理 */  
    @Override  
    public boolean outOfBounds() {  
        return false;    
    }  

    /** 发射子弹 */  
    public Bullet[] shoot(){     
        int xStep = width/4;      //4半  
        int yStep = 20;  //步  
        if(doubleFire>0){  //双倍火力  
            Bullet[] bullets = new Bullet[2];  
            bullets[0] = new Bullet(x+xStep,y-yStep);  //y-yStep(子弹距飞机的位置)  
            bullets[1] = new Bullet(x+3*xStep,y-yStep);  
            return bullets;  
        }else{      //单倍火力  
            Bullet[] bullets = new Bullet[1];  
            bullets[0] = new Bullet(x+2*xStep,y-yStep);    
            return bullets;  
        }  
    }  

    /** 移动 */  
    @Override  
    public void step() {  
        if(images.length>0){  
            image = images[index++/10%images.length];  //切换图片hero0,hero1  
        }  
    }  

    /** 碰撞算法 */  
    public boolean hit(FlyingObject other){  

        int x1 = other.x - this.width/2;                 //x坐标最小距离  
        int x2 = other.x + this.width/2 + other.width;   //x坐标最大距离  
        int y1 = other.y - this.height/2;                //y坐标最小距离  
        int y2 = other.y + this.height/2 + other.height; //y坐标最大距离  

        int herox = this.x + this.width/2;               //英雄机x坐标中心点距离  
        int heroy = this.y + this.height/2;              //英雄机y坐标中心点距离  

        return herox>x1 && heroxy1 && heroy

游戏启动主类

import java.awt.Font;  
import java.awt.Color;  
import java.awt.Graphics;  
import java.awt.event.MouseAdapter;  
import java.awt.event.MouseEvent;  
import java.util.Arrays;  
import java.util.Random;  
import java.util.Timer;  
import java.util.TimerTask;  
import java.awt.image.BufferedImage;  

import javax.imageio.ImageIO;  
import javax.swing.ImageIcon;  
import javax.swing.JFrame;  
import javax.swing.JPanel;  
/**
 * 
 */
public class ShootGame extends JPanel {  
    public static final int WIDTH = 400; // 面板宽  
    public static final int HEIGHT = 654; // 面板高  
    /** 游戏的当前状态: START RUNNING PAUSE GAME_OVER */  
    private int state;  
    private static final int START = 0;  
    private static final int RUNNING = 1;  
    private static final int PAUSE = 2;  
    private static final int GAME_OVER = 3;  

    private int score = 0; // 得分  
    private Timer timer; // 定时器  
    private int intervel = 1000 / 100; // 时间间隔(毫秒)  

    public static BufferedImage background;  
    public static BufferedImage start;  
    public static BufferedImage airplane;  
    public static BufferedImage bee;  
    public static BufferedImage bullet;  
    public static BufferedImage hero0;  
    public static BufferedImage hero1;  
    public static BufferedImage pause;  
    public static BufferedImage gameover;  

    private FlyingObject[] flyings = {}; // 敌机数组  
    private Bullet[] bullets = {}; // 子弹数组  
    private Hero hero = new Hero(); // 英雄机  

    static { // 静态代码块,初始化图片资源  
        try {  
            background = ImageIO.read(ShootGame.class  
                    .getResource("background.png"));  
            start = ImageIO.read(ShootGame.class.getResource("start.png"));  
            airplane = ImageIO  
                    .read(ShootGame.class.getResource("airplane.png"));  
            bee = ImageIO.read(ShootGame.class.getResource("bee.png"));  
            bullet = ImageIO.read(ShootGame.class.getResource("bullet.png"));  
            hero0 = ImageIO.read(ShootGame.class.getResource("hero0.png"));  
            hero1 = ImageIO.read(ShootGame.class.getResource("hero1.png"));  
            pause = ImageIO.read(ShootGame.class.getResource("pause.png"));  
            gameover = ImageIO  
                    .read(ShootGame.class.getResource("gameover.png"));  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }  

    /** 画 */  
    @Override  
    public void paint(Graphics g) {  
        g.drawImage(background, 0, 0, null); // 画背景图  
        paintHero(g); // 画英雄机  
        paintBullets(g); // 画子弹  
        paintFlyingObjects(g); // 画飞行物  
        paintScore(g); // 画分数  
        paintState(g); // 画游戏状态  
    }  

    /** 画英雄机 */  
    public void paintHero(Graphics g) {  
        g.drawImage(hero.getImage(), hero.getX(), hero.getY(), null);  
    }  

    /** 画子弹 */  
    public void paintBullets(Graphics g) {  
        for (int i = 0; i < bullets.length; i++) {  
            Bullet b = bullets[i];  
            g.drawImage(b.getImage(), b.getX() - b.getWidth() / 2, b.getY(),  
                    null);  
        }  
    }  

    /** 画飞行物 */  
    public void paintFlyingObjects(Graphics g) {  
        for (int i = 0; i < flyings.length; i++) {  
            FlyingObject f = flyings[i];  
            g.drawImage(f.getImage(), f.getX(), f.getY(), null);  
        }  
    }  

    /** 画分数 */  
    public void paintScore(Graphics g) {  
        int x = 10; // x坐标  
        int y = 25; // y坐标  
        Font font = new Font(Font.SANS_SERIF, Font.BOLD, 22); // 字体  
        g.setColor(new Color(0xFF0000));  
        g.setFont(font); // 设置字体  
        g.drawString("SCORE:" + score, x, y); // 画分数  
        y=y+20; // y坐标增20  
        g.drawString("LIFE:" + hero.getLife(), x, y); // 画命  
    }  

    /** 画游戏状态 */  
    public void paintState(Graphics g) {  
        switch (state) {  
        case START: // 启动状态  
            g.drawImage(start, 0, 0, null);  
            break;  
        case PAUSE: // 暂停状态  
            g.drawImage(pause, 0, 0, null);  
            break;  
        case GAME_OVER: // 游戏终止状态  
            g.drawImage(gameover, 0, 0, null);  
            break;  
        }  
    }  

    public static void main(String[] args) {  
        JFrame frame = new JFrame("Fly");  
        ShootGame game = new ShootGame(); // 面板对象  
        frame.add(game); // 将面板添加到JFrame中  
        frame.setSize(WIDTH, HEIGHT); // 设置大小  
        frame.setAlwaysOnTop(true); // 设置其总在最上  
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 默认关闭操作  
        frame.setIconImage(new ImageIcon("images/icon.jpg").getImage()); // 设置窗体的图标  
        frame.setLocationRelativeTo(null); // 设置窗体初始位置  
        frame.setVisible(true); // 尽快调用paint  

        game.action(); // 启动执行  
    }  

    /** 启动执行代码 */  
    public void action() {  
        // 鼠标监听事件  
        MouseAdapter l = new MouseAdapter() {  
            @Override  
            public void mouseMoved(MouseEvent e) { // 鼠标移动  
                if (state == RUNNING) { // 运行状态下移动英雄机--随鼠标位置  
                    int x = e.getX();  
                    int y = e.getY();  
                    hero.moveTo(x, y);  
                }  
            }  

            @Override  
            public void mouseEntered(MouseEvent e) { // 鼠标进入  
                if (state == PAUSE) { // 暂停状态下运行  
                    state = RUNNING;  
                }  
            }  

            @Override  
            public void mouseExited(MouseEvent e) { // 鼠标退出  
                if (state == RUNNING) { // 游戏未结束,则设置其为暂停  
                    state = PAUSE;  
                }  
            }  

            @Override  
            public void mouseClicked(MouseEvent e) { // 鼠标点击  
                switch (state) {  
                case START:  
                    state = RUNNING; // 启动状态下运行  
                    break;  
                case GAME_OVER: // 游戏结束,清理现场  
                    flyings = new FlyingObject[0]; // 清空飞行物  
                    bullets = new Bullet[0]; // 清空子弹  
                    hero = new Hero(); // 重新创建英雄机  
                    score = 0; // 清空成绩  
                    state = START; // 状态设置为启动  
                    break;  
                }  
            }  
        };  
        this.addMouseListener(l); // 处理鼠标点击操作  
        this.addMouseMotionListener(l); // 处理鼠标滑动操作  

        timer = new Timer(); // 主流程控制  
        timer.schedule(new TimerTask() {  
            @Override  
            public void run() {  
                if (state == RUNNING) { // 运行状态  
                    enterAction(); // 飞行物入场  
                    stepAction(); // 走一步  
                    shootAction(); // 英雄机射击  
                    bangAction(); // 子弹打飞行物  
                    outOfBoundsAction(); // 删除越界飞行物及子弹  
                    checkGameOverAction(); // 检查游戏结束  
                }  
                repaint(); // 重绘,调用paint()方法  
            }  

        }, intervel, intervel);  
    }  

    int flyEnteredIndex = 0; // 飞行物入场计数  

    /** 飞行物入场 */  
    public void enterAction() {  
        flyEnteredIndex++;  
        if (flyEnteredIndex % 40 == 0) { // 400毫秒生成一个飞行物--10*40  
            FlyingObject obj = nextOne(); // 随机生成一个飞行物  
            flyings = Arrays.copyOf(flyings, flyings.length + 1);  
            flyings[flyings.length - 1] = obj;  
        }  
    }  

    /** 走一步 */  
    public void stepAction() {  
        for (int i = 0; i < flyings.length; i++) { // 飞行物走一步  
            FlyingObject f = flyings[i];  
            f.step();  
        }  

        for (int i = 0; i < bullets.length; i++) { // 子弹走一步  
            Bullet b = bullets[i];  
            b.step();  
        }  
        hero.step(); // 英雄机走一步  
    }  

    /** 飞行物走一步 */  
    public void flyingStepAction() {  
        for (int i = 0; i < flyings.length; i++) {  
            FlyingObject f = flyings[i];  
            f.step();  
        }  
    }  

    int shootIndex = 0; // 射击计数  

    /** 射击 */  
    public void shootAction() {  
        shootIndex++;  
        if (shootIndex % 30 == 0) { // 300毫秒发一颗  
            Bullet[] bs = hero.shoot(); // 英雄打出子弹  
            bullets = Arrays.copyOf(bullets, bullets.length + bs.length); // 扩容  
            System.arraycopy(bs, 0, bullets, bullets.length - bs.length,  
                    bs.length); // 追加数组  
        }  
    }  

    /** 子弹与飞行物碰撞检测 */  
    public void bangAction() {  
        for (int i = 0; i < bullets.length; i++) { // 遍历所有子弹  
            Bullet b = bullets[i];  
            bang(b); // 子弹和飞行物之间的碰撞检查  
        }  
    }  

    /** 删除越界飞行物及子弹 */  
    public void outOfBoundsAction() {  
        int index = 0; // 索引  
        FlyingObject[] flyingLives = new FlyingObject[flyings.length]; // 活着的飞行物  
        for (int i = 0; i < flyings.length; i++) {  
            FlyingObject f = flyings[i];  
            if (!f.outOfBounds()) {  
                flyingLives[index++] = f; // 不越界的留着  
            }  
        }  
        flyings = Arrays.copyOf(flyingLives, index); // 将不越界的飞行物都留着  

        index = 0; // 索引重置为0  
        Bullet[] bulletLives = new Bullet[bullets.length];  
        for (int i = 0; i < bullets.length; i++) {  
            Bullet b = bullets[i];  
            if (!b.outOfBounds()) {  
                bulletLives[index++] = b;  
            }  
        }  
        bullets = Arrays.copyOf(bulletLives, index); // 将不越界的子弹留着  
    }  

    /** 检查游戏结束 */  
    public void checkGameOverAction() {  
        if (isGameOver()==true) {  
            state = GAME_OVER; // 改变状态  
        }  
    }  

    /** 检查游戏是否结束 */  
    public boolean isGameOver() {  

        for (int i = 0; i < flyings.length; i++) {  
            int index = -1;  
            FlyingObject obj = flyings[i];  
            if (hero.hit(obj)) { // 检查英雄机与飞行物是否碰撞  
                hero.subtractLife(); // 减命  
                hero.setDoubleFire(0); // 双倍火力解除  
                index = i; // 记录碰上的飞行物索引  
            }  
            if (index != -1) {  
                FlyingObject t = flyings[index];  
                flyings[index] = flyings[flyings.length - 1];  
                flyings[flyings.length - 1] = t; // 碰上的与最后一个飞行物交换  

                flyings = Arrays.copyOf(flyings, flyings.length - 1); // 删除碰上的飞行物  
            }  
        }  

        return hero.getLife() <= 0;  
编程语言用 Java 开发一个打飞机小游戏(附完整源码)编程语言用 Java 开发一个打飞机小游戏(附完整源码)    }  

    /** 子弹和飞行物之间的碰撞检查 */  
    public void bang(Bullet bullet) {  
        int index = -1; // 击中的飞行物索引  
        for (int i = 0; i < flyings.length; i++) {  
            FlyingObject obj = flyings[i];  
            if (obj.shootBy(bullet)) { // 判断是否击中  
                index = i; // 记录被击中的飞行物的索引  
                break;  
            }  
        }  
        if (index != -1) { // 有击中的飞行物  
            FlyingObject one = flyings[index]; // 记录被击中的飞行物  

            FlyingObject temp = flyings[index]; // 被击中的飞行物与最后一个飞行物交换  
            flyings[index] = flyings[flyings.length - 1];  
            flyings[flyings.length - 1] = temp;  

            flyings = Arrays.copyOf(flyings, flyings.length - 1); // 删除最后一个飞行物(即被击中的)  

            // 检查one的类型(敌人加分,奖励获取)  
            if (one instanceof Enemy) { // 检查类型,是敌人,则加分  
                Enemy e = (Enemy) one; // 强制类型转换  
                score += e.getScore(); // 加分  
            } else { // 若为奖励,设置奖励  
                Award a = (Award) one;  
                int type = a.getType(); // 获取奖励类型  
                switch (type) {  
                case Award.DOUBLE_FIRE:  
                    hero.addDoubleFire(); // 设置双倍火力  
                    break;  
                case Award.LIFE:  
                    hero.addLife(); // 设置加命  
                    break;  
                }  
            }  
        }  
    }  

    /** 
     * 随机生成飞行物 
     *  
     * @return 飞行物对象 
     */  
    public static FlyingObject nextOne() {  
        Random random = new Random();  
        int type = random.nextInt(20); // [0,20)  
        if (type < 4) {  
            return new Bee();  
        } else {  
            return new Airplane();  
        }  
    }  
}

原文链接:Java 开发打飞机小游戏(附完整源码)_一只独孤的程序猿-CSDN博客_java小游戏代码

版权声明:本文为CSDN博主「一只独孤的程序猿」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

近期热文推荐:

1.1,000+ 道 Java面试题及答案整理(2021最新版)

2.别在再满屏的 if/ else 了,试试策略模式,真香!!

3.卧槽!Java 中的 xx ≠ null 是什么新语法?

4.Spring Boot 2.5 重磅发布,黑暗模式太炸了!

5.《Java开发手册(嵩山版)》最新发布,速速下载!

觉得不错,别忘了随手点赞+转发哦!

阿哇教育
www.awaedu.com
搜白度
www.sobd.cc
作文哥
www.zuowenge.cn
搜码吧
www.somanba.cn
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

编程语言用 Java 开发一个打飞机小游戏(附完整源码) 的相关文章

  • 按位运算符简单地翻转整数中的所有位?

    我必须翻转整数的二进制表示形式中的所有位 鉴于 10101 输出应该是 01010 当与整数一起使用时 完成此操作的按位运算符是什么 例如 如果我正在编写类似的方法int flipBits int n 什么会进入身体 我只需要翻转数字中已经
  • 探索java图像处理的好资源[关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我是图像处理领域的新手 请推荐一些好的资源 书籍和网络链接 来学习 Java 中的图像处理 最适合隐写术分析 适合初学者和高级水平 我看过
  • 为什么这个动作不抽象? [关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我很难理解为什么一个类中的一个操作是抽象的 而另一个类中的操作不是 源代码1 编译时出错 https gyazo com cd3c
  • 如何添加 Java 正则表达式实现中缺少的功能?

    我是 Java 新手 作为一名 Net 开发人员 我非常习惯Regex Net 中的类 Java 实现Regex 正则表达式 还不错 但它缺少一些关键功能 我想为 Java 创建自己的帮助器类 但我想也许已经有一个可用的了 那么 是否有任何
  • Apache Commons VFS - 无法解析文件

    VFS 方法无法处理此 URI jboss server temp dir local outgoing配置在jboss beans xml这是决心 C Download jboss eap 5 1 1 server default tmp
  • 外部实体更改后索引不更新

    我目前正在开发一个项目 使用 JPA 2 1 保存数据并使用 hibernate search 4 5 0 final 搜索实体 映射类和索引后 搜索工作正常 但是 当我更改值时描述B 类从 someStr 到 anotherStr 数据库
  • 欧拉项目 45

    我还不是一名熟练的程序员 但我认为这是一个有趣的问题 我想我应该尝试一下 三角形 五边形 六边形 数字由以下生成 公式 三角形 T n n n 1 2 1 3 6 10 15 五边形 P n n 3n 1 2 1 5 12 22 35 六角
  • 使用 equals 方法比较两个对象,Java

    我有一个对象数组 我想将它们与目标对象进行比较 我想返回与目标对象完全匹配的对象的数量 这是我的计数方法 public int countMatchingGhosts Ghost target int count 0 for int i 0
  • java数学中的组合“N选择R”?

    java库中是否有内置方法可以为任何N R计算 N选择R 公式 实际上很容易计算N choose K甚至不需要计算阶乘 我们知道 公式为 N choose K is N N K K 因此 公式为 N choose K 1 is N N N
  • 如何构建和使用 TimeSeriesCollections

    我想在图表的 X 轴上显示一些日期 并且here https stackoverflow com questions 5118684 jfreechart histogram with dates据说我必须使用 TimeSeriesColl
  • JPA 的 Hibernate 查询提示

    我一直在尝试为所有可以通过设置的提示找到一个明确的资源Query setHint String Object JPA 中的方法调用 但我一无所获 有人知道一个好的参考吗 See 3 4 1 7 查询提示 http docs jboss or
  • 如何将测试类打包到jar中而不运行它们?

    我正在努力将我的测试类包含到 jar 包中 但不运行它们 经过一番谷歌搜索后 我尝试过mvn package DskipTests 但我的测试类根本没有添加到 jar 中 有任何想法吗 如果您遵循 Maven 约定 那么您的测试类位于src
  • Java:java.util.Preferences 失败

    我的程序将加密的产品密钥数据保存到计算机上java util Preferences类 系统首选项 而不是用户 问题是 在 Windows 和 Linux 上 尚未在 OSX 上测试过 但可能是相同的 如果我不运行该程序sudo或者具有管理
  • java中的第三个布尔状态是什么?

    虽然我知道根据定义 布尔值仅包含两种状态 真或假 我想知道布尔值在用这些状态之一初始化之前有什么值 它默认为 false http java sun com docs books tutorial java nutsandbolts dat
  • 从特定 JAR 文件读取资源(文件的重复路径)

    假设您有 jar1 和artifactId 动物园 jar2 和artifactId 动物 两个 jar 都有一个具有相同路径的资源文件 例如 animals animal txt 有什么方法可以从特定的 jar 中读取该文件吗 使用 ge
  • 将 PropertyPlaceholderConfigurer 中的所有属性注入到 bean 中

    我有一个PropertyPlaceholderConfigurer加载多个属性文件 我想通过配置 XML 将合并的属性映射注入到 Spring Bean 中 我可以这样做以及如何做 您只需创建一个属性 bean 并将其用于您的Propert
  • 使用 Commons 或 Guava 将文本文件转换为 Java Set

    我想将文件中的每一行加载到 HashSet 集合中 有没有一种简单的方法可以做到这一点 怎么样 Sets newHashSet Files readLines file charSet 使用番石榴 参考 文件 readLines http
  • 如何在apache POI中读取excel文件的准确单元格内容

    当我读取单元格的内容时 例如如果它是日期格式 它会转换为另一个值 例如 12 31 2099 gt 46052 和 50 00 gt 50 和 50 00 gt 0 5 但我想要的是获取每个单元格的确切字符串值 我的代码是这样的 cell
  • 检查 Java 字符串实例是否可能包含垃圾邮件数据的最简单方法

    我有一个迭代 String 实例的过程 每次迭代对 String 实例执行很少的操作 最后 String 实例被持久化 现在 我想为每次迭代添加一个检查 String 实例是否可能是垃圾邮件的检查 我只需验证 String 实例不是 成人材
  • 膨胀类 android.support.design.widget.CoordinatorLayoute 时出错

    我正在尝试运行我的应用程序 但不断收到标题中列出的错误 我读过周围的内容 人们说尝试将主题更改为 AppCombat 主题 但这似乎不起作用 以下是我遇到的错误 Process com example jmeyer27 crazytiles

随机推荐

  • NeuPhysics: Editable Neural Geometry and Physics from Monocular Videos 解读

    1 论文简介 1 将NeRF和SDF方法结合来更好的回归物体表面 mesh 2 通过在神经辐射场后嵌入可微模拟器 实现动力学参数学习和进行场景编辑 2 核心思想 上述论文包含三个模块 1 Time invariant information
  • matlab生成dll

    实验室的一个项目需要调用matlab程序 经过再三考虑 决定使用vc调用matlab导出库的形式 而我主要负责与matlab程序结合的工作 以下是今天工作的简要总结 全当是个备忘吧 1 在matlab中选择compiler 在命令行窗口输入
  • 中国科学信息科学latex模板编译报错的解决办法

    中国科学 信息科学 latex模板编译不通过解决办法 1 前言 本文的解决办法不需要重新下载ctex 只需要添加两个文件即可 主要参考了下面的这篇文章如果你想知道为什么要这么改 强烈推荐阅读这篇博客 编译 CCT 模板 stone zeng
  • Django 模板的导入与继承

    目录 模板的导入和继承 1 模板的导入之include标签 2 模板的继承 派生之extendds标签 block标签 模板的导入和继承 在实际开发中 模板文件彼此之间可能会有大量冗余代码 为此django提供了专门的语法来解决这个问题 主
  • AIGC之GPT-4:GPT-4的简介与详细攻略

    AIGC之GPT 4 GPT 4的简介与详细攻略 简介 欢迎来到人工智能生成内容 AIGC 时代的新篇章 本篇博客将介绍GPT 4 Generative Pre trained Transformer 4 的核心原理 意义 亮点 技术点 缺
  • 【java笔记】泛型定义和使用

    为什么使用泛型 泛型的字面意思就是广泛的类型 利用泛型 同一套代码可以用于多种数据类型 这样 不仅可以复用代码 降低耦合 而且可以提高代码的可读性和安全性 可读性 var s new ArrayList
  • 【OpenGL进阶】04.支持多贴图的Shader

    这篇文章来实现一下多贴图的效果 在这篇文章中 再次对代码进行了封装 是代码看起来更加清晰明了 shader h中添加了SetTexture接口 pragma once include ggl h struct UniformTexture
  • [canvas] 坐标旋转

    坐标旋转 做圆周运动 vr 0 1 angle 0 radius 100 centerX 0 centerY 0 object x centerX Math sin angle radius object y centerY Math co
  • git报错:warning: unable to access

    git操作的时候出现该错误 warning unable to access Users a10 12 config git ignore Permission denied warning unable to access Users a
  • 一个女孩的就业之路(同济大学BBS上两年不沉的帖子)

    文章很长 有机会见到这篇文章的童鞋 希望能耐心看完 其他不多说 我是2005年毕业的 偶尔来这里看看 不常灌水 今天来随意写下一些 如果对各位有任何的帮助 是我衷心所愿 1 考研与就业 2004年的暑假 我和大多数人一样 艰难的抉择 究竟是
  • NacosValue 注解

    NacosValue 定义在 nacos api 工程中 com alibaba nacos api config annotation NacosValue 注解解析在 nacos spring project 工程中 com aliba
  • 阻塞队列java实现

    阻塞队列 目前队列存在的问题 1 很多场景要求分离生产者和消费者两个角色 它们得由不同的线程来担当 而之前的实现根本没有考虑线程安全问题 2 队列为空 那么在之前的实现里会返回null 如果硬拿到一个元素 只能不断循环尝试 3 队列为满 那
  • PHP魔术方(2)

    PHP魔术方 2 文章目录 PHP魔术方 2 1 toString 和 invoke tostring 和 invoke 两者的触发形式接近 2 call 用来检测所调用的成员方法是否存在 3 callStatic 4 get 5 set
  • 在Linux系统上用C++将主机名称转换为IPv4、IPv6地址

    在Linux系统上用C 将主机名称转换为IPv4 IPv6地址 功能 指定一个std string类型的主机名称 函数解析主机名称为IP地址 含IPv4和IPv6 解析结果以std vector
  • vue div高度自适应

    1 在 js文件中编写自定义指令 export default install Vue 在组件标签上绑定 v resizable 指令 并使用对象的形式通过绑定值传递宽度和高度以及最大 最小高度的值 在 bind 函数中 获取传递的值 并根
  • 走进区块链企业 I 用实践赋能实体产业,坚持提供价值服务的旺链科技

    作为华东师范大学MBA高材生 他在高科技制造 金融行业有着超过16年的业务咨询管理和技术架构经验 他是中国云体系产业创新联盟理事会常务理事 边缘计算产业联盟专家委员 也是原 Accenture资深总监 集成技术专家 而在如今话题正盛的 区块
  • linux创建,恢复和删除screen

    学习记录 侵删 目录 1 创建 2 恢复 3 删除 使用服务器训练模型时 如果服务器断开 之前的训练结果显示的终端就不好找到了 貌似可以通过线程去恢复 没试过 可以使用screen 训练前先打开一个screen 如果服务器断开 重连后可以恢
  • 最新免费版 Office 全家桶Copilot,Gamma+MindShow 两大ChatGPT AI创意工具GPT-4神器助力高效智能制作 PPT,一键生成,与AI智能对话修改PPT(免安装)

    目录 前言 ChatGPT MindShow 1 使用ChatGPT工具生成PPT内容 2 使用MindShow工具一键智能制作PPT MindShow简介 使用网页版制作 pdf转ppt GAMMA AI神器 GAMMA app介绍 注册
  • MySQL基础篇:sql_mode配置

    文章目录 零 简介 一 sql mode常用来解决的几类问题 二 sql mode包含的模式 三 sql mode各个选项作用示例 3 1 sql mode为空 对于不符合定义的值 会截断到符合定义类型 3 2 sql mode为ANSI
  • 编程语言用 Java 开发一个打飞机小游戏(附完整源码)

    编程语言用 Java 开发一个打飞机小游戏 附完整源码 上图 写在前面 技术源于分享 所以今天抽空把自己之前用java做过的小游戏整理贴出来给大家参考学习 java确实不适合写桌面应用 这里只是通过这个游戏让大家理解oop面向对象编程的过程