⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 searchinfoscreen.java

📁 本程序是一个查询程序
💻 JAVA
字号:
/*
 *  图书信息显示界面类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);
    //启动线程获取并显示图书信息
    new Thread(new HttpConnector()).start();
  }

  private void showsearchInfo() {
    repaint();
  }

  /**处理命令事件 */
  public void commandAction(Command command, Displayable displayable) {
    //如果是BACK命令则将界面切换到图书编号输入界面
    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(); // 从服务器端获取图书信息
      //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("价格:" + bookAuthor, 0, (Font.SIZE_MEDIUM + 25) * 2,
            //       Font.SIZE_MEDIUM);

    }
  }

  private String topicNo = null;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -