📄 elementinfoscreen.java
字号:
package webservice.midlet;import javax.microedition.lcdui.*;import javax.microedition.io.*;import java.io.*;public class ElementInfoScreen extends Canvas implements CommandListener { String elementName = null; public ElementInfoScreen(String elementNumber) { this.elementNumber = elementNumber; addCommand(new Command("Back", Command.BACK, 1)); setCommandListener(this); new Thread(new HttpConnector()).start(); } private void showElementInfo () { repaint(); } /**处理命令事件*/ public void commandAction(Command command, Displayable displayable) { if(command.getCommandType()==command.BACK) { ElementNumberScreen clientScreen = new ElementNumberScreen(); Display.getDisplay(ChemistryMIDlet.chemistryMIDlet).setCurrent(clientScreen); } } class HttpConnector implements java.lang.Runnable { /*** 在线程主函数中调用获取化学元素名称方法获取化学元素名称,* 并调用显示方法进行显示。*/ public void run () { getElementName(); showElementInfo (); } } /** * 获取元素名称方法 */public void getElementName () { try { HttpConnection connection = (HttpConnection)Connector.open("http://localhost:7001/midp/chemistryservlet?inputpara="+elementNumber); InputStream is = null; is = connection.openInputStream(); DataInputStream dis = new DataInputStream(is); elementName = 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 (elementNumber != null) { g.drawString("元素号 : " + elementNumber, 0, 20, Font.SIZE_MEDIUM); } if (elementName != null) { g.drawString("元素名称 : " + elementName, 0, 40, Font.SIZE_MEDIUM); } } private String elementNumber = null;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -