?? searchinfoscreen.java
字號(hào):
/*
* 圖書信息顯示界面類searchInfoScreen.java
*/
//package bookshop.midlet;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import java.io.*;
public class searchInfoScreen extends Canvas implements CommandListener {
String bookTitle = null;
//String bookAuthor = null;
//String bookPrice = null;
public searchInfoScreen(String topicNo) {
this.topicNo = topicNo;
//添加Back命令
addCommand(new Command("Back", Command.BACK, 1));
setCommandListener(this);
//啟動(dòng)線程獲取并顯示圖書信息
new Thread(new HttpConnector()).start();
}
private void showsearchInfo() {
repaint();
}
/**處理命令事件 */
public void commandAction(Command command, Displayable displayable) {
//如果是BACK命令則將界面切換到圖書編號(hào)輸入界面
if (command.getCommandType() == command.BACK) {
topicNoScreen clientScreen = new topicNoScreen();
Display.getDisplay(search.search).setCurrent(clientScreen);
}
}
//HTTP連接器類
class HttpConnector
implements java.lang.Runnable {
/**
* 獲取并顯示圖書信息的線程主方法
*/
public void run() {
getsearchInfo();
showsearchInfo();
}
}
/**
* 獲取圖書信息的方法
*/
public void getsearchInfo() {
try {
HttpConnection connection = (HttpConnection) Connector.open(
"http://localhost:7001/book/bookServlet?topicNo=" + topicNo);
InputStream is = null;
is = connection.openInputStream();
DataInputStream dis = new DataInputStream(is);
bookTitle = dis.readUTF(); // 從服務(wù)器端獲取圖書信息
//bookAuthor = dis.readUTF();
// bookPrice = dis.readUTF();
dis.close();
is.close();
connection.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}
public void paint(Graphics g) {
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0x000000);
//顯示圖書信息
if (bookTitle != null) {
g.drawString("主題:" + bookTitle, 0, 0, Font.SIZE_MEDIUM);
//g.drawString("作者:" + bookAuthor, 0, Font.SIZE_MEDIUM + 25,
// Font.SIZE_MEDIUM);
//g.drawString("價(jià)格:" + bookAuthor, 0, (Font.SIZE_MEDIUM + 25) * 2,
// Font.SIZE_MEDIUM);
}
}
private String topicNo = null;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -