码迷,mamicode.com
首页 > 编程语言 > 详细

Java GUI 简单台球游戏模型

时间:2018-05-22 22:24:18      阅读:364      评论:0      收藏:0      [点我收藏+]

标签:print   getc   ade   buffered   window   AC   listen   location   test   

完成效果:

技术分享图片

 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 }

 

Java GUI 简单台球游戏模型

标签:print   getc   ade   buffered   window   AC   listen   location   test   

原文地址:https://www.cnblogs.com/liuhuijie/p/9074039.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!