📄 displayable1.java
字号:
package paowuxian;
import javax.microedition.lcdui.*;
import java.io.*;
import java.util.Hashtable;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Displayable1 extends Canvas implements CommandListener ,Runnable{
private Image imgWu=null;
private int x,y;
private boolean bFire=false;
Thread thisThread;
// public Hashtable angleValue;
//public int tempAngle;
//public int tempValue;
private int angle=45;
private int v0=10;
private int windSpeed=0;//300000;
private int vx,vy;
private boolean bShowline=true;
private int t,tTemp;
public Displayable1() {
Resource.loadAngleValue();
try {
imgWu = Image.createImage("/images/paodan.png");
y =getHeight()-imgWu.getHeight();
// x=getWidth()/2;
}
catch (IOException ex) {
}
thisThread=new Thread(this);
thisThread.start();
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
// Set up this Displayable to listen to command events
setCommandListener(this);
// add the Exit command
addCommand(new Command("Exit", Command.EXIT, 1));
}
public void commandAction(Command command, Displayable displayable) {
/** @todo Add command handling code */
if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
MIDlet1.quitApp();
}
}
private void gameRun(){
if(bFire){
x= (vx+windSpeed )*t /100000; ;
int pianyi=(t*400000);
if(vy==0){
pianyi=0;
}else if(vy<0){
pianyi=280000*t;
}
y=(100000*(getHeight()-imgWu.getHeight())-(vy*t-100000*t*t+pianyi))/100000;
// bFire=false;
}
repaint();
}
protected void paint(Graphics g) {
g.setColor(0xffffffff);
g.fillRect(50,10,80,40);
if(bShowline){
g.setColor(0xffffffff);
g.fillRect(0,0,getWidth(),getHeight());
}
g.setColor(0x0000ff);
g.drawString("角度"+angle+"(按8/2键调整)",50,0,0);
g.drawString("力度"+v0+"(按1)",50,10,0);
g.drawString("是否留下轨迹"+(bShowline?" 否":" 是")+"(按3)",50,20,0);
g.drawString("风力"+windSpeed/100000+"(按7/9)",50,30,0);
g.drawImage(imgWu,x,y,0);
}
public void run(){
while (true){
try {
thisThread.sleep(10);
if(bFire){
tTemp++;
if (tTemp >2) {
t+=1;
tTemp = 0;
}
if(y>getHeight()||x>getWidth()){
x=0;
y=getHeight()-imgWu.getHeight();
bFire=false;
vx=0;vy=0;
t=0;
v0=10;
}
}
}
catch (InterruptedException ex) {
}
gameRun();
}
}
/**
* keyPressed
*
* @param keyCode int
* @todo Implement this javax.microedition.lcdui.Canvas method
*/
protected void keyPressed(int keyCode) {
if(keyCode==KEY_NUM5){
bFire=true;
vx=Resource.getCosAngleValue(angle)*v0;
vy=Resource.getSinAngleValue(angle)*v0;
}else if(keyCode==KEY_NUM8){
if(angle>0){
angle -= 3;
}
}
else if(keyCode==KEY_NUM2){
if(angle<90){
angle += 3;
}
}else if(keyCode==KEY_NUM1){
v0++;
}else if(keyCode==KEY_NUM3){
bShowline=!bShowline;
}else if(keyCode==KEY_NUM7){
windSpeed+=100000;
}else if(keyCode==KEY_NUM9){
windSpeed-=100000;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -