Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-07-2012, 12:04 PM   PM User | #1
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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.
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 02:21 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 02:43 PM   PM User | #3
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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!
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 03:08 PM   PM User | #4
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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) 
{ 
}
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 03:12 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 03:18 PM   PM User | #6
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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) 
{ 
} 
	}
}
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 03:24 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 04:17 PM   PM User | #8
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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!
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 04:48 PM   PM User | #9
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point

please help! :/
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 05:17 PM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by TestingPHP View Post

please help! :/
Embed that in an attachment or indicate what the problem is.
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 05:32 PM   PM User | #11
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
Fixed the issue I changed the int to:
Code:
for (int i2 = 0; i2 < iBrowserWindows; ++i)
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 05:54 PM   PM User | #12
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
My favorite kind of answers !
Fou-Lu is offline   Reply With Quote
Old 06-07-2012, 06:20 PM   PM User | #13
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
alykins is offline   Reply With Quote
Old 06-07-2012, 06:41 PM   PM User | #14
TestingPHP
New Coder

 
Join Date: Jun 2012
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
TestingPHP is an unknown quantity at this point
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) 
{ 
} 
				}
			}
		}
}
TestingPHP is offline   Reply With Quote
Old 06-07-2012, 07:10 PM   PM User | #15
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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?
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:19 PM.


Advertisement
Log in to turn off these ads.