简体   繁体   中英

Java Applet not Displaying Correctly

I've written a small java applet to act as an online form which will take in information pertaining to orders etc... and sent appropriate emails to company inboxes. My problem is that the applet is not loading correctly and that none of the event-driven code in the program is running. (This includes functions which populate lists and choices within the form). I've asked my co-worker if he has put up the *.class file onto the company webserver (in the same directory as the html code being executed), and he has verified that he has.

I'm stumped, what could be causing the applet to be failing to load properly and what would cause the applet not to able to fire-off event driven code? Here is the applet in a shortened version (it's a little lengthy so look out, really draw your attention to methods like the get* * (), which is one of the methods which isn't running, it populates the distributor list with choices).

package OrderSpecs;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Properties;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.mail.*;
import javax.mail.internet.*;

import java.util.Date;
import java.text.SimpleDateFormat;
import javax.swing.JTextField;


public class OrderSpecs extends JApplet implements ActionListener {

    /**
     * This is the OrderSpecs default constructor
     */
    public OrderSpecs() {
        super();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    public void init() {
        this.setPreferredSize(new Dimension(880, 1279));
        this.setSize(880, 1279);
        this.setContentPane(new JScrollPane(getJContentPane()));

        applicationList = new ArrayList<Application>();

        Date dateNow = new Date ();
        SimpleDateFormat dateformatMMDDYYYY = new SimpleDateFormat("MM/dd/yyyy");
        this.dateString = new StringBuilder( dateformatMMDDYYYY.format( dateNow ) );
    }

    /**
     * Initialize the list of industries for the drop-down list
     */
    private String[] getIndustryList()
    {
        String[] industries = 
        {
                "            ", "Commercial Lab", "Environmental", "Food / Wine", "Government", "Marine Lab", 
                "Other", "Petro Chemical", "Power Generation", "Pulp & Paper", "University"
        };
        return industries;
    }

I'm using Eclipse for applet development and when I compile / run the code it appears perfectly on my machine, any ideas? Thanks a lot,

  • Mike

but the textboxes will be of 0 length

Well that depends on how you define the text field. If you use:

JTextField textField = new JTextField();

Then the text field will have a size equal to the text which in this case is 0. You should be using something like the following to give a preferred size:

JTextField textField = new JTextField(10);

and none of the drop-down boxes that I have in the applet are populated with any values

Again we can't tell from the posted code what you are doing so we can't offer any help.

The applet in its entirety is very long,

So the question is why are you writing a program that is very long without doing any debugging along the way? Start by creating a 10 line program that simply creates a combo box, adds data to the model and displays the combo box on the GUI. If it works great, now you can compare the working code with your program to see what you are doing differently.

If it doesn't work then you have a simple complete program to post on the forum. This is called a SSCCE . Otherwise we are just making wild guesses which is not very good use of our time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM