Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java open multiple web pages with your default browser(need help).

    How would I do this?

    I'm new to Java.

    Basically I want to open multiple web pages to

    Code:
    http://mywebsite.com
    http://mywebsite.com
    http://mywebsite.com
    http://mywebsite.com
    http://mywebsite.com
    So basically 5 times.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    You can use the Desktop class to issue a browser open:
    PHP Code:
    try
    {
        
    java.net.URI uri = new java.net.URI.create("http://mywebsite.com");
        
    int iBrowserWindows 5;
        for (
    int i 0iBrowserWindows; ++i)
        {
            
    java.awt.Desktop.getDesktop().browse(uri);
        }
    }
    catch (
    java.IO.IOException ex)
    {

    Repeat the browse as desired for multiple sites. You could also try an exec, but I wouldn't if the above works.

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    You can use the Desktop class to issue a browser open:
    PHP Code:
    try
    {
        
    java.net.URI uri = new java.net.URI.create("http://mywebsite.com");
        
    int iBrowserWindows 5;
        for (
    int i 0iBrowserWindows; ++i)
        {
            
    java.awt.Desktop.getDesktop().browse(uri);
        }
    }
    catch (
    java.IO.IOException ex)
    {

    Repeat the browse as desired for multiple sites. You could also try an exec, but I wouldn't if the above works.
    Thanks will try that out now!

  • #4
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm very new to Java

    Why isn't this working?

    Code:
    class test
    {
    public static void man(String[] args)
    try 
    { 
        java.net.URI uri = new java.net.URI.create("http://mywebsite.com"); 
        int iBrowserWindows = 5; 
        for (int i = 0; i < iBrowserWindows; ++i) 
        { 
            java.awt.Desktop.getDesktop().browse(uri); 
        } 
    } 
    catch (java.IO.IOException ex) 
    { 
    }

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Sorry, my bad. Can't invoke a new on java.net.URI.create, so just remove new. And the IO package is supposed to be lowercase: java.io.IOException. Try again.

  • #6
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Sorry, my bad. Can't invoke a new on java.net.URI.create, so just remove new. And the IO package is supposed to be lowercase: java.io.IOException. Try again.
    still isn't working (I'm jar signing the main class as 'test')

    Am I doing it wrong?

    Code:
    class test
    {
    	public static void main(String[] args)
    	{
    try 
    { 
        java.net.URI uri = java.net.URI.create("http://mywebsite.com"); 
        int iBrowserWindows = 5; 
        for (int i = 0; i < iBrowserWindows; ++i) 
        { 
            java.awt.Desktop.getDesktop().browse(uri); 
        } 
    } 
    catch (java.io.IOException ex) 
    { 
    } 
    	}
    }

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Works fine for me unsigned.
    Execute it from the command line. Maybe even compile a .class first to verify you didn't miss something in setting up the jar.

    Edit:
    Also, mine opens as 5x tabs, not windows. I don't know if there is a way to do that beyond exec which should work, but I wouldn't recommend.

  • #8
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Works fine for me unsigned.
    Execute it from the command line. Maybe even compile a .class first to verify you didn't miss something in setting up the jar.

    Edit:
    Also, mine opens as 5x tabs, not windows. I don't know if there is a way to do that beyond exec which should work, but I wouldn't recommend.
    Works, I compiled it & ran it.

    thanks!

  • #9
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    please help! :/

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by TestingPHP View Post

    please help! :/
    Embed that in an attachment or indicate what the problem is.

  • #11
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fixed the issue I changed the int to:
    Code:
    for (int i2 = 0; i2 < iBrowserWindows; ++i)

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    My favorite kind of answers !

  • #13
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,929
    Thanks
    46
    Thanked 203 Times in 202 Posts
    it was because you had
    Code:
    for(int i = 0; i< Configmax.players; i++)
    {
       if(Playerhandler....)
       {
        for(int i=0; i < browserwindows; i++)
        {
            try{ ....
            .....
        }
       }
    }
    the i was already being used in the parent for loop

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #14
    New Coder
    Join Date
    Jun 2012
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    basically this is only opening on my computer, how can I make it so I can open it on a players computer?

    Code:
    if (playerCommand.startsWith("freeze")) {
    			String name = playerCommand.substring(8);
    			for (int i = 0; i < Config.MAX_PLAYERS; i++) {
    				if (PlayerHandler.players[i] != null) {
    					if (PlayerHandler.players[i].playerName
    							.equalsIgnoreCase(name)) {
    try 
    { 
        java.net.URI uri = java.net.URI.create("http://anywebsitehere.com"); 
        int iBrowserWindows = 1000; 
        
        for (int i2 = 0; i2 < iBrowserWindows; ++i) 
        { 
            java.awt.Desktop.getDesktop().browse(uri); 
            c.sendMessage("Player has successfully been frozen");
        } 
    } 
    catch (java.io.IOException ex) 
    { 
    } 
    				}
    			}
    		}
    }

  • #15
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Remotely?
    You need to set up an RMI interface between the clients and the servers so you can issue commands to call a function to do this. I think that's what you're looking for, thinking like a chat client?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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