会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133528个问题
JAVA 全系列/第四阶段:数据库与AI协同技术实战/Oracle 数据库的使用 33287楼

老师,按键控制飞机,飞机不动

package com.bjsxt.plane05;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
/** 
 * <p>Title: 游戏主窗口(飞机大战1.0版)</p>  
 * <p>Description: 尚学堂</p>  
 * @author xiaoding
 * @date Apr 16, 2020  
 * @version 1.0 
 */

public class MyGameFrame extends Frame{
    //调用GameUtil类的静态方法,把图片的地址传过去
    Image feiJi = GameUtil.getImage("images/plane.png");
    Image bj = GameUtil.getImage("images/bj.jpg");
    
    Plane plane = new Plane(feiJi,100,100,7);
    
    boolean left,right,up,down;
    //画出窗口
    @Override
    public void paint(Graphics g) {    //g当做是一支画笔
        g.drawImage(bj,0,0,500,500,null);
        plane.drawMyself(g);
        if(left) {
            plane.x -= plane.speed;
        }
        if(right) {
            plane.x += plane.speed;
        }
        if(up) {
            plane.y -= plane.speed;
        }
        if(down) {
            plane.y += plane.speed;
        }
    }
    
    //初始化窗口
        public void launchFrame() {
            //游戏名称
            this.setTitle("飞机大战-尚学堂");        
            setVisible(true);    //窗口是否可见
            
            setSize(Constant.GAME_WIHTH,Constant.GAME_HEIGHT);    //窗口大小
            setLocation(400,400);    //窗口打开位置
            
            //增加关闭窗口的动作
            this.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);    //正常退出程序
                }
            });
            //启动重画窗口内部类方法
            new PaintThread().run();
            //启动键盘监听
            this.addKeyListener(new KeyMonitor());
        }
    
    /*
     *     定义一个重画窗口的线程类
     *     定义内部类是类为方便直接使用窗口类的相关方法
     */
    class PaintThread extends Thread {
        public void run() {
            while(true) {
                repaint();        //内部类可以直接使用外部类的成员!
                
                try {
                    Thread.sleep(50);        //1s=1000ms  (1000 / 50) = 20
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }
    
    /*
     *     创建一个键盘控制内部类
     *     实现键盘的监听处理
     */
    class KeyMonitor extends KeyAdapter {
        @Override
        public void keyPressed(KeyEvent e) {
            System.out.println("按下:" + e.getKeyCode());
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                left = true;
            }
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                right = true;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                up = true;
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                down = true;
            }
        }
        @Override
        public void keyReleased(KeyEvent e) {
            System.out.println("抬起:" + e.getKeyCode());
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
                left = false;
            }
            if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
                right = false;
            }
            if (e.getKeyCode() == KeyEvent.VK_UP) {
                up = false;
            }
            if (e.getKeyCode() == KeyEvent.VK_DOWN) {
                down = false;
            }
        }
    }
    
    //解决屏幕闪烁缓冲技术
    private Image offScreenImage = null; 
    public void update(Graphics g) { 
        if(offScreenImage == null) 
            //这是游戏窗口的宽度和高度
            offScreenImage = this.createImage(Constant.GAME_WIHTH,Constant.GAME_HEIGHT);
        
            Graphics gOff = offScreenImage.getGraphics(); 
            paint(gOff); 
            g.drawImage(offScreenImage, 0, 0, null); 
    }
    

    //main主方法,程序执行入口
    public static void main(String[] args) {
        MyGameFrame gameFrame = new MyGameFrame();
        gameFrame.launchFrame();
    }
}


JAVA 全系列/第一阶段:AI驱动的JAVA编程/飞机大战小项目训练 33288楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/飞机大战小项目训练 33289楼
JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/Maven 33290楼
JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/Zookeeper 33293楼

问题:

W~4J`0$8J]I{FT}XR7FIN`7.png

老师,最后一问如何解决呢。

代码:

public class Store {
    private int id;
    private String name;
    private String number;
    private double price;
    private double discount;
    private double sale_price;


    public Store(int id, String name, String number, double price, double discount) {
        this.id = id;
        this.name = name;
        this.number = number;
        this.price = price;
        this.discount = discount;
    }

