📄 fullscreen.java~123~
字号:
package fullscreen;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.media.*;
import javax.wireless.messaging.*;
import java.io.*;
public class fullScreen
extends MIDlet
implements CommandListener, MessageListener, Runnable {
Thread thread;
/** Connections detected at start up. */
// String[] connections;
/** Flag to signal end of processing. */
boolean done;
Message msg;
MessageConnection smsconn;
String smsConnection = "sms://:" + "6262";
//sms://:6262
private Command exitCommand;
private Command showCommand;
private Command fullCommand;
private Command menuCommand1;
private Command menuCommand2;
private Command menuCommand3;
private Command menuCommand4;
private Command menuCommand5;
private Command menuCommand6;
private Command menuCommand7;
private fullScreenCanvas sg;
public fullScreen() {
exitCommand = new Command("退出系统", Command.EXIT, 11);
showCommand = new Command("正常", Command.SCREEN, 1);
fullCommand = new Command("全屏", Command.SCREEN, 1);
menuCommand1 = new Command("进入交易", Command.SCREEN, 1);
menuCommand2 = new Command("交易历史查询", Command.SCREEN, 10);
menuCommand3 = new Command("供应商信息", Command.SCREEN, 10);
menuCommand4 = new Command("货物信息", Command.SCREEN, 10);
menuCommand5 = new Command("过期消息", Command.SCREEN, 10);
menuCommand6 = new Command("取消交易", Command.SCREEN, 1);
menuCommand7 = new Command("播放声音", Command.SCREEN, 2);
sg = new fullScreenCanvas();
sg.addCommand(exitCommand);
sg.addCommand(fullCommand);
sg.setCommandListener(this);
sg.setTitle(this.getClass().getName());
}
protected void startApp() {
/** Open the message connection. */
/** Open the message connection. */
if (smsconn == null) {
try {
smsconn = (MessageConnection) Connector.open(smsConnection);
smsconn.setMessageListener(this);
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
done = false;
thread = new Thread(this);
thread.start();
Display.getDisplay(this).setCurrent(sg);
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) {
}
public void commandAction(Command c, Displayable d) {
if (c == exitCommand) {
destroyApp(false);
notifyDestroyed();
}
// if (c == showCommand) {
// sg.addCommand(fullCommand);
// sg.removeCommand(showCommand);
// sg.show();
//
// }
// if (c == fullCommand) {
// sg.removeCommand(fullCommand);
// sg.addCommand(showCommand);
// sg.addCommand(menuCommand1);
// sg.addCommand(menuCommand2);
// sg.addCommand(menuCommand3);
// sg.addCommand(menuCommand4);
// sg.addCommand(menuCommand5);
// sg.addCommand(menuCommand6);
// sg.addCommand(menuCommand7);
//
// sg.full();
//
// }
// if (c == menuCommand1) {
// this.connect();
// }
// if (c == this.menuCommand6) {
// sg.show("你已取消交易!");
// }
// if (c == this.menuCommand7) {
// this.playWAV();
// }
}
SocketConnection connection = null;
OutputStream os = null;
InputStream is = null;
public void connect() {
try {
connection = (SocketConnection) Connector.open(
// "socket://211.152.109.101:9999");
"socket://127.0.0.1:9999");
connection.setSocketOption(SocketConnection.LINGER, 15);
// this.connection.setSocketOption((byte)'1', 15);
byte iii = connection.DELAY;
os = connection.openDataOutputStream();
os.write("hello dachan!\r\n".getBytes());
is = connection.openDataInputStream();
int ch;
ByteArrayOutputStream tmp = new
ByteArrayOutputStream();
while ( (ch = is.read()) != -1) {
tmp.write(ch);
if (ch == 50) { //'2'
break;
}
}
os.write("see u!\r\n".getBytes());
byte[] b = tmp.toByteArray();
StringBuffer s = new StringBuffer();
for (int i = 0; i < b.length - 1; i++) {
s.append( (char) b[i]);
}
this.sg.show(s.toString());
// this.sg.setTitle(s.toString());
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
// data = tmp.toByteArray();
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
if (connection != null) {
connection.close();
}
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public void playWAV() {
try {
InputStream in = getClass().getResourceAsStream("hello.wav");
Player p = Manager.createPlayer(in, "audio/x-wav");
p.start();
}
catch (MediaException pe) {
pe.printStackTrace();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
/**
* notifyIncomingMessage
*
* @param messageConnection MessageConnection
*/
public void notifyIncomingMessage(MessageConnection messageConnection) {
if (thread == null) {
done = false;
thread = new Thread(this);
thread.start();
}
}
/**
* run
*/
public void run() {
try {
msg = smsconn.receive();
}
catch (IOException e) {
// e.printStackTrace();
}
}
}
class fullScreenCanvas
extends Canvas {
private boolean fulled = false; //cleared 表示被清除了
private boolean showString = false;
private String s = "";
private javax.microedition.lcdui.TextField aaa = new TextField("asdf", "asdf", TextField.ANY, TextField.PASSWORD);
protected fullScreenCanvas() {
fulled = false;
}
protected void paint(Graphics g) {
if (showString) {
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
g.drawString(s, this.getWidth() / 2 - 2, this.getHeight() / 2 - 2,
Graphics.BOTTOM | Graphics.HCENTER);
showString = false;
}
else if (!fulled) {
//先清屏,后显示字符串
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
g.drawString("目前状态:正常屏幕", this.getWidth() / 2, this.getHeight() / 2,
Graphics.BOTTOM | Graphics.HCENTER);
}
else {
//先清屏,后显示字符串
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
g.drawString("目前状态:全屏", this.getWidth() / 2, this.getHeight() / 2,
Graphics.BOTTOM | Graphics.HCENTER);
fulled = true;
}
}
public void full() {
setFullScreenMode(true);
fulled = true;
repaint();
}
public void show() {
setFullScreenMode(false);
fulled = false;
repaint();
}
public void show(String s) {
setFullScreenMode(true);
this.s = s;
this.showString = true;
repaint();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -