Thread: Applet Help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0

    Applet Help


    Hello Forum
    I have an applet that works partially and I need some help figuring out what I am doing wrong.
    What I have
    Standard Classes Nothing Special Uses Constructors>>
    file reader
    file writer
    average
    email
    factorial

    Class app_primary
    this is the applet class
    based on which button is clicked I grab an new object of the classes above and process stuff

    the factorial class works no problem as that is totally on the server

    the other 2 classes require that the user enter a file path , read in data, and then process the data

    this works properly when I run it locally, but after deployed theses last 2 dont work

    Any Ideas ???
    If this is not enough information please let me know?
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    need some help figuring out what I am doing wrong.
    Can you provide some specific information about your problem?
    If you are getting error messages, please copy the full text and paste it here.
    Look in the browser's java console for error messages.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0
    I am getting no error message at all
    I just click on the button and get nothing



    package myprog.single;


    import java.awt.Color;
    import java.awt.GridLayout;

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.util.InputMismatchException;

    import javax.swing.BorderFactory;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;


    /**
    * @brief Chapter 4 problem set contained in 1 applet
    * @author Nathan
    * @purpose Builds a wrapper around the problems we needed to finish for chpt 4
    * and lets the user see all of them in one place
    *
    */
    public class app_primary extends JApplet {


    private static final long serialVersionUID = 1L;

    JButton chpt4_1, chpt4_2, chpt4_3;
    JButton innerFact, innerAvg, innerEmail;
    JTextField txtFld, txtOut;
    JTextArea rslt;
    JPanel btns, applets;


    /**
    * Applet Entry Point
    * Calls 4 functions
    * 1> create new grid layout
    * 2> set up button panel
    * 3> set up Applet Panel container
    * 4> fill applet panel with first applet Factorial by default
    */
    public void init()
    {
    setLayout(grid(1,2,10,10));
    setBtnPanel();
    setAppletPanel();
    setFactPanel();
    }


    /**
    * @brief Acts as a wrapper to the Grid Layout Function as it is called multiple times
    * @param row
    * @param col
    * @param hgap
    * @param vgap
    * @return new GridLayout Manager with above parameters
    */
    private GridLayout grid(int row, int col, int hgap, int vgap)
    {
    return new GridLayout(row,col,hgap,vgap);
    }


    /**
    * @brief Setup the panel that will hold the applets when they are being used
    */
    private void setAppletPanel()
    {
    applets = new JPanel();
    applets.setBorder(BorderFactory.createLineBorder (Color.blue, 2));
    applets.setLayout(grid(0,1,0,0));
    }


    /**
    * @brief Setup the panel to hold the buttons to switch between applets
    * each button will be assigned an action listner
    */
    private void setBtnPanel()
    {
    chpt4_1 = new JButton("Factorial");
    chpt4_1.addActionListener(new eventListener());

    chpt4_2 = new JButton("Average");
    chpt4_2.addActionListener(new eventListener());

    chpt4_3 = new JButton("Email");
    chpt4_3.addActionListener(new eventListener());

    btns = new JPanel();
    btns.setLayout(grid(0,1,0,0));
    btns.add(chpt4_1);
    btns.add(chpt4_2);
    btns.add(chpt4_3);
    add(btns);
    }


    /**
    * @brief Setup the Applet 4.1
    * Calculate A Factorial Of A Number
    */
    private void setFactPanel()
    {
    JLabel fact = new JLabel("Enter A Number");
    fact.setHorizontalAlignment(JLabel.CENTER);
    applets.add(fact);

    txtFld = new JTextField(5);
    txtFld.setHorizontalAlignment(JTextField.CENTER);
    applets.add(txtFld);

    innerFact = new JButton("Click me");
    innerFact.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    rslt.setText(null);
    int usrInput = Integer.parseInt( txtFld.getText() );
    try
    {
    myprog.single.Factorial f = new myprog.single.Factorial(usrInput);
    rslt.append("The Factorial of " + usrInput + " is " + f.getResult());
    f = null;
    }
    catch(InputMismatchException ime)
    {
    System.out.println("Invalid Input -- Input Must Be A Non Negative Integer" + ime.getLocalizedMessage());
    rslt.append("Invalid Input: -- Input Must Be A Non Negative Integer\n" + ime.getLocalizedMessage());
    }
    }
    });
    applets.add(innerFact);

    rslt = new JTextArea(10,10);
    rslt.setEditable(false);
    applets.add(rslt);

    add(applets);

    }

    /**
    * @brief Setup Applet 4.2
    * Read a List of integers from a file
    * Calculate the average of the list
    * Return the average and the count of integers
    */
    private void setAvgPanel()
    {
    JLabel avg = new JLabel("Enter The Source File Path");
    avg.setHorizontalAlignment(JLabel.CENTER);
    applets.add(avg);

    txtFld = new JTextField(5);
    txtFld.setHorizontalAlignment(JTextField.CENTER);
    applets.add(txtFld);

    innerAvg = new JButton("Click me");
    //innerAvg.addActionListener(new classListener());
    innerAvg.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

    Average avg = null;
    try
    {
    rslt.setText(null);
    avg = new Average(new File_Reader(new File(txtFld.getText())).getList());
    rslt.append("File Name: " + txtFld.getText() + "\n" + avg.result());

    }
    catch(InputMismatchException ime2)
    {
    System.out.println("Input Mismatch Exception " + ime2.getMessage().toString());
    rslt.append("Input Mismatch Exception \n" + ime2.getMessage().toString());
    }
    catch(NumberFormatException nfe)
    {
    System.out.println("Number Format Exception BAD DATA " + nfe.getMessage().toString());
    rslt.append("Number Format Exception BAD DATA \n" + nfe.getMessage().toString());
    }
    catch (IOException ioe)
    {
    System.out.println("There Was A Problem Reading the File " + ioe.getMessage().toString());
    rslt.append("File Name: NOT FOUND \n" + ioe.getMessage().toString());
    }
    finally
    {
    avg = null;
    }
    }
    });



    applets.add(innerAvg);

    rslt = new JTextArea(10,10);
    rslt.setEditable(false);
    applets.add(rslt);

    add(applets);

    }

    /**
    * @brief Setup Applet 4.3
    * Read a list of student information from text file
    * parse out the pertinant information
    * put together a list of student email based on student info
    * write the list to a file
    */
    private void setEmailPanel()
    {
    JLabel in = new JLabel("Enter The Source File Path");
    in.setHorizontalAlignment(JLabel.CENTER);
    applets.add(in);

    txtFld = new JTextField(5);
    txtFld.setHorizontalAlignment(JTextField.CENTER);
    applets.add(txtFld);

    JLabel out = new JLabel("Enter The Destination File Path");
    out.setHorizontalAlignment(JLabel.CENTER);
    applets.add(out);

    txtOut = new JTextField(5);
    txtOut.setHorizontalAlignment(JTextField.CENTER);
    applets.add(txtOut);

    innerEmail = new JButton("Click me");
    innerEmail.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {

    try
    {
    rslt.setText(null);

    File_Reader fr = new File_Reader(new File(txtFld.getText()));
    new File_Writer(fr, new File(txtOut.getText()));
    rslt.append("File Source Name: " + txtFld.getText() + "\n");
    rslt.append("File Destination Name: " + txtOut.getText() + "\n");
    rslt.append("Converted Emails Written To File Successfully");
    }
    catch (FileNotFoundException fnfe)
    {
    System.out.println("File Not Found Error " + fnfe.getMessage().toString());
    rslt.append("File Not Found Error \n" + fnfe.getMessage().toString());
    }
    catch(IOException ioe_2)
    {
    System.out.println("File Output Error " + ioe_2.getMessage().toString());
    rslt.append("File Output Error \n" + ioe_2.getMessage().toString());
    }
    }
    });
    applets.add(innerEmail);

    rslt = new JTextArea(10,10);
    rslt.setEditable(false);
    applets.add(rslt);

    add(applets);

    }





    /**
    * @brief Inner Private Class that will switch between each applet
    * by using the click event of buttons
    * @author Nathan
    *
    */
    private class eventListener implements ActionListener
    {
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource() == chpt4_1)
    {
    applets.removeAll();
    setFactPanel();
    }
    else if (e.getSource() == chpt4_2)
    {
    applets.removeAll();
    setAvgPanel();
    }
    else if (e.getSource() == chpt4_3)
    {
    applets.removeAll();
    setEmailPanel();
    }
    applets.revalidate();
    applets.repaint();
    }
    }





    }
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Please edit your post and wrap the code in code tags to preserve the formatting.

    I just click on the button and get nothing
    Add some println statements to the code that print out messages as the code executes to see how far the code executes and determine why you get nothing. Where is the code stopping execution?

    What is printed in the browser's java console?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0
    None,
    I get nothing in the java console
    all errors are blank

    could this have something to do with the file reader trying to read off the server

    this program works locally??
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    I don't know where the code stops executing. You need to do some debugging with println statements.
    Where is the last println that prints out a message? How far does the code execute before nothing more happens? What statements are in front of a println that did NOT print? When some printlns print and some don't print, the problem must be between the last one to print and the first one that did not print.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    4
    Rep Power
    0
    Solved this problem

    I needed to sign the applet which required access to the local resources of the user

IMN logo majestic logo threadwatch logo seochat tools logo