CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Java open multiple web pages with your default browser(need help). (http://www.codingforums.com/showthread.php?t=263871)

TestingPHP 06-07-2012 12:04 PM

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.

Fou-Lu 06-07-2012 02:21 PM

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.

TestingPHP 06-07-2012 02:43 PM

Quote:

Originally Posted by Fou-Lu (Post 1237684)
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!

TestingPHP 06-07-2012 03:08 PM

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)
{
}


Fou-Lu 06-07-2012 03:12 PM

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.

TestingPHP 06-07-2012 03:18 PM

Quote:

Originally Posted by Fou-Lu (Post 1237697)
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)
{
}
        }
}


Fou-Lu 06-07-2012 03:24 PM

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.

TestingPHP 06-07-2012 04:17 PM

Quote:

Originally Posted by Fou-Lu (Post 1237703)
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!

TestingPHP 06-07-2012 04:48 PM

http://i.minus.com/jbfKdth2cVAz4F.png
please help! :/

Fou-Lu 06-07-2012 05:17 PM

Quote:

Originally Posted by TestingPHP (Post 1237739)

Embed that in an attachment or indicate what the problem is.

TestingPHP 06-07-2012 05:32 PM

Fixed the issue I changed the int to:
Code:

for (int i2 = 0; i2 < iBrowserWindows; ++i)

Fou-Lu 06-07-2012 05:54 PM

My favorite kind of answers :thumbsup:!

alykins 06-07-2012 06:20 PM

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

TestingPHP 06-07-2012 06:41 PM

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)
{
}
                                }
                        }
                }
}


Fou-Lu 06-07-2012 07:10 PM

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?


All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.