完成效果:
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 }
原文地址:https://www.cnblogs.com/liuhuijie/p/9074039.html
时间: 2024-11-08 22:30:30