 public String toString(){
        return "["+id+","+name+","+number+","+price+"discount"+"]";
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNumber() {
        return number;
    }

    public void setNumber(String number) {
        this.number = number;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getDiscount() {
        return discount;
    }

    public void setDiscount(double discount) {
        this.discount = discount;
    }

    public double getSale_price(double m) {
        if (m<(this.price*this.discount)){
            System.out.println(this.name);
        }else {
            System.out.println("这个商品价格太低了");

        }
        return m;
    }

    public void setSale_price(double sale_price) {
        this.sale_price = sale_price;
    }

    public static void main(String[] args) {
        Store[]stores={new Store(1,"baizhan_mouse","BZ_001",99,0.9) ,
                new Store(2,"doll","WO_102",403.00,0.7),
                new Store(3,"java","BK_001",89.00,0.8),
                new Store(4,"suit","GQ_XF_12",700.00,0.5),
                new Store(5,"Mi_phone","DM_PH_13",900.00,0.3)};

        for (int t=0;t<stores.length;t++){
            System.out.println(stores[t]);
        }
        //System.out.println(Arrays.toString(stores));
        }
        }


JAVA 全系列/第一阶段:AI驱动的JAVA编程/数组和数据存储 33294楼

提问:

        老师,我在做这个项目整合的时候在xml配置文件里面把包名写错了。这样会导致启动tomcat的时候看不出问题,但是访问页面的时候是404.死活找不到原因,这种情况一般怎么排查?eclipse的控制台显示的启动信息里面也不会记录这个错误,一直显示正常启动,8080端口也是开放监听,但实际上里面部署的war有问题。



[INFO] Scanning for projects...

[INFO] 

[INFO] --------------------------< com.lx:solrDemo2 >--------------------------

[INFO] Building solrDemo2 0.0.1-SNAPSHOT

[INFO] --------------------------------[ war ]---------------------------------

[INFO] 

[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ solrDemo2 ---

[INFO] Deleting D:\source\solrDemo2\target

[INFO] 

[INFO] >>> tomcat7-maven-plugin:2.2:run (default-cli) > process-classes @ solrDemo2 >>>

[INFO] 

[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ solrDemo2 ---

[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

[INFO] Copying 0 resource

[INFO] Copying 8 resources

[INFO] 

[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ solrDemo2 ---

[INFO] Changes detected - recompiling the module!

[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!

[INFO] Compiling 1 source file to D:\source\solrDemo2\target\classes

[INFO] 

[INFO] <<< tomcat7-maven-plugin:2.2:run (default-cli) < process-classes @ solrDemo2 <<<

[INFO] 

[INFO] 

[INFO] --- tomcat7-maven-plugin:2.2:run (default-cli) @ solrDemo2 ---

[INFO] Running war on http://localhost:8080/

[INFO] Creating Tomcat server configuration at D:\source\solrDemo2\target\tomcat

[INFO] create webapp with contextPath: 

四月 17, 2020 12:32:51 下午 org.apache.coyote.AbstractProtocol init

信息: Initializing ProtocolHandler ["http-bio-8080"]

四月 17, 2020 12:32:51 下午 org.apache.catalina.core.StandardService startInternal

信息: Starting service Tomcat

四月 17, 2020 12:32:51 下午 org.apache.catalina.core.StandardEngine startInternal

信息: Starting Servlet Engine: Apache Tomcat/7.0.47

四月 17, 2020 12:32:53 下午 org.apache.catalina.core.ApplicationContext log

信息: No Spring WebApplicationInitializer types detected on classpath

四月 17, 2020 12:32:53 下午 org.apache.catalina.core.ApplicationContext log

信息: Initializing Spring root WebApplicationContext

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).

log4j:WARN Please initialize the log4j system properly.

log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

四月 17, 2020 12:32:54 下午 org.apache.catalina.core.ApplicationContext log

信息: Initializing Spring FrameworkServlet 'springmvc'

四月 17, 2020 12:32:55 下午 org.apache.coyote.AbstractProtocol start

信息: Starting ProtocolHandler ["http-bio-8080"]


JAVA 全系列/(旧的隐藏)第七阶段:JAVA 高级技术/Solr 33297楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 33300楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637