zoukankan      html  css  js  c++  java
  • Java GUI 简单台球游戏模型

    完成效果:

     1 package com.neuedu.test;
     2 
     3 import java.awt.Frame;
     4 import java.awt.Graphics;
     5 import java.awt.event.WindowAdapter;
     6 import java.awt.event.WindowEvent;
     7 
     8 import com.neuedu.utill.GameUtill;
     9 
    10 public class TaiQiu extends Frame {
    11     public void loadFrame () {
    12         setLocation(100, 100);
    13         setSize(800,600);
    14         setTitle("台球");
    15         setResizable(false);
    16         setVisible(true);
    17         addWindowListener(new WindowAdapter() {
    18 
    19             @Override
    20             public void windowClosing(WindowEvent e) {
    21                 // TODO Auto-generated method stub
    22                 System.exit(0);
    23             }
    24             
    25         });
    26     }
    27     @Override
    28     public void paint(Graphics g) {
    29         // TODO Auto-generated method stub
    30         g.drawImage(GameUtill.getImage("com/neuedu/img/zhuomian.png"),10,50,null);
    31         g.drawImage(GameUtill.getImage("com/neuedu/img/0.png"),200,200,20,20,null);
    32         g.drawImage(GameUtill.getImage("com/neuedu/img/1.png"),250,200,20,20,null);
    33         g.drawImage(GameUtill.getImage("com/neuedu/img/2.png"),200,250,20,20,null);
    34         g.drawImage(GameUtill.getImage("com/neuedu/img/3.png"),300,350,20,20,null);
    35         g.drawImage(GameUtill.getImage("com/neuedu/img/4.png"),400,180,20,20,null);
    36         g.drawImage(GameUtill.getImage("com/neuedu/img/5.png"),500,200,20,20,null);
    37         g.drawImage(GameUtill.getImage("com/neuedu/img/6.png"),650,200,20,20,null);
    38         g.drawImage(GameUtill.getImage("com/neuedu/img/7.png"),480,200,20,20,null);
    39         g.drawImage(GameUtill.getImage("com/neuedu/img/8.png"),580,300,20,20,null);
    40         g.drawImage(GameUtill.getImage("com/neuedu/img/9.png"),360,300,20,20,null);
    41         g.drawImage(GameUtill.getImage("com/neuedu/img/10.png"),550,350,20,20,null);
    42         g.drawImage(GameUtill.getImage("com/neuedu/img/11.png"),350,250,20,20,null);
    43         g.drawImage(GameUtill.getImage("com/neuedu/img/12.png"),300,400,20,20,null);
    44         g.drawImage(GameUtill.getImage("com/neuedu/img/13.png"),400,300,20,20,null);
    45         g.drawImage(GameUtill.getImage("com/neuedu/img/14.png"),200,250,20,20,null);
    46         g.drawImage(GameUtill.getImage("com/neuedu/img/15.png"),100,200,20,20,null);
    47         
    48         
    49     }
    50   public static void main(String[] args) {
    51     TaiQiu tq = new TaiQiu();
    52     tq.loadFrame();
    53 }
    54 }
     1 package com.neuedu.utill;
     2 
     3 import java.awt.Image;
     4 import java.awt.image.BufferedImage;
     5 import java.io.IOException;
     6 import java.net.URL;
     7 
     8 import javax.imageio.ImageIO;
     9 
    10 public class GameUtill {
    11       public static Image getImage (String imgPath) {
    12         URL u = GameUtill.class.getClassLoader().getResource(imgPath);
    13           BufferedImage img = null;
    14           try {
    15             img = ImageIO.read(u);
    16         } catch (IOException e) {
    17             // TODO Auto-generated catch block
    18             e.printStackTrace();
    19         }
    20           return img;
    21           
    22       }
    23 }
  • 相关阅读:
    CEF解决加载慢问题
    CEF之CefSettings设置locale
    Win32程序支持命令行参数的做法(转载)
    VC++实现程序重启的方法(转载)
    CEF之CefSettings设置日志等级
    libcurl开源库在Win32程序中使用下载文件显示进度条实例
    libcurl开源库在Win7 + VS2012环境下编译、配置详解 以及下载文件并显示下载进度 demo(转载)
    使用ShellExecute打开目标文件所在文件夹并选中目标文件
    linux下gimp的使用
    linux下的chm阅读器?
  • 原文地址:https://www.cnblogs.com/liuhuijie/p/9074039.html
Copyright © 2011-2022 走看看