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

📄 topics.java

📁 JAVA Servlet2.3外文书籍源码
💻 JAVA
字号:
package forum;

import java.util.*;

/**
 * Represents all topics in the discussion forum.
 * <p>
 * In a real system there would be a database containing the topics.
 *
 * @author    Simon Brown
 */
public class Topics {

  /** a collection of all topics in the system */
  private static ArrayList topics = new ArrayList();

  /**
   * Populates the collection of all topics when the class is loaded.
   */
  static {
    Topic topic;
    Response response;
    User user1, user2;

    user1 = Users.getUser("Simon");
    user2 = Users.getUser("Sam");

    topic = new Topic(0, user1, "How do I write a Java Servlet?", "How do I write a Java Servlet and which class do I need to extend?");
    topic.add(new Response(user2, "You need to write a Java class that extends <code>javax.servlet.http.HttpServlet</code>, and implement the doGet or doPost methods."));
    topic.add(new Response(user1, "What's the purpose of doGet and doPost?"));
    topics.add(topic);

    topic = new Topic(1, user1, "Front Controller pattern?", "How do I use it?");
    topics.add(topic);

    topic = new Topic(2, user1, "HTTP session timeout", "When does the session timeout?");
    topics.add(topic);
  }

  /**
   * Gets a collection of all topics in the system.
   *
   * @return  a Collection of Topic instances
   */
  public static Collection getTopics() {
    return topics;
  }

  /**
   * Looks up the Topic with the specified id.
   *
   * @param id    the topic id
   * @return  the appropriate Topic instance
   */
  public static Topic getTopic(int id) {
    return (Topic)topics.get(id);
  }

}

⌨️ 快捷键说明

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