Results 1 to 11 of 11
  1. #1
    fantasyme is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Default How can I change webpage by applet?

    Sorry, if my topic is weird.
    I try to make game by using applet.
    When game over, I want the applet call the new page/change the page.

    Like this :applet.html -> gameover.html.

    Do anybody know the code or tutorial?

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    Do you want it to go to another page or just change the link?

  3. #3
    fantasyme is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Default

    well, I want to change the current page to be the new page.
    I found that getAppletContext().showDocument may work.
    But it doesn't work.

    Can you see my code and tell me why it doesn't switch to the new page?
    Java Code:
    package dicegame;
     
     
    import java.awt.*;
    import java.net.MalformedURLException;
    import java.net.URL;
     
    import javax.swing.JApplet;
     
     
     
    import javax.swing.*;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
     
     
     
     
    public class game extends JApplet {
      
    	private JLabel appletScoreLabel;
    		
       public void init() {
          try {
        	 
             javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                   createGUI();
                }
             });
          }
          catch (Exception e) {
             System.err.println("createGUI didn't successfully complete");
          }
       }
     
       private void createGUI() {
    	   this.setSize(240, 300);
          final roll gamepanel = new roll();
      		
          appletScoreLabel = new JLabel(""+gamepanel.score, SwingConstants.CENTER);
        
          gamepanel.addChangeListener(new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                           
    int score = gamepanel.score;
                 
                           
                             appletScoreLabel.setText(String.valueOf(score));
                 gameover(score);
          
              }
              });
          
         
           
     
          JPanel statusPanel = new JPanel();
          statusPanel.add(new JLabel("Score (in the Applet):  "));
          statusPanel.add(appletScoreLabel);
          
          getContentPane().add(gamepanel, BorderLayout.CENTER);
          getContentPane().add(statusPanel, BorderLayout.SOUTH);
          
     	
          
       
     
     
       }
       public void gameover(int s){
    	   System.out.println(s);
    	   if(s<=0)
    	      {
    	    	  try {
    	    		  System.out.println("hello");
    				this.getAppletContext().showDocument
    				  (new URL(getCodeBase()+"test.php"),"_self");
    			} catch (MalformedURLException e1) {
    				  System.out.println("error");
    				e1.printStackTrace();
    			}
    	      }
       }

  4. #4
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    URL(getCodeBase()+"test.php"),"_
    Is the test.php is in applet folder?
    And tell us how do you start your applet?
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  5. #5
    fantasyme is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Default

    well, test.php is in thew same folder as applet.
    And I start applet by set in html.
    Java Code:
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    
    </br>
    
    
    <APPLET ARCHIVE="dice.jar" CODE="dicegame.game.class" WIDTH=240 HEIGHT=300>
    </APPLET>
    
    
    
    </BODY>
    </HTML>

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    How you start it? Is it a host or a local disk volume?

  7. #7
    fantasyme is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Default

    It is from the local disk(my computer) not the host server.

    I just realised that showdocument(); need exactly URL and I found error message is
    no protocol.

    After, I try "http://www.yahoo.com" it works.

    I think I use the wrong command.
    Is there any possibility to link to local disk?

  8. #8
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Lightbulb

    Quote Originally Posted by fantasyme View Post
    It is from the local disk(my computer) not the host server.

    I just realised that showdocument(); need exactly URL and I found error message is
    no protocol.

    After, I try "http://www.yahoo.com" it works.

    I think I use the wrong command.
    Is there any possibility to link to local disk?
    well as a rule code like a

    Java Code:
    getCodeBase()
    it's suppose to provide link which starts like "http://host/appletfolder/"
    but your link not like that because of local valume
    it is "file://blabla/appletfolder"
    moreover I must notice one simple rule which says
    Remember please...Unsigned applet cannot load web pages from non native host !!! :)
    So either locate the applet right to your host next to test.php file or just sign it .
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  9. #9
    fantasyme is offline Member
    Join Date
    Apr 2010
    Posts
    16
    Rep Power
    0

    Default

    thanks ! it is works now.
    Actually, I have already try on getbasecode() before but
    my browser doesn't update when I refreshed the page.
    So I got confused that I always get the same wrong result even though I made the right result.

    And as you request about rep.
    Thanks everyone.

  10. #10
    rochardgems is offline Member
    Join Date
    Apr 2010
    Posts
    4
    Rep Power
    0

    Default

    Its just simple Applet Below
    public class Transfer extends JApplet {
    public void init() {
    try {
    SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
    JLabel lbl = new JLabel();
    for(int i=0; i<10; i++){
    lbl.setText("Transferring...." + i);
    }
    add(lbl);
    }
    });
    } catch (Exception e) {
    System.err.println("createGUI didn't complete successfully");
    }
    }
    }

    How its fetch the web page,
    function loadNextPage( )
    {
    document.write("<APPLET name='Transfer' code='com.test.transfer.Transfer.class' archive='transfer.jar'>");
    document.writeln("<param name='archive' value='transfer.jar'>");
    document.writeln("<param name='code' value='com.test.transfer.Transfer.class'>");
    }
    <form>
    <input type="button" value="Proceed" size="10" onclick="loadNextPage()">
    </form>

  11. #11
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 02-18-2010, 04:24 PM
  2. Add a Swing UI in a WebPage
    By ivvgangadhar in forum AWT / Swing
    Replies: 9
    Last Post: 06-30-2009, 08:16 AM
  3. Replies: 4
    Last Post: 02-22-2009, 06:31 AM
  4. save a webpage.....?
    By 05bit044 in forum Networking
    Replies: 1
    Last Post: 08-04-2008, 04:49 PM
  5. print webpage through applet
    By shakti singh in forum Java Applets
    Replies: 1
    Last Post: 07-22-2008, 07:17 PM

Posting Permissions

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