2

Applet used to work, but now it will not. I am not very experienced with GUI's much less Applets. Here is the GUI code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;

public class StockGUI extends JApplet implements ActionListener
{
private final String sPASS = "abc123";
//Stock oStock = new Stock();
//StockInput oStockInput = new StockInput();

//////////////////////////////////////////////////////////

JPanel jPanel;
JPasswordField jPass;
JButton jBEnter, jBYes, jBNo;
JTextArea jTAInput, jTACurrent;
JTextField jTxtField;
JLabel jLEnterP, jLQue, jLCurrent;
JScrollPane jScroll;




public void init()
{
    getContentPane().setLayout(null);
    jPanel = new JPanel();  jPanel.setSize(500,1500);

    ////////////////////////////////////////////////

    jPass = new JPasswordField(20);
    jPass.setActionCommand(sPASS);
    jLEnterP = new JLabel("Enter Password:");
    jPanel.add(jLEnterP);
    jPanel.add(jPass);

    jPass.addActionListener(new ActionListener()
    {
        public void actionPerformed(ActionEvent e)
        {
            String cmd = e.getActionCommand();
            if(cmd.equals(sPASS))
            {
                char[] cAry = jPass.getPassword();
                if(isPassword(cAry))
                {
                    doPass();
                }
            }
        }
    });

    getContentPane().add(jPanel, BorderLayout.CENTER);

}

public void actionPerformed(ActionEvent e)
{
    String cmd = e.getActionCommand();


    if(cmd.equals("Yes"))
    {

        doInput();

    }
    if(cmd.equals("No") || cmd.equals("Done"))
    {
        doMain();
    }

}

public void doPass()
{
        jPanel.removeAll();
        jLQue = new JLabel("Do you need to input more data?");
        jBYes = new JButton("Yes");

        jBYes.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                doInput();
            }
        });

        jBNo = new JButton("No");

        jBNo.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                doMain();
            }
        });

        jPanel.add(jLQue);
        jPanel.add(jBYes);
        jPanel.add(jBNo);
        refresh();

}

public void doInput()
{
    jPanel.removeAll();
    jLQue = new JLabel("Enter Data:");
    jTAInput = new JTextArea(25,50);
    jLCurrent = new JLabel("Current Data");
    jTACurrent = new JTextArea(25, 25);
        jTACurrent.setEditable(false);
        //jTACurrent.setText(oStockInput.getList());
    jScroll = new JScrollPane(jTACurrent);
    jPanel.add(jLQue);
    jPanel.add(jTAInput);
    refresh();
}

public void doMain()
{

    jPanel.removeAll();
    jPanel.add(new JLabel("HELLO WORKD!!"));
    refresh();

}

public void refresh()
{
    jPanel.repaint();
    jPanel.revalidate();
    super.validate();
    super.repaint();
}

public boolean isPassword(char[] cAry)
{

    return Arrays.equals(cAry, sPASS.toCharArray());

}

The HTML Code:

//  <html>
//<body>
//<p align=center>
//<applet code="StockGUI.class" width=500 height=1500>
//  </applet>
//</p>
//</body>
//</html>

I get no errors on compile. I am trying to use Anonymous Classes for the ActionListeners, but this is the first time I have used them. When I launch it Chrome, all it shows is a white background. Any help would be good. Thanks.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
01somebody
  • 45
  • 5
  • 2) yes it showed the one you pointed to me 1) what layout should i use? – 01somebody Feb 11 '12 at 05:35
  • I took out the setLayout(null) and it still Shows nothing – 01somebody Feb 11 '12 at 05:38
  • I set the layout to BorderLayout. Still Nothing... – 01somebody Feb 11 '12 at 05:45
  • // //

    // // //

    //
    – 01somebody Feb 11 '12 at 05:47
  • and there is not a URL, sorry. and i dont know how to get to the java console – 01somebody Feb 11 '12 at 05:48
  • Please edit the HTML back into the question. Note that it is invalid due to a lack of `` elements. As to seeing the console, open the [Java Control Panel](http://pscode.org/player.jnlp) and configure it in the last tab). – Andrew Thompson Feb 11 '12 at 06:03
  • I edited the question and set the setting to show console. but i still don't know what im doing... – 01somebody Feb 11 '12 at 06:11
  • scratch that, this is what it shows: – 01somebody Feb 11 '12 at 06:11
  • Exception in thread "thread applet-StockGUI.class-1" java.lang.NoClassDefFoundError: StockGUI$1 at StockGUI.init(StockGUI.java:40) at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.ClassNotFoundException: StockGUI$1 at sun.plugin2.applet.Applet2ClassLoader.findClass – 01somebody Feb 11 '12 at 06:12
  • (Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more – 01somebody Feb 11 '12 at 06:13
  • Ok, i had other classes in the program, sorry i didn't show, but i wanted to keep the code private. I added their .class files and now it works. Thank you very much for your help! – 01somebody Feb 11 '12 at 06:17

2 Answers2

4

I usually debug applets by using appletviewer. Add the following line to the top of your program and recompile:

//<applet code="StockGUI.class" width="500" height="300"></applet>

Then you can test the applet from the command line using:

appletviewer StockGUI.java

You can add debug statements to see what is happening. I see a prompt for the password when I do this.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • Well I just decided to reinstall the JDK since I was having trouble with it. I'll be sure to do that as soon as it finishes. Thank you. – 01somebody Feb 11 '12 at 05:26
  • Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\UserName>appletviewer StockGUI.java 'appletviewer' is not recognized as an internal or external command, operable program or batch file. C:\Users\UserName> – 01somebody Feb 11 '12 at 05:28
  • You need to set the "path" variable to point to the "bin" directory of your JDK. This is where the "java" and "javac" executables are also found. – camickr Feb 11 '12 at 05:39
  • i got this: Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\UserName>path C:\Program Files\Java\jdk1.6.0_30\bin C:\Users\UserName>appletviewer StockGUI.java I/O exception while reading: C:\Users\Ryan Fabela\StockGUI.java (The system cann ot find the file specified) C:\Users\UserName> – 01somebody Feb 11 '12 at 05:44
2

Check the Java Console. It is likely to provide the cause of the failure.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433