Results 1 to 7 of 7
  1. #1

    Default Whats wrong with my AppletContext.showdocument?


    ive been having a hard time figuring out my problem and i think its time to let this problem out to the world. im trying to call a certain html file to be shown on a certain frame of another html file, after a Java-made button is clicked.

    to clear things out, here's the code:

    Code:
    import java.applet.*;
    import java.net.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.AbstractButton;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    
    public class TestHomeButton extends Applet implements ActionListener {
    
    
    JButton homeButton;
    JPanel panel; 
    AppletContextAdapter fetchURL = new AppletContextAdapter(); 
    
    public void init( ) {
    setLayout(new BorderLayout( ));
    setBackground(Color.white);
    
    homeButton = new JButton("Home");
    homeButton.setVerticalTextPosition(AbstractButton.CENTER);
    homeButton.setHorizontalTextPosition(AbstractButton.CENTER);
    homeButton.setToolTipText("History & Introduction");
    homeButton.setActionCommand("home");
    homeButton.addActionListener(this);
    add("Center", homeButton);
    }
    
    
    public void start( ) {
    System.out.print("Applet starting.");
    }
    
    
    public void stop( ) {
    System.out.print("Applet stopping.");
    }
    
    
    public void destroy( ) {
    System.out.print("Destroy method called.");
    }
    
    
    public void actionPerformed(ActionEvent e) {
    try
    {
    // URL myUrl = new URL("simple.htm");
    if ("home".equals(e.getActionCommand( ))) 
    fetchURL.showDocument(new URL("simple.htm"),"ButtonResults");
    AppletContext.showDocument(new URL("simple.htm"),"ButtonResults");
    
    }
    catch(Exception exept)
    {
    }
    }

    the code above is good for one button only. i have made a dozen of these but im just testing one button for now to get the solution right.. the other would be later...

    here's the (main) html file...
    Code:
    <html>
    <head> <title> SKI group </title> </head>
    <body background="bg_fade.gif">
    
    <center><table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    
    <tr>
    <td colspan=11><br></td>
    </tr>
    
    <tr>
    <td colspan=11><br></td>
    </tr>
    
    <tr>
    <td width=25><br></td>
    <td width=50 align="center"><img src="house.jpg" width=60 height=50 ></td>
    <td width=25><br></td> 
    <td width=50 align="center"><img src="puzzle.jpg" width=60 height=50 ></td>
    <td width=25><br></td> 
    <td width=50 align="center"><img src="gears01.jpg" width=60 height=50 ></td>
    <td width=25><br></td>
    <td width=50 align="center"><img src="maze.jpg" width=60 height=50 ></td>
    <td width=25><br></td>
    <td width=50 align="center"><img src="peoplemove.jpg" width=60 height=50 ></td>
    <td width=25><br></td>
    </tr>
    
    <tr>
    <td width=25><br></td>
    <td width=50 align=center><applet code="TestHomeButton.class" width=120 height=40> </applet></td>
    <td width=25><br></td> 
    <td width=50 align=center><applet code="TestVariablesButton.class" width=120 height=40></applet></td>
    <td width=25><br></td>
    <td width=50 align=center><applet code="TestOperatorsButton.class" width=120 height=40></applet></td>
    <td width=25><br></td>
    <td width=50 align=center><applet code="TestFunctionsButton.class" width=120 height=40></applet></td>
    <td width=25><br></td>
    <td width=50 align=center><applet code="TestCrewButton.class" width=120 height=40></applet></td> 
    <td width=25><br></td>
    </tr> 
    
    <tr>
    <td colspan=11><br></td>
    </tr>
    
    <tr>
    <td colspan=12>
    <iframe name="ButtonResults" src="welcome.htm" 
    width="700" height="500" 
    scroll="0" frameborder="0">
    </iframe>
    </td>
    </tr>
    
    </table></center>
    
    </body>
    </html>



    so, once homeButton is clicked it calls on another html file to be shown inside the iframe... unfortunately, it just didnt work

    i am hoping you guys here could help me out and enlighten me...

    thanks, in advance

  2. #2

    Default Re: Whats wrong with my AppletContext.showdocument?

    I believe there are many solutions to this problem, if you ask me to program, I would rather use JEditorPane, you can find a sample code along with the Java installer, in linux it is in /usr/java/jdk1.5.0_06/demo/jfc/SwingSet2/ depending on what version you have. In Windows, it is under Program Files then Java ...

  3. #3

    Default Re: Whats wrong with my AppletContext.showdocument?

    i did solve my problem...

    Code:
    public void actionPerformed(ActionEvent e) {
       try {
         if ("home".equals(e.getActionCommand( ))) 
         getAppletContext( ).showDocument(new URL("simple.htm"),"ButtonResults");
       }
       catch(Exception exept) { }
    }
    but the page i requested everytime i clicked on any button wouldnt be loaded on the specified frame. anyone would care to help?


  4. #4

    Default Re: Whats wrong with my AppletContext.showdocument?

    Code:
    public void actionPerformed(ActionEvent e) {
       try {
         if ("home".equals(e.getActionCommand( ))) 
         getAppletContext( ).showDocument(new URL("simple.htm"),"ButtonResults");
       }
       catch(Exception exept) { }
    }
    getAppletContext( ).showDocument(new URL("simple.htm"),"ButtonResults");

    Na try na nimo og absolute ang path? Ex. C:\simple.htm nya wala gihapon og work?
    Sa path man gud nasangit usahay ang mga programmers.

  5. #5

    Default Re: Whats wrong with my AppletContext.showdocument?

    will try inserting the whole path...

    but it shouldnt be of a problem since the classes and the HTML files are on the same directory unless i put it somewhere else.

  6. #6

    Default Re: Whats wrong with my AppletContext.showdocument?

    mura madala manang imong gi buhat without using Java...

  7. #7

    Default Re: Whats wrong with my AppletContext.showdocument?

    Code:
    public void actionPerformed(ActionEvent e) {
       try {
         if ("home".equals(e.getActionCommand( ))) 
         getAppletContext( ).showDocument(new URL("simple.htm"),"ButtonResults");
       }
       catch(Exception exept) { }
    }
    ni work ba sa pag-try nimo og absolute path? Pls. reply...

    if yes try this...

    insert this one --> System.getProperty("user.dir"); // this code returns a string which is the current directory.

    example:

    getAppletContext( ).showDocument(new URL(System.getProperty("user.dir") + "\simple.htm"),"ButtonResults");

    gamit ni nako permi. :mrgreen:

    example:

    C:\MyProgram
    |--------->Sample.jar
    |--------->record.xml

    Since

    System.getProperty("user.dir"); // the parameter "user.dir" returns "C:\MyProgram" string

    I often use this code

    Code:
    props.loadFromXML(new FileInputStream(System.getProperty("user.dir")+"/record.xml"));
    Hope it works bro. Goodluck :mrgreen:

  8.    Advertisement

Similar Threads

 
  1. whats wrong with my fon
    By zmoktyok in forum Gizmos & Gadgets (Old)
    Replies: 5
    Last Post: 09-24-2007, 04:42 PM
  2. WHATS WRONG WITH MY PC- upgrading the rig and its downside
    By benchkicker in forum Computer Hardware
    Replies: 74
    Last Post: 09-09-2007, 12:47 AM
  3. whats wrong with my photoshop?
    By estor_boot in forum Software & Games (Old)
    Replies: 10
    Last Post: 07-25-2007, 02:46 PM
  4. Whats wrong with my CD-rom?
    By pobre in forum Computer Hardware
    Replies: 8
    Last Post: 11-30-2005, 07:47 PM
  5. whats wrong with my monitor?
    By jonmlas in forum Computer Hardware
    Replies: 8
    Last Post: 10-22-2005, 02:43 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
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top