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

📄 indyapplet.java~1~

📁 大量java源程序
💻 JAVA~1~
字号:
/*
 * @(#)IndyApplet
 *
 * Copyright (c) 1998 Karl Moss. All Rights Reserved.
 *
 * You may study, use, modify, and distribute this software for any
 * purpose provided that this copyright notice appears in all copies.
 *
 * This software is provided WITHOUT WARRANTY either expressed or
 * implied.
 *
 * @author  Karl Moss
 * @version 1.0
 * @date    17Apr98
 *
 */

package javaservlets.tunnel;

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

/**
  * <p>This applet demonstrates how to use the tunnel clients
  * to perform remote method calls using serialization
  */

public class IndyApplet
  extends Applet
  implements ActionListener
{
  // Define our global components
  TextField year = new TextField(10);
  TextField driver = new TextField(20);
  TextField speed = new TextField(10);
  Button query = new Button("Query");
  IndyInterface indy;

  /**
    * <p>Initialize the applet
    */
  public void init()
    {
      // Don't allow the results to be edited
      driver.setEditable(false);
      speed.setEditable(false);

      // Use a grid bag layout
      GridBagLayout gridbag = new GridBagLayout();
      GridBagConstraints gbcon = new GridBagConstraints();
      setLayout(gridbag);

      // Setup the reusable constraint
      gbcon.weightx = 1.0;
      gbcon.weighty = 0.0;
      gbcon.anchor = gbcon.CENTER;
      gbcon.fill = gbcon.NONE;
      gbcon.gridwidth = gbcon.REMAINDER;

      // Add listeners
      query.addActionListener(this);

      // Add the components
      add(new Label("Enter the year:"));
      gridbag.setConstraints(year, gbcon);
      add(year);

      add(new Label("Press to query:"));
      gridbag.setConstraints(query, gbcon);
      add(query);

      add(new Label("Driver(s):"));
      gridbag.setConstraints(driver, gbcon);
      add(driver);

      add(new Label("Average Speed:"));
      gridbag.setConstraints(speed, gbcon);
      add(speed);

      // Create an instance of our remote object
      try {
        indy = new RemoteIndyClient("http://localhost:7001/servlet/");//(getCodeBase() + "servlet/");

        // Open the database connection
        boolean rc = indy.connect();
        if (!rc) {
          System.out.println("Connection not initialized");
          indy = null;
        }

      }
      catch (Exception ex) {
        ex.printStackTrace();
      }
    }

  /**
    * <p>Called when the applet is being destroyed
    */
  public void destroy()
    {
      // If the remote object was created close the connection
      if (indy != null) {
        indy.close();
        indy = null;
      }
    }

 public void start()
 {System.out.println("I want to paint");
       int n = 0;
        try {
          n =1900;
        }
        catch (Exception ex) {
        }

        // Get the indy record
        IndyRecord r = indy.query(n);

        // Populate
        if (r != null) {
          driver.setText(r.driver);
          speed.setText("" + r.speed);
        }



 }
  /**
    * <p>Process an action
    */
  public void actionPerformed(ActionEvent event)
    {
      Object o = event.getSource();

      // Figure out which component caused the event
      if (o == query) {

        // If the indy object was not created, get out
        if (indy == null) {
          return;
        }

        // Clear the display fields
        driver.setText("");
        speed.setText("");

        // Get the year entered by the user
        int n = 0;
        try {
          n = Integer.parseInt(year.getText());
        }
        catch (Exception ex) {
        }

        // Get the indy record
        IndyRecord r = indy.query(n);

        // Populate
        if (r != null) {
          driver.setText(r.driver);
          speed.setText("" + r.speed);
        }

      }
    }

}

⌨️ 快捷键说明

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