Solved

ok in Netscape, applet does not display in IE

Posted on 2000-05-11
3
167 Views
Last Modified: 2010-04-01
I have a somewhat simple Applet that displays ok in Netscape 4.5 but I just get a grey box in IE 5.0 - any ideas?  I guess it is probably some var that needs to be set differently depending on the browser.  I've tried everything I can think of with my limited java experience.
Thanks! -BB

Here is most of the code:

import java.applet.*;
    :
    :
    :

public class t9citypair extends Applet {
    List attcoaList = new List(22, false);
    List attcozList = new List(22, false);
    List speedList = new List(4, false);
        Button priceButton = new Button("Price");
        TextField costTextField = new TextField(13);
        TextField dateTextField = new TextField(12);
        TextArea miscTextArea = new TextArea("", 15, 38);
        Font lblFont = new Font("Times", Font.BOLD, 12);
        Font effdateFont = new Font("Times", Font.BOLD, 14);
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints constr = new GridBagConstraints();
    Font f;
        public void init() {
        f = new Font("Monospaced", Font.PLAIN, 12);
        miscTextArea.setFont(f);
        constr.fill=GridBagConstraints.NONE;
        constr.insets = new Insets(2, 2, 2, 2);
        setLayout(gbl);
        setBackground(new Color(0xC0C0C0));
        speedList.addItem("T45");
        speedList.addItem("OC3");
        speedList.select(0);

        Label speedLabel = new Label("Speed");
        constr.gridx=0; constr.gridy=0; constr.gridwidth=2; constr.gridheight=1;
        constr.weightx = 0.0; constr.weighty = 0.0;
        constr.fill=GridBagConstraints.NONE;
        speedLabel.setFont(lblFont);
        gbl.setConstraints(speedLabel, constr);
        add(speedLabel);

        constr.gridx=0; constr.gridy=1; constr.gridwidth=2; constr.gridheight=3;
        constr.weightx = 0.0; constr.weighty = 1.0;
        constr.fill=GridBagConstraints.NONE;
        gbl.setConstraints(speedList, constr);
        add(speedList);

        :
        :
        :
        constr.gridx=4; constr.gridy=18; constr.gridheight=1;
        gbl.setConstraints(dateTextField, constr);
        add(dateTextField);
        show(true);

        DataInputStream is;
        try {
            URL url = new URL("http:/  .......           " + speedList.getSelectedItem());
            is = new DataInputStream (url.openStream());
            String c = is.readLine() ;
            int nummisc = (new Integer(c)).intValue();
            int indx;

            miscTextArea.setText("Misc Charges for Speed " + speedList.getSelectedItem() + ":\n\n");

            for(indx=0; indx < nummisc; indx++) {
                c = is.readLine() ;
                miscTextArea.appendText(c + "\n");
            }
        } catch(Exception e) {
            miscTextArea.setText("Problem getting Misc. Charges");
        }

        try {
            URL url = new URL("http:/   ...................    " + speedList.getSelectedItem());              
            is = new DataInputStream (url.openStream());
            String c = is.readLine() ;
            int numcities = (new Integer(c)).intValue();
            int indx;

            attcoaList.setVisible(false);
            attcozList.setVisible(false);
            for(indx=0; indx < numcities; indx++) {
                c = is.readLine() ;
                attcoaList.addItem(c);
                attcozList.addItem(c);
            }
            attcoaList.select(0);
            attcozList.select(1);
            attcoaList.setVisible(true);
            attcozList.setVisible(true);
        } catch(Exception e) {
            System.out.println("Exception getting city list" + e);
        }

                try {
        :
        :


0
Comment
Question by:borghard
3 Comments
 
LVL 3

Accepted Solution

by:
falter earned 134 total points
Comment Utility
I think you are miss using the init() method.
There is a hint in Java in a Nutshell saying:
the applet isn't controling the execution thread it has to respond to the browser calls, so every method
start(), stop(), init(), destroy() have to return immediatley. Its not allowed to have a time consuming task or infinite loop in f.e. the init method.
If you wanna do such things you have to start your own thread.

I have als mentioned that Netscape is very tolerant to applets doing all the stuff in their init method, but they shouldn't do so.

If you didn't return from your init method you will block the event queue means your browser gets frozen.

Think of init in applets like a constructor and I don't think you will code your whole application stuff in a constructor.

0
 
LVL 1

Expert Comment

by:pran071199
Comment Utility
Try using the html converter  to generate the HTML page for applet. Html converter can be downloaded from

http://java.sun.com/products/plugin/1.2/features.html
0
 

Author Comment

by:borghard
Comment Utility
Thanks both for the info!
BB
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now