⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 .#graphicspanel.java.1.2

📁 java编写的打鸟游戏
💻 2
字号:
/* * GraphicsPanel.java * * Created on 2007年12月18日, 下午12:27 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package SBGameCore;import graphics.Bird;import graphics.Feather;import java.awt.Cursor;import java.awt.Font;import java.awt.Point;import java.util.Vector;import javax.swing.JFrame;import javax.swing.JPanel;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.Toolkit;import javax.swing.JPanel;/** * * @author wusir */public class GraphicsPanel extends JPanel implements Runnable{ /* Toolkit toolkit = Toolkit.getDefaultToolkit();    Image image1 = toolkit.getImage("image/2.jpg");    int x=0;    int y=0;    boolean stop=false;      public GraphicsPanel(){        super();        move();    }    public void paintComponent(Graphics g) {        super.paintComponent(g);        Graphics2D g2d = (Graphics2D) g;        g2d.setColor(Color.WHITE);        g2d.fillRect(0, 0, this.getWidth(), this.getHeight());        g2d.drawImage(image1,x,y,this);    }    public void move(){        Thread t=new Thread(){            public void run(){                while(!stop){                    try {                        repaint();                        Thread.sleep(20);                        x+=1;                        y+=1;                        repaint();                        if(x>700||y>700)stop=true;                    } catch (InterruptedException ex) {                        ex.printStackTrace();                    }                }            }        };        t.start();    }*/    Toolkit toolkit = null;    Image buffer = null ;	 // image buffer    Image backdrop = null ;      // background    Image bgimg  = null ;        // privouse background    Image[] birds = new Image[7];//birds images    Image feather = null;        //feather    Image cursor = null;           //cursor    Graphics  buf_g = null ;     // graphics buffer    Graphics  bkd_g = null ;     // background graphics    Dimension window_size = null;//windows size    Font font ;    Font font_s ;                //word fonts        Thread game = null;          //game thread    boolean game_over = false;    Point mouse = null;           //mouse position    Vector Vbird = new Vector();  //bird vector    int Nbird = 1;                //count of bird    Vector Vfeather = new Vector();//count of dropping-feather    int score = 0;        public GraphicsPanel(){        toolkit = Toolkit.getDefaultToolkit();        // bgimg = toolkit.getImage("");        for(int i=0;i<7;i++)            birds[i] = toolkit.getImage("image/"+i+".jpg");        // feather = toolkit.getImage("");        cursor = toolkit.getImage("image/");        font   = new Font("Helvetica", Font.BOLD, 24) ;        font_s = new Font("Helvetica", Font.BOLD, 14) ;            }        public void start(){                setCursor(toolkit.createCustomCursor(cursor,new Point(0,0),"sight")) ; //set the cursor here        window_size=this.size();//get the panel size                buffer = null;        buffer = createImage(window_size.width, window_size.height);                backdrop = null;        backdrop = createImage(window_size.width, window_size.height);                buf_g = buffer.getGraphics();        buf_g.fillRect(0, 0, window_size.width, window_size.height);                /*load sound here                  */    }        public void stop() {        if(game!=null){            game.stop();            game = null;        }        setCursor(Cursor.getDefaultCursor()) ;    }        public void paintComponent(Graphics g) {                //draw the panel with the graphics from buffer        super.paintComponent(g);        Graphics2D g2d = (Graphics2D) g;                            }            public void run() {                Bird bird = new Bird();        Feather feather = new Feather();        long time = 0;        buf_g = backdrop.getGraphics();        buf_g.drawImage(bgimg,0,0,window_size.width,window_size.height,this) ;        buf_g = getGraphics();        buf_g.drawImage(backdrop,0,0,this) ;                       buf_g = buffer.getGraphics();        buf_g.drawImage(bgimg,0,0,window_size.width,window_size.height,this) ;                repaint() ;                while(true){            time = System.currentTimeMillis() ;            	    if ((Vbird.size() < Nbird) && (Math.random() > (Vbird.size() == 0 ? 0.90 : 0.98))) {                        bird = new Bird();                        Vbird.add(bird);                    }                    }    }        public void display_score() {        }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -