开发工具:
文件大小: 2kb
下载次数: 0
上传时间: 2011-11-23
详细说明: import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Animation extends JFrame implements Runnable,ActionListener{ private Container cont; private JButton btnUp; private JButton btnDown; private ImageIcon imgPlane; private ImageIcon imgBullet; private int planeX; private int planeY; private int bulletX; private int bulletY; private int planeSpeed; private int bulletSpeed; private int planeChangeSpeed; private Thread thread; public Animation(){ this.setBounds(30, 30, 400, 300); this.setDefaultCloseOperation(this.EXIT_ON_CLOSE); cont = this.getContentPane(); cont.setLayout(null); imgPlane = new ImageIcon("find.jpg"); imgBullet = new ImageIcon("bullet.jpg"); planeX = 0; planeY = 150; bulletX = 400; bulletY = 150; planeSpeed = 8; bulletSpeed = 8; planeChangeSpeed = 6; btnUp = new JButton("up"); btnDown = new JButton("down"); btnUp.setBounds(0, 240, 80, 30); btnDown.setBounds(90, 240, 80, 30); btnUp.addActionListener(this); btnDown.addActionListener(this); cont.add(btnUp); cont.add(btnDown); thread = new Thread(this); thread.start(); this.setVisible(true); } public void paint(Graphics grp){ super.paint(grp); imgPlane.paintIcon(this, grp, planeX, planeY); imgBullet.paintIcon(this, grp, bulletX, bulletY); } public void run(){ while((bulletX > 0) &&(planeX < 400)){ repaint(); planeX = planeX + planeSpeed; bulletX = bulletX - bulletSpeed; try{ Thread.sleep(200); }catch(Exception e){} } thread = null; } public void actionPerformed(ActionEvent aEvt){ JButton ob=(JButton)aEvt.getSource(); if(ob==btnUp){ planeY-=planeChangeSpeed; } if(ob==btnDown){ planeY+=planeChangeSpeed; } } public static void main(String args[]){ new Animation(); } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.