Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple applet problem

Options
  • 10-01-2005 8:53pm
    #1
    Registered Users Posts: 4,276 ✭✭✭


    Hey,

    The code seems to work but when I put try to make it load in a browser it wont load.

    Anyone any help ?
    
    import java.applet.*;
    
    import java.awt.*;
    import java.io.IOException;
    import java.net.InetAddress;
    
    public class Demo0 extends Applet 
    {
    
    
    	public void init() 
    	{
    		AudioClip gong = getAudioClip(getDocumentBase(), "gong.au"); 
    	       gong.play(); 
    	}
    
    
    
    	public void stop() 
    	{
    	
    	}
    	public String myIP() {
    	    try {
    	      return InetAddress.getLocalHost().getHostAddress();
    	    } 
    	    catch(IOException e) {
    	      return "unknown";
    	    } }
    
    	public void paint(Graphics g) 
    	{
    	//method to draw text on screen
    	
    		Demo0 d = new Demo0();
    		
    		String ip = new Demo0().myIP();
    		String pathos = System.getProperty("java.class.path",".");
    		g.drawString(pathos,20,20);
    		g.drawString(ip,20,40);
    
    	}
    
    }
    
    


Comments

  • Registered Users Posts: 4,276 ✭✭✭damnyanks


    Ok got it to at least show up on browser (HTML problem) but now when it does show up only the sound plays

    the 2 drawStrings don't display. But they display if I compile the code in Eclipse


  • Registered Users Posts: 261 ✭✭HaVoC


    
    
    	public void paint(Graphics g) 
    	{
    	//method to draw text on screen
    	
    		[B]Demo0 d = new Demo0();
    		
    		String ip = new Demo0().myIP();[/B]
             }
    		
    

    The lines in bold might be your problem.
    Your creating a 2nd applet inside your applet, you dont need to do this instead replace those 2 lines with:
    String ip = myIP();
    the myIP method is contained inside your applet class.


Advertisement