资源简介
用java的swing编程写的线程,实现绘图,画月亮升起降落,星星闪烁

代码片段和文件信息
package com.noon;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.Jframe;
import javax.swing.JPanel;
public class ChangeNoon extends Jframe implements ActionListener{
JPanel jp1;
JButton jb1;
PaintNoon noon;
public ChangeNoon() {
noon = new PaintNoon();
jb1=new JButton(“开始“);
jb1.addActionListener(this);
jp1=new JPanel();
jp1.add(jb1);
this.add(noon);
this.add(jp1“South“);
this.setSize(450 400);
this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
this.settitle(“月亮“);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ChangeNoon noon = new ChangeNoon();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb1){
new Thread(noon).start();
}
}
}
class PaintNoon extends JPanel implements Runnable{
Noon noon1 = new Noon(10 150 50);
Noon noon2 = new Noon(-30 115 80);
boolean flag=true;
int xPoint[]={225223215222220225230228235227};
int xPoint2[]={20181017142026233022};
int yPoint[]={150160160163170165170163160160};
int yPoint2[]={10202023322532232020};
public void paint(Graphics g) {
super.paint(g);
g.setColor(Color.black);
g.fillRect(0 0 450 300);
g.setColor(Color.yellow);
//圆
g.fillOval(noon1.getX() noon1.getY() noon1.getR() noon1.getR());
//g.fillRect(10 10 10 10);
g.setColor(Color.black);
g.fillOval(noon2.getX() noon2.getY() noon2.getR() noon2.getR());
//change();
//星星
if(flag)
{
g.setColor(Color.yellow);
g.fillPolygon(xPoint yPoint 10);
g.setColor(Color.black);
g.fillPolygon(xPoint2 yPoint2 10);
}else
{
g.setColor(Color.yellow);
g.fillPolygon(xPoint2 yPoint2 10);
g.setColor(Color.black);
g.fillPolygon(xPoint yPoint 10);
}
//g.fillPolygon(xPoint yPoint 10);
// g.fillPolygon(xPoint2 yPoint2 10);
//
}
public void paintDraw(Noon noon1Noon noon2Graphics g){
g.setColor(Color.yellow);
// 圆
g.fillOval(noon1.getX() noon1.getY() noon1.getR() noon1.getR());
g.setColor(Color.black);
g.fillOval(noon2.getX() noon2.getY() noon2.getR() noon2.getR());
}
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 1; i < 180; i++) {
if(i%3==0){
int n=i/3;
if(n%2==0){
flag=true;
}
if(n%2==1){
flag=false;
}
}
try {
Thread.sleep(50);
noon1.setX(noon1.getX()+2);
noon2.setX(noon2.getX()+2);
if(i<40){
noon1.setY(noon1.getY()-2);
noon2.setY(noon2.getY()-2);
}else if(i>=40&&i<80){
noon1.setY(noon1.getY()-1);
noon2.setY(noon2.getY()-1);
}else if(i>=80&&i<100){
//noon.setY(noon.getY()+1);
}else if(i
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3894 2011-10-24 11:24 noon\ChangeNoon.java
文件 803 2011-10-24 10:55 noon\XingXing.java
目录 0 2011-10-28 22:07 noon
----------- --------- ---------- ----- ----
4697 3
- 上一篇:支付宝app登入授权,现金红包
- 下一篇:java的swing实现计时与倒计时
相关资源
- 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投票实例
评论
共有 条评论