Make any java applet on the web fullscreen (in browser)

Alec Jacobson

August 12, 2009

weblog/

Sometimes on the web I find great java applets that I'd enjoy more if they were bigger. I wrote a little php script to generate a fullscreen java applet wrapper on the fly for any given applet. You just need to find the applet's code and codebase parameters from the original page's html source. Here's the bulk of the php source:
<?php
  $applet = "";
  $code = "";
  if (isset($_GET['code'])&&strlen($_GET['code'])>0)
    $code = $_GET['code'];
  # remove surrounding quotes if given any
  $code = preg_replace("/[\"\']$/","",$code);
  $code = preg_replace("/^[\"\']/","",$code);
  # remove trailing .class just in case it's included
  $code = preg_replace("/\.class$/","",$code);
  $codebase = "";
  if (isset($_GET['codebase'])&&strlen($_GET['codebase'])>0)
    $codebase = $_GET['codebase'];
  # remove surrounding quotes if given any
  $codebase = preg_replace("/[\"\']$/","",$codebase);
  $codebase = preg_replace("/^[\"\']/","",$codebase);
  $path= "";
  if (isset($_GET['path'])&&strlen($_GET['path'])>0)
    $path = $_GET['path'];
  if(empty($code)&&empty($codebase)&&!empty($path)){
    # stip out basename to get just the code's name
    $code = `basename $path`;
    $code = preg_replace("/\n$/","",$code);
    # remove trailing .class just in case it's included
    $code = preg_replace("/\.class$/","",$code);
    if(empty($codebase)){                                     
      $codebase = `dirname $path`;                            
      # make the codebase look like a directory, not neccessary for all browsers
      $codebase = preg_replace("/\n$/","/",$codebase);        
    }                                                         
    $applet = "<applet width='100%' height='100%' code='$code' codebase='$codebase' ></applet>";
  }else if(!empty($code)&&!empty($codebase)){                 
    # remove trailing .class just in case it's included       
    $applet = "<applet width='100%' height='100%' code='$code' codebase='$codebase' ></applet>";
  }
?>
Then I just echo the $applet variable's contents. Not a lot is actually being done besides build an <applet> tag with the given parameters. Most of the mumbojumbo is preparing the strings. I don't think it would be too hard to use wget and yank out the code and codebase parameters automatically... maybe I will add that soon. Update: I've added some css to make the page load better in Firefox. Also added the above mentioned wget applet extractor feature. I realized that I hadn't considered applet's with archive= parameters, so I have fixed that. Just now I am realizing that some applets won't run correctly if they rely on <param name = appletAttribute1 value = value> type tags in the <applet> tag. I will fix that soon.