
//Title:       Your Product Name
//Version:
//Copyright:   Copyright (c) 1998
//Author:      Mikael Bonnier
//Company:     Orbin
//Description: Your description
package dbapp;

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

//import com.sun.java.swing.UIManager;
public class QueryDB extends Applet
{
   boolean isStandalone = false;
   TextField txtCountry = new TextField();
   TextField txtCurrency = new TextField();
   Button btnNext = new Button();

   Connection dbConn;
   Statement sqlStmt;
   ResultSet rSet;
   Label lblCountry = new Label();
   Label lblCurrency = new Label();

   //Construct the applet

   public QueryDB()
   {
   }
//Initialize the applet

   public void init()
   {
      try
      {
         jbInit();
      }
      catch (Exception e)
      {
         e.printStackTrace();
      }
   }
   //static {
   //  try {
   //    //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel());
   //    //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
   //    UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
   //  }
   //  catch (Exception e) {}
   //}
//Component initialization

   private void jbInit() throws Exception
   {
      txtCountry.setBounds(new Rectangle(195, 123, 138, 27));
      txtCurrency.setBounds(new Rectangle(195, 164, 138, 27));
      btnNext.setBounds(new Rectangle(274, 208, 59, 25));
      btnNext.setLabel("Next");
      lblCountry.setBounds(new Rectangle(103, 129, 86, 23));
      lblCountry.setText("Country:");
      lblCurrency.setBounds(new Rectangle(100, 168, 92, 24));
      lblCurrency.setText("Currency:");
      btnNext.addActionListener(new java.awt.event.ActionListener()
      {
         public void actionPerformed(ActionEvent e)
         {
            btnNext_actionPerformed(e);
         }
      });
      this.setLayout(null);

      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      this.add(txtCountry, null);
      this.add(txtCurrency, null);
      this.add(btnNext, null);
      this.add(lblCountry, null);
      this.add(lblCurrency, null);
   }
//Start the applet
   
   public void start()
   {
      try
      {
         dbConn = DriverManager.getConnection("jdbc:odbc:DataSet Tutorial",
            "SYSDBA", "masterkey");
         sqlStmt = dbConn.createStatement();
         rSet = sqlStmt.executeQuery(
            "SELECT COUNTRY, CURRENCY"
            + " FROM COUNTRY");
      }
      catch(SQLException e)
      {
         System.out.println(e);
      }
      showNextRow();
   }
//Stop the applet

   public void stop()
   {
      try
      {
         sqlStmt.close();
         dbConn.close();
      }
      catch(SQLException e)
      {
         System.out.println(e);
      }
   }
//Destroy the applet
   
   public void destroy()
   {
   }
//Get Applet information
   
   public String getAppletInfo()
   {
      return "Applet Information";
   }
//Get parameter info
   
   public String[][] getParameterInfo()
   {
      return null;
   }
//Main method
   
   public static void main(String[] args)
   {
      QueryDB applet = new QueryDB();
      applet.isStandalone = true;
      Frame frame = new Frame();
      frame.addWindowListener(new WindowAdapter()
         {
            public void windowClosing(WindowEvent we)
            {
               System.exit(0);
            }
         });
      frame.setTitle("Applet Frame");
      frame.add(applet, BorderLayout.CENTER);
      applet.init();
      applet.start();
      frame.setSize(400,320);
      Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
      frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
      frame.setVisible(true);
   }

   void btnNext_actionPerformed(ActionEvent e)
   {
      showNextRow();
   }

   void showNextRow()
   {
      try
      {
         rSet.next();
         txtCountry.setText(rSet.getString("COUNTRY"));
         txtCurrency.setText(rSet.getString("CURRENCY"));
      }
      catch(SQLException e)
      {
         System.out.println(e);
      }
   }
}


