📄 touchscreenmidlet.java
字号:
/*
* * @(#) TouchScreenMidlet.java 1.15 2007-11-13
*/
import java.io.IOException;
import java.util.Enumeration;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class TouchScreenMidlet extends MIDlet implements CommandListener
{
private Display display;
private Command exitCommand;
private NewTouchCanvas touchCanvas;
public TouchScreenMidlet()
{
System.out.println("Hello");
this.display = Display.getDisplay(this);
this.exitCommand = new Command("退出", Command.EXIT, 1);
}
public void startApp(){
touchCanvas = new NewTouchCanvas();
display.setCurrent(touchCanvas);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional)
{
this.notifyDestroyed();
}
public void commandAction(Command command, Displayable displayable)
{
if (command == this.exitCommand)
{
this.destroyApp(true);
}
}
}
class NewTouchCanvas extends Canvas
{
private String action = "";
public NewTouchCanvas()
{
super();
}
protected void paint(Graphics g)
{
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
if (hasPointerEvents())
{
g.drawString("支持触摸", 10, 10, 0);
}
else
{
g.drawString("不支持触摸", 10, 10, 0);
}
if (this.hasPointerMotionEvents())
{
g.drawString("支持拖动", 10, 20, 0);
}
else
{
g.drawString("不支持拖动", 10, 20, 0);
}
g.drawString(action, 10, 30, 0);
}
protected void pointerPressed(int x, int y)
{
action = "<pp> x :" + x + "|" + " y :" + y;
repaint();
}
protected void pointerReleased(int x, int y)
{
action = "<pr> x :" + x + "|" + " y :" + y;
repaint();
}
protected void pointerDragged(int x, int y)
{
action = "<pd> x :" + x + "|" + " y :" + y;
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -