Page 1 of 1

Java enabled PHP problem

Posted: Mon Oct 06, 2003 1:33 am
by thomas777neo
When I run this script it keeps on asking me to save the file.

What it should do is actually create a visual gui. Is it possible to draw gui's through PHP using JAVA.

Here is the code:

Code: Select all

$frame  = new Java('java.awt.Frame', 'PHP');
  $button = new Java('java.awt.Button', 'Hello Java World!');

  $frame->add('North', $button);
  $frame->validate();
  $frame->pack();
  $frame->visible = True;

  $thread = new Java('java.lang.Thread');
  $thread->sleep(10000);

  $frame->dispose();

Posted: Mon Oct 06, 2003 4:09 am
by volka
the php script runs server-side.
Do you want the window to be shown at the server?

Posted: Mon Oct 06, 2003 4:56 am
by thomas777neo
I actually wanted to have the gui appear on the client-side.

At the moment i am testing this code on my local machine.I have configured everything correctly and i have tested my java via php.

Posted: Mon Oct 06, 2003 6:16 am
by volka
then you can't do it with php. The java-frame would be instantiated by the server process. Open the source view of your browser; what you see there is what the client does. It does not see the php code (if the server is configured to run php-scripts).
If you want something done client-side, the client has to run the code.

Posted: Mon Oct 06, 2003 8:10 am
by thomas777neo
thanks, I see that non-gui components seem to work
php via java
. Yet the gui component as you said needs to run on the clients side. So, would it work on my local machine, if so why does it prompt me to download the script that contains the code.

I think if I can get it to run on my local machine then I can sort out a plan to have it run on the clients machine via the server.

Thanks, so is it still possible to instantiate the code on my machine and actually view the gui without it prompting me to save it.

I understand the complications running the code via a server to client, thanks once again.

Posted: Mon Oct 06, 2003 10:24 am
by volka
ok, step by step ;-)
does

Code: Select all

<?php phpinfo(); ?>
work and output infos about your php-installation?

Posted: Mon Oct 06, 2003 10:42 am
by Cruzado_Mainfrm
ok maybe if you use the <object></object> tags and embed the php file that has the java applet it may show the applet, give it a try

Status

Posted: Tue Oct 07, 2003 2:24 am
by thomas777neo
I have tried that <? phpinfo(); ?> function and it does output the credits for php.

I have also tried that <object></object> tag, it doesn't seem to work.

But, here is the test output for my PHP Java configuration
Java version=1.4.1_01
Java vendor=Sun Microsystems Inc.
OS=Windows XP 5.1 on x86
Tuesday, October 07, 2003 at 9:17:10 AM GMT+02:00
Fatal error: No usable fonts found.
And here is the code for the output:

Code: Select all

<?
  $system = new Java("java.lang.System");
  print "Java version=".$system->getProperty("java.version")." <br>\n";
  print "Java vendor=".$system->getProperty("java.vendor")." <p>\n\n";
  print "OS=".$system->getProperty("os.name")." ".
              $system->getProperty("os.version")." on ".
              $system->getProperty("os.arch")." <br>\n";

  $formatter = new Java("java.text.SimpleDateFormat","EEEE, 
	MMMM dd, yyyy 'at' h:mm:ss a zzzz");
  print $formatter->format(new Java("java.util.Date"))."\n";
  echo "<br>";

  //echo "<object>";	
  $frame  = new Java('java.awt.Frame', 'PHP');
  $button = new Java('java.awt.Button', 'Hello Java World!');

  $frame->add('North', $button);
  $frame->validate();
  $frame->pack();
  $frame->visible = True;

  $thread = new Java('java.lang.Thread');
  $thread->sleep(10000);

  $frame->dispose();
  //echo "</object>";
?>
So, now it doesn't ask me to download the page anymore yet it gives me an error.

The gui doesn't want to instantiate on my local machine.

Thanks so far... 8)

Posted: Tue Oct 07, 2003 3:24 am
by volka
ok, first the short, straight answer: You won't achieve what you want with this approach.
The purpose of echo is to add something to the output stream. If you're running php as console-application the output stream is the console (it will be printed there).
If php is running as a module/cgi for a webserver the output stream (maybe with some redirections) is what the client -waiting for the response document- receives. The script

Code: Select all

<?php
echo '<html>';
echo '	<head>';
echo '		<title>test</title>';
echo '	</head>';
echo '	<body>';
echo '		nothing important';
echo '	</body>';
echo '</html>';
?>
and the plain html-file

Code: Select all

&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;test&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		nothing important
	&lt;/body&gt;
&lt;/html&gt;
will produce the same output and the client will (probably) parse and display it as html. They are indistinguishable for the client. Only the output matters (ok, there's also the response-header, but that's negligible for now).
That's what I meant with
Open the source view of your browser; what you see there is what the client does.
. Just try it, it will be the same for both files.

Creating a java-frame adds nothing to the output stream. The window (if it could be instantiated/made visible) is bound to the systems that called the function/method/constructor. And in your case that's the server.
The reason it does not show up when server and client are the same machine is probably that the webserver's process is not attached to the gui or not allowed to interact with it.
(only out of curiosity: which webserver/os do you use?)

Posted: Tue Oct 07, 2003 8:27 am
by thomas777neo
I am running windows Xp build 2600 with the standard IIS that comes with it. I do have apache on my machine but i haven't configured with PHP as yet.

My IIS is on port 80, and I run apache on port 8080 in console mode. Due to IIS been my primary webserver. I had trouble having them both run as services.

Anyway, so it looks like the GUI idea won't work.

It's strange how my script can output certain java stuff but not visual gui's.

Thanks for all your trouble, if you find anything let me know.

Posted: Tue Oct 07, 2003 9:01 am
by volka
It's strange how my script can output certain java stuff but not visual gui's.

Code: Select all

print "Java version=".$system->getProperty("java.version")." <br>\n";
Java returns a string and php prints it (/adds it to the output stream). Same as

Code: Select all

$javastring $system->getProperty("java.version");
print "Java version=". $javastring ." <br>\n";
What you're looking for is a completely different protocol, http can't handle graphical interactions. Would be something more like the x protocol.
What about writing an applet?

Posted: Tue Oct 07, 2003 11:43 pm
by thomas777neo
That sounds good...

Thanks Volka