Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Simple applet problem

  • 10-01-2005 08:53PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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