473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamically pre-size an applet to percentage of window width?

I've always been bothered about having to statically declare the size of
a Java applet window (container?) in the calling HTML. I've always
wanted the moral equivalent of width=50% statement (of the window or frame).

I can sort of get an example working in a Mozilla browser:
<!-- This works on Mozilla only (and maybe netscape) -->
<script language="Javascript">
document.write( "<applet code=MyApplet.class width="
+ window.innerWidth/2 + " height="
+ window.innerWidth/2 + "></applet> <br>" );
</script>


So the document.write statement produces a normal looking applet string
like this:

<applet code=MyApplet.class width=252.5 height=252.5></applet>

Which gets intepreted by the browser, kicking off the applet. But as
you resize the browser the alignment with other text in the html window
is funky. Also, in the above example, the window.innerWidth is
apparently from the Mozilla/Netscape DOM, not MS-IE's.

Does anybody have any examples of how to dynamically presize an applet
to some percentage of the window/frame width? (that's mostly portable)

--
Ben in DC
Pu***********@benslade.com (put 030516 anywhere in the subj to get thru)
"It's the mark of an educated mind to be moved by statistics"
Oscar Wilde

Jul 17 '05 #1
1 5901
Actually, I figured this out myself:

This should *pre* size one time based on the
width of the web browser screen when the HTML page is loaded.

Here's my slightly verbosely commented example,
(also see www.benslade.com/DynAppletSize.html, note that I needed
the Sun Java plugin for this to work with MS-IE 6 on Win XP. Why?)

The first part which calculates the browser window dimensions has to come
after the <body> declaration for certain web browsers:
<body>

<script language="Javascript">
// Calc window/screen width/height for Mozilla, NN>4, IE>4, IE6 in CSS1Compat mode (with a Formal DOCTYPE)
// from http://jibbering.com/faq/ with slight mods
// Note, this size calc must be in the body for IE 5+
// Exports global variables winWidth, WinHeight

var d=document;
var winWidth, WinHeight;

if (typeof window.innerWidth!='undefined')
{ winWidth = window.innerWidth; var winHeight = window.innerHeight; }
else
if (d.documentElement && typeof d.documentElement.clientWidth!='undefined' && d.documentElement.clientWidth!=0)
{ winWidth = d.documentElement.clientWidth; winHeight = d.documentElement.clientHeight; }
else
if (d.body && typeof d.body.clientWidth!='undefined')
{ winWidth = d.body.clientWidth; winHeight = d.body.clientHeight; }
else { winWidth=150; winHeight=150; }
</script>

then somewhere later in the same HTML document. This example sizes
the Java applet to 1/2 the width of the web browser window:
<script language="Javascript">
// Dynamically generate the HTML for an applet tag so that
// it can be initially sized based on the browser window size
// The round() func is needed for MS-IE on Mac & PC?

document.write( "<applet code=MySwitchTest.class width=" +
Math.round(winWidth/2) +
" height=" + Math.round(winWidth/2) + "> </applet> <br>" );
document.write( "applet code=MySwitchTest.class width=" +
Math.round(winWidth/2) +
" height=" + Math.round(winWidth/2) + " /applet <br>" );
</script>


Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Daniel Ehrenberg | last post by:
One of the most common bugs that people have on the Python Tutor list are caused by the fact the default arguments for functions are evaluated only once, not when the function is called. The...
3
by: Robert Oschler | last post by:
Hello, I am a Python newbie (by experience, not chronologically :) ), so if any of this doesn't make sense my apologies in advance. I am reading the chapter in The Python Cookbook on databases...
14
by: Peter Olcott | last post by:
I want to be able to efficiently build data structures at run-time. These data structures need to be accessed with minimal time. The only a few ways that come immediately to mind would be some...
8
by: Kevin Little | last post by:
#!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or...
4
by: pauld | last post by:
$sql= sql query $i=0; while ($a2=mysql_fetch_array($a1)){array_push($temparray,$a2,$a2,$a2,$a2); { I want this array to be the value of an asssoc. array $results $results =$temparray doesnt...
0
by: comzy | last post by:
Hi all, I just need to add a class file in the updateable pre compiled project in vs.net 2005. can anyone tell me how can i do this because i couldnt find the APP_Code folder in the pre compiled...
46
by: Usenet User | last post by:
I need to be able to call the same API function from VB, which will reside in different DLLs. While all of the functions have the same signature and name, DLL file names are not known at compile...
5
by: marfi95 | last post by:
I have a form that has a left and right panel. In the left panel is a treeview. The right panel I want to change dynamically based on the type of node selected. What I'm doing is loading the...
1
by: BigDave | last post by:
Hi all, We have the desire to improve the "first hit lag" issue our their still low-volume asp.net 2.0 site. I maintain that the app is being unloaded from IIS 6 due to idleness. However, our...
4
by: mohaaron | last post by:
I can think of a lot of reasons why this might need to be done but as far as I can tell it's not possible. I've been looking for a way to add HtmlTableRows to a table using a button click for a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.