📄 sumscreen.java
字号:
package example.sum;
import javax.microedition.lcdui.*;
import java.io.IOException;
class SumScreen
extends Form
implements CommandListener, HttpPosterListener
{
private final SumMIDlet midlet;
private final HttpPoster httpPoster;
private final TextField inputField;
private final StringItem outputField;
private final Command sendCommand;
private final Command quitCommand;
private volatile boolean readyForInput = true;
SumScreen(SumMIDlet midlet,
HttpPoster httpPoster)
{
super("Sum");
this.midlet = midlet;
this.httpPoster = httpPoster;
inputField = new TextField("Input:", "1", 8, TextField.NUMERIC);
append(inputField);
outputField = new StringItem("Output:", "0");
append(outputField);
sendCommand = new Command("Send", Command.SCREEN, 2);
addCommand(sendCommand);
quitCommand = new Command("Quit", Command.EXIT, 2);
addCommand(quitCommand);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d)
{
if (!readyForInput)
{
return;
}
if (c == sendCommand)
{
try
{
String requestStr = inputField.getString();
httpPoster.sendRequest(requestStr, this);
readyForInput = false;
}
catch (IOException e)
{
outputField.setText("Error");
}
}
else if (c == quitCommand)
{
midlet.sumScreenQuit();
}
}
public void receiveHttpResponse(String response)
{
outputField.setText(response);
readyForInput = true;
}
public void handleHttpError(String errorStr)
{
outputField.setText("Error");
readyForInput = true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -