Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8617323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:49:39+00:00 2026-06-12T05:49:39+00:00

Here is my current program: import java.applet.Applet; import java.awt.Graphics; import java.io.FileInputStream; import java.io.FileNotFoundException; import

  • 0

Here is my current program:

import java.applet.Applet;
import java.awt.Graphics;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.swing.JComboBox;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.Properties;

public class CodesApplet extends Applet 
{
    private Properties properties;
    private String configFilePath;
    private FileInputStream fis;
    private String driverName;
    private String userName;
    private String password;
    private String url;

    private Connection conn;
    private Statement st;
    private Timestamp created = new Timestamp(System.currentTimeMillis());

    private JComboBox codes1;
    private JComboBox codes2;
    private JComboBox otherCodes;

    public void init() 
    {
        try 
        {
            //Loads the values from the properties file 
            try 
            {
                properties = new Properties();
                configFilePath="C:\\scriptProps.properties";
                fis = new FileInputStream(configFilePath);

                properties.load(fis);

                if (fis != null)
                {
                    fis.close();
                }
            } 
            catch (FileNotFoundException e) 
            {
                System.err.println("init(): FileNotFoundException(): " + e.getMessage());
            }

            driverName=properties.getProperty("driverName");
            userName=properties.getProperty("userName");
            password=properties.getProperty("password");
            url=properties.getProperty("url");

            //Establishes the connection to the database
            System.out.println("init(): loading OracleDriver for applet created at " + created.toString());
            Class.forName(driverName);
            System.out.println("init(): getting connection");
            conn = DriverManager.getConnection(url, userName, password);
            st = conn.createStatement();

            //Instantiates the previously declared variables for the drop-downs.
            codes1 = new JComboBox();
            codes2 = new JComboBox();
            otherCodes = new JComboBox();
        }
        catch (ClassNotFoundException e)
        {
            System.err.println("init(): ClassNotFoundException: " + e.getMessage());
        } 
        catch (SQLException e)
        {
            System.err.println("init(): SQLException: " + e.getMessage());
        } catch (IOException e) 
        {
            System.err.println("init(): IOException. " + e.getMessage());
        }
    }

    public void start() 
    {
        System.out.println("start(): ");
    }

    public void stop()
    {
        System.out.println("stop(): ");
    }

    //Returns the first drop-down...
    public JComboBox getComboBox1() 
    {
        codes1.removeAllItems();
        codes1.addItem("Please Select...");

        try 
        {
            ResultSet rs = st.executeQuery("select codes from myTable");

            while (rs.next()) 
            {
                codes1.addItem(rs.getString("codes"));
            }

            rs.close();
            st.close();
        } 
        catch (SQLException sqle)
        {
            System.out.println(sqle);
        }

        return codes1;
    }

    //Returns the second drop-down...
    public JComboBox getComboBox2() 
    {
        codes2.removeAllItems();
        codes2.addItem("Please Select...");

        try 
        {
            ResultSet rs = st.executeQuery("select codes from myTable");

            while (rs.next()) 
            {
                codes2.addItem(rs.getString("codes"));
            }

            rs.close();
            st.close();
        } 
        catch (SQLException sqle)
        {
            System.out.println(sqle);
        }

        return codes2;
    }

    //Returns the third drop-down...
    public JComboBox getComboBox3() 
    {
        otherCodes.removeAllItems();
        otherCodes.addItem("Please Select...");

        try 
        {
            ResultSet rs = st.executeQuery("select otherCodes from myTable2");

            while (rs.next()) 
            {
                otherCodes.addItem(rs.getString("otherCodes"));
            }

            rs.close();
            st.close();
        } 
        catch (SQLException sqle)
        {
            System.out.println(sqle);
        }

        return otherCodes;
    }

    public void paint(Graphics g)
    {
        System.out.println("paint(): creating the drop-downs...");

        getComboBox1();
        getComboBox2();
        getComboBox3();
    }

    public void destroy() 
    {
        System.out.println("destroy(): closing connection for applet created at " + created.toString());

        try 
        {
            conn.close();
        } 
        catch (SQLException e) 
        {
            System.err.println("destroy: SQLException: " + e.getMessage());
        }
    }
}

Essentially, what I want to do is have this applet that pulls data from multiple tables and populates drop-down boxes with that data. I’ve seen some examples on how to do this with one drop-down (thus why you see one return statement involving codes1).

My primary questions are:

  • In general, am I doing this right? Is this the best way to pull in multiple fields from multiple tables?
  • Also, I understand that this would only populate the combo boxes. If I wanted to allow the user to hit a button after selecting the appropriate values from the drop-downs (after they’ve been populated), and store those values to a separate table in the database, how would I do that?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:49:41+00:00Added an answer on June 12, 2026 at 5:49 am

    There are many problems in your applet:

    • You never add your comboboxes to a top-level container hierarchy
    • You can add ActionListener to the JComboBoxes if you want to be notified of user selection changes
    • You should not override paint
    • You are recreating the content of your comboboxes everytime paint is called. You should rather create and add your comboboxes upon applet initalization
    • Applet are usually distributed through web pages/server: your propery file won’t be available
    • Unless your database allow remote access, this will not work.
    • To add a button to the display, simply call new JButton(“My button”) and add it to the component hierarchy
    • …

    Here is a link to Swing tutorials. I think that many chapters can help you

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my current code , and here's my current output: This program will calculate
I am writing a program for Bully Algorithm in Java Here is the code:
Here's my current situation: I have a NSMutableArray named dictKeyArray which I assign a
Here is the current code in my application: String[] ids = str.split("/"); When profiling
Here is the current code I am using to parse the URL and it's
Here is my current position with a Jquery Banner - http://jsfiddle.net/WcXBs/2/ Apologies for the
Here is my current setup. I have two pages running on the jquery mobile
Here is my current code in the controller. @rating = (@approvals.count / @user.pages.count) +
Here is my current situation; I am a near complete regexp illiterate, and have
Here is my current setup: Database Role - MyDbRole Schema - MySchema User -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.