资源简介
用两个圆叠加实现简单的实现月食的模拟,采用多线程实现动画效果。

代码片段和文件信息
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Sky extends Jframe implements ComponentListenerActionListenerRunnable
{
private Thread thread_rollby;
private JPanel Jpanel_1Jpanel_2;
private JButton Jbutton_playJbutton_pauseJbutton_fastJbutton_slowJbutton_stop;
private JLabel Jlabel_speed;
static int xy;
static int sleeptime=80;
public Sky()
{super(“月食“);
this.setSize(680400);
this.setLocation(200240);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
Jpanel_1=new JPanel(new FlowLayout(0));
this.add(Jpanel_1BorderLayout.NORTH);
Jpanel_1.setBackground(Color.BLACK);
Jbutton_play=new JButton(“播放“);
Jpanel_1.add(Jbutton_play);
Jbutton_play.addActionListener(this);
Jbutton_pause=new JButton(“暂停“);
Jpanel_1.add(Jbutton_pause);
Jbutton_pause.addActionListener(this);
Jbutton_pause.setEnabled(false);
Jbutton_fast=new JButton(“加速“);
Jpanel_1.add(Jbutton_fast);
Jbutton_fast.addActionListener(this);
Jbutton_slow=new JButton(“减速“);
Jpanel_1.add(Jbutton_slow);
Jbutton_slow.addActionListener(this);
Jbutton_stop=new JButton(“停止“);
Jpanel_1.add(Jbutton_stop);
Jbutton_stop.addActionListener(this);
Jbutton_stop.setEnabled(false);
Jpanel_2=new JPanel(new FlowLayout(0));
this.add(Jpanel_2BorderLayout.CENTER);
Jpanel_2.setSize(600400);
Jpanel_2.setBackground(Color.BLACK);
Jlabel_speed=new JLabel(“中速“);
Jlabel_speed.setForeground(Color.YELLOW);
Jpanel_2.add(Jlabel_speed);
this.addComponentListener(this);
x=Jpanel_2.getWidth()/15;
y=Jpanel_2.getHeight()/4;
this.setVisible(true);
}
public void run()
{while(thread_rollby.isAlive()&&!thread_rollby.isInterrupted())
{x=x+1;
try{
repaint();
thread_rollby.sleep(sleeptime);
}
catch(InterruptedException e)
{break;
}
}
}
public void paint(Graphics g)
{super.paint(g);
int diameter=Math.min(Jpanel_2.getWidth()*2/3Jpanel_2.getHeight()*2/3);
g.setColor(Color.YELLOW);
g.fillOval(280ydiameterdiameter);
g.setColor(Jpanel_2.getBackground());
g.fillOval(xydiameterdiameter);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Jbutton_play)
{thread_rollby=new Thread(this);
thread_rollby.start();
Jbutton_play.setEnabled(false);
Jbutton_pause.setEnabled(true);
Jbutton_stop.setEnabled(true);
}
if(e.getSource()==Jbutton_pause)
{thread_rollby.interrupt();
Jbutton_pause.setEnabled(false);
Jbutton_play.setEnabled(true);
}
if(e.getSource()==Jbutton_fast)
{
Jbutton_slow.setEnabled(true);
sleeptime/=2;
switch(sleeptime)
{case 160:Jlabel_speed.setText(“较慢“);break;
case 80:Jlabel_speed.setText(“中速“);break;
case 40:Jlabel_speed.setText(“较快“);break;
case 20:{Jlabel_speed.setText(“快速“);
Jbutton_fast.setEnabled(false);
}break;
}
}
if(e.getSource()==Jbutton_slow)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4109 2009-06-08 15:01 Sky\Sky.class
文件 3899 2009-06-08 15:01 Sky\Sky.java
目录 0 2010-03-22 15:00 Sky
----------- --------- ---------- ----- ----
8008 3
- 上一篇:android断点续传demo
- 下一篇:java初学者习题
相关资源
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
- [免费]java实现有障碍物的贪吃蛇游戏
- java Servlet投票实例
评论
共有 条评论