会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132469个问题
JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 15845楼

package com.whygame;
import java.awt.*;
import java.awt.event.*;
import  static com.whygame.GameUtil.*;
public class whygameframe extends Frame {
    int x=100,y=100;//飞机的坐标
    Image bg =GameUtil.getImage("images/bg.jpg");

    Image palane=GameUtil.getImage("images/meinv .jpg" );
    Plane plane=new Plane(palane,100,100,1);
    class keymonitr extends KeyAdapter {
        @Override
        public void keyPressed(KeyEvent e) {
           plane.addDriection(e);
        }

        @Override
        public void keyReleased(KeyEvent e) {
           plane.relDriection(e);
        }
    }
   public void Launchframe(){

        this.setTitle("Ying ge 's 飞机大战");
        this.setVisible(true);//窗口默认不可见,设置为可见true
        this.setSize(FrameWidth,FrameHeight);
        this.setLocation(FrameWidth,FrameHeight);
        //增加关闭窗口的动作
       this.addWindowListener(new WindowAdapter() {
           @Override
           public void windowClosing(WindowEvent e) {
              System.exit(0);
           }
       });
       new PaintThread().start();
       //启动键盘监听
       this.addKeyListener( new keymonitr());
    }

    @Override
    public void paint(Graphics g) {
     g.drawImage(bg,0,0,FrameWidth,FrameHeight,null);
plane.drawMyself(g);

     /*  Color old=g.getColor();
        g.setColor(Color.PINK);
       g.drawLine(100,10,200,20);
       g.drawRect(300,300,300,300);
       g.drawOval(400,400,100,100);
       g.drawString("你好",300,300);
       g.setColor(old);
       g.drawLine(200,50,400,100);
*/
    }
    public static void main(String[]args) {
        long a1 = System.currentTimeMillis();
        whygameframe frame = new whygameframe();
        frame.Launchframe();
        long a2 = System.currentTimeMillis();
        System.out.println("共用时:" + (a2 - a1) + "ms");
    }
class PaintThread extends Thread{
    @Override
    public void run() {
       while(true){
           repaint();
           try {
               sleep(10);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       }
    }
}
//解决屏幕闪烁问题
    private Image offScreenImage=null;
   public void update(Graphics g){
       if (offScreenImage==null){
           offScreenImage=this.createImage(FrameWidth,FrameHeight);
       }
       Graphics gOff=offScreenImage.getGraphics();
       paint(gOff);
       g.drawImage(offScreenImage,0,0,null);
   }
}
这是个什么错误,正常运行了几秒钟就不动了

image.png

JAVA 全系列/第一阶段:JAVA 快速入门/飞机大战小项目训练 15846楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>自定义右键菜单</title>
    <style>
        *{margin: 0;padding: 0;}
        ul{
            list-style: none;
            background-color: darkgray;
            min-width: 220px;
            display: inline-block;
            position: absolute;
            display: none;
        }
        ul li{
            height: 30px;
            line-height: 30px;
            padding: 5px 20px;
            cursor: pointer;/*光标变小手*/
            transition:0.3s;
        }
        ul li:hover{
            background-color: orange;
            color: white;
        }
    </style>
</head>
<body>
<ul>
    <li>我想你了!</li>
    <li>你真的忍心离开本页面吗?</li>
    <li>去百度搜索页面中选中的内容</li>
    <li>输入内容然后去百度搜索</li>
</ul>
<textarea  cols="80" rows="20"></textarea>
<script>
    var ul=document.querySelector('ul');
    //系统右键菜单禁用事件【contextmenu】
    document.oncontextmenu = function (eve) {
        return false; //return false表示事件禁用
    }
    document.onmouseup=function (eve) {
        //eve.button能够判断鼠标用的是哪个按钮
        //0 左键   1滚轮    2右键
        if (eve.button==2){
            ul.style.display='inline-block';
            //设置鼠标点击的位置
            ul.style.left=eve.clientX+'px';
            ul.style.top=eve.clientY+'px';
        }else {
            //关闭菜单
            ul.style.display='none';
        }
    }
    //点击某一个菜单选项时触发的事件(事件委托)
    ul.onmousedown=function (eve) {
        if (eve.target.innerHTML=='我想你了!'){
            alert('那就去吧,她在北京三区');
        }else if (eve.target.innerHTML=='你真的忍心离开本页面吗!'){
            if (confirm('你真的忍心离开本页面吗!')){
                window.close();
            }
        }else if (eve.target.innerHTML=='去百度搜索页面中选中的内容!'){
            var resukt=document.getSelection().toString();
            window.open('http://www.baidu.com/s?wd='+resukt);
        }else{
            var result=prompt('输入内容然后去百度搜索');
            window.open('http://www.baidu.com/s?wd='+result);
        }
    }
</script>
</body>
</html>

老师,我这个第三个功能实现不了,我也不知道是什么原因?

WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 15847楼
Python 全系列/第四阶段:函数式编程和核心特性/正则表达式 15848楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 15850楼
JAVA 全系列/第一阶段:JAVA 快速入门/面向对象详解和JVM底层内存分析 15851楼
JAVA 全系列/(旧的隐藏)第二十一阶段:百战商城项目(Spring Cloud最新架构)/百战商城项目 15854楼
JAVA 全系列/第十二阶段:Spring Cloud Alibaba技术栈/Dubbo 15855楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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