资源简介
用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圆形电子时钟源代码
相关资源
- 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投票实例
评论
共有 条评论