Results 1 to 3 of 3
  1. #1
    chaucer345 is offline Member
    Join Date
    Dec 2012
    Posts
    44
    Rep Power
    0

    Default Trying to get an applet with multiple class files to run in a web page

    Hello All,

    So I've been trying to develop a text adventure and I've got it to the point where I've got it running fine in eclipse's applet viewer, but I can't quite seem to get it to run in a web page. I've put all the class files into a jar file:
    in the same directory on my web page with an html document that calls the applet at:

    http://firstprinceproductions.helioh...g/Wounded.html

    Java Code:
    <HTML>
    <BODY>
    <applet code='woundedTestPackage.MainProgram',
    archive = 'Wounded.jar',
    height='1000',
     width='1000'>
    </applet>
    </BODY>
    </HTML>
    The code runs fine now, after some minor edits, but I'm worried about the fact that when I access the applet, my browser informs me that the applet has security vulnerabilities. Is there anything I can do to make my applet more secure?
    Any assistance would be appreciated.

    The code for the main class of the applet is located below:
    Java Code:
    package woundedTestPackage;
    /**
     * Program creates a GUI that then adds to a String variable story and displays
     * the string in a TextArea output. It receives input from the user into the 
     * JTextArea userInput and then passes that input off for error checking by
     * author, an instance of the StoryTeller class. It also passes the memory 
     * address of an instance of the Story class called theStory to author so that 
     * author can display the text in the  various methods there based on the user's 
     * input.
     * ------------------------------------------------------
     * Programmer: 
     * Program: Wounded
     * Last modified: April 2, 2013 2:39 PM Central Time
     * ------------------------------------------------------ 
     */
    
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JTextArea;
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JScrollPane;
    import java.awt.Font;
    import javax.swing.JLabel;
    
    
    public class MainProgram extends JApplet implements ActionListener
    {
    //Declare all the necessary variables and initialize as needed.
    private JTextArea userInput;
    private JTextArea output;
    private JScrollPane scrollPane;
    private boolean canProceed;
    static final long serialVersionUID = 1; // added in an attempt to fix an error, highly confused as to what it does.
    public String story = "My Little Pony: Friendship is Magic is the property of\n" +
    		"Hasbro, Lauren Faust, and the rest of its creative team. \n" +
    		"Please support the official release. \n\n" +
    		"Your eyes are bleary... you feel drained, so very " +
    		"drained... and dizzy. \nYou tilt your head over to " +
    		"the side of the rickety cot you're lying on and \n" +
    		"manage to throw up. To your surprise, there's a " +
    		"basin waiting for you.\n" +
    		"\"Hey there,\" comes a voice.\n" +
    		"You see an Earth Pony mare in an orange vest sitting at your bedside.\n" +
    		"She gives you a half hearted smile. \"Welcome to the land of the living.\" \n" +
    		"\"Can you tell me your name?\" She asks. \n" +
    		"1)Heavy Hooves\n" +
    		"2)Careful Crafts\n" +
    		"3)Free Faller\n" +
    		"4)Lie about name\n\n";
    public String input;
    StoryTeller author = new StoryTeller(0, 0, 0, 0, 0, 0);
    Story theStory = new Story();
    
    public void init()
    {
    	//Add the necessary content pane and set the layout.
    	Container contentPane = getContentPane();
    	contentPane.setLayout(new FlowLayout());
    	
    	
    	//Create Wounded Label
    	JLabel title = new JLabel();
    	title.setText("WOUNDED");
    	title.setFont(new Font("Courier", Font.PLAIN, 28));
    	contentPane.add(title);
    	
    	//Create the JTextArea for user input.
    	userInput = new JTextArea(1, 20);
    	userInput.setText("Enter your choice here");
    	contentPane.add(userInput);
    	
    	//Create the essential choose button to signal that
    	//the program should retrieve user input from userInput.
    	JButton chooseButton = new JButton();
    	chooseButton.setText("Choose");
    	chooseButton.addActionListener(this);
    	contentPane.add(chooseButton);
    	
    	//Create the JTextArea for the display of story.
    	output = new JTextArea(20, 100);
    	scrollPane = new JScrollPane(output);
    	output.setFont(new Font("Courier", Font.PLAIN, 16));
    	output.setText(story);
    	contentPane.add(scrollPane);	
    }
    
    /*Method that realizes when chooseButton has been pressed 
     * and then stores the string entered into userInput
     * in input. Then it checks if it can proceed with that
     * input by calling the author.readInput method which
     * also returns a boolean which is stored in canProceed.
     * If canProceed is true, the program invokes the 
     * author.continueStory method which returns the new story 
     * (among other things discussed in the documentation 
     * for StoryTeller). If canProceed is false, then 
     * an error message is added to story. In either case
     * the text of output is set to story.
    */
    public void actionPerformed(ActionEvent e)
    {
    	String	actionCommand = e.getActionCommand();
    	if (actionCommand.equals("Choose"))
    	{
    		input = userInput.getText();
    		canProceed = author.readInput(input);
    		if (canProceed)
    		{
    		story = author.continueStory(story, theStory);
    		output.setText(story);
    		}
    		else
    		{
    			story = story + "\n Not a valid choice, choose again:\n";
    			output.setText(story);
    		}
    	}
    }
    
    public static void main(String[] args)
    {
    	
    }
    
    }
    Last edited by chaucer345; 04-02-2013 at 11:50 PM. Reason: problem fixed

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Trying to get an applet with multiple class files to run in a web page

    Moved from New to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Trying to get an applet with multiple class files to run in a web page

    Any applet downloaded to a browser, if it isn't signed with a valid certificate, will generate that warning.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. source code in multiple .class files
    By vastrolorde in forum New To Java
    Replies: 23
    Last Post: 01-04-2013, 05:49 PM
  2. Replies: 2
    Last Post: 06-11-2011, 02:54 PM
  3. Multiple Language in my web page
    By Albert in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 09-21-2009, 02:46 PM
  4. Multiple class applet
    By lordbob75 in forum Java Applets
    Replies: 5
    Last Post: 01-08-2009, 02:22 AM
  5. multiple class files
    By nemesys571 in forum Eclipse
    Replies: 0
    Last Post: 06-26-2008, 02:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •