资源简介
用java写的5层电梯模拟实验,包括开关门
代码片段和文件信息
/**
* @author 杨一峰 09030228 2011.5.17
*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class lift extends applet implements Runnable ActionListener {
Thread thread;
private static final int UP = 0;
private static final int DOWN = 1;
private static final int OPEN = 2;
private static final int CLOSE = 3;
private static final int WAIT = 4;
private boolean F1 = false;
private boolean F2 = false;
private boolean F3 = false;
private boolean F4 = false;
private boolean F5 = false;
private boolean target = false;
private boolean painted = false;
private int state = WAIT;
private int t currentfloor;
private int x y width height openxblock;
Image BufferImage;
Graphics BufferGraphics;
Button f1 f2 f3 f4 f5;
Label lab;
public void init() {
setSize(300 500);
setLayout(null);
lab = new Label(“0“);
f1 = new Button(“1“);
f2 = new Button(“2“);
f3 = new Button(“3“);
f4 = new Button(“4“);
f5 = new Button(“5“);
lab.setBounds(120 160 20 20);
f1.setBounds(200 160 30 30);
f2.setBounds(200 200 30 30);
f3.setBounds(200 240 30 30);
f4.setBounds(200 280 30 30);
f5.setBounds(200 320 30 30);
BufferImage = createImage(getSize().widthgetSize().height);
BufferGraphics = BufferImage.getGraphics();
currentfloor = 0;
openx = 0;
t = 0;
x = 20;
y = 10;
width = 80;
height = 400;
block=20;
f1.addActionListener(this);
f2.addActionListener(this);
f3.addActionListener(this);
f4.addActionListener(this);
f5.addActionListener(this);
add(lab);
add(f1);
add(f2);
add(f3);
add(f4);
add(f5);
}
public void paint(Graphics g) {
BufferGraphics.setColor(Color.white);
BufferGraphics.fillRect(0 0 getSize().widthgetSize().height);
BufferGraphics.setColor(Color.black);
BufferGraphics.fillRect(x y + 9 width + 1 height + 3);
BufferGraphics.setColor(Color.white);
BufferGraphics.drawRect(x + 1+block y + height / 5 * 4 - t + 10+block (width - 2) / 2 - openx-block
height / 5-block);
BufferGraphics.fillRect(x + 1 + (width - 2) / 2 - openx
y + height / 5 * 4 - t + 10+block openx * 2 height / 5 + 1-block);
BufferGraphics.drawRect(x + 1 + (width - 2) / 2 + openx
y + height / 5 * 4 - t + 10+block (width - 2) / 2 - openx-block
height / 5-block);
if(state==UP)
BufferGraphics.setColor(Color.red);
else
BufferGraphics.setColor(Color.black);
BufferGraphics.drawString(“△“120 200);
if(state==DOWN)
BufferGraphics.setColor(Color.red);
else
BufferGraphics.setColor(Color.black);
BufferGraphics.drawString(“▽“120 220);
lab.setText(String.valueOf(currentfloor));
painted = true;
g.drawImage(BufferImage00this);
}
public void update(Graphics g){
paint(g);
}
public void control() {
if (state == UP) {
if (t == y + height / 5 * 4)
t = y + height / 5 * 4;
- 上一篇:网上花店Java源代码
- 下一篇:Java圆形电子时钟源代码
相关资源
- Java圆形电子时钟源代码
- 网上花店Java源代码
- java点菜系统源码
- http客户端java程序
- java基于udp的聊天服务端
- Apriori算法java实现,解释也很详细
- javaweb登录功能实现,eclipse开发工具,
- java 动态获取数据库信息生成word(含
- 操作系统大作业-理发师问题
- 神州另一套笔试题JAVA
- mysql-connector-java-5.1.9.jar
- Spark大数据中文分词统计Java工程源码
- 中国象棋源码JAVA版,很详细
- smali文件编译java文件
- java jar包jbig转bmp
- Java语音聊天
- JAVA netty 获取串口数据并且下发数据
- java课程设计-拿火柴游戏
- 基于web的员工工资管理系统毕业论文
- 用java编写的科学计算器
- Java编程思想第4版源代码+习题答案
- 名片管理系统(jsp+Struts+javabean)
- java版通讯录管理系统
- java求圆周率PI的值 蒙特卡洛方法
- cache模拟器
- javaxmail jar包
- 局域网坦克大战源码Java版
- java加数据库的网吧管理系统
- javaweb英语论文原文+翻译
- 基于java的视频中车辆的标记
评论
共有 条评论