473,734 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="Javas cript">
document.write( "<applet code=MyApplet.c lass width="
+ window.innerWid th/2 + " height="
+ window.innerWid th/2 + "></applet> <br>" );
</script>


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

<applet code=MyApplet.c lass 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.innerWid th 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***********@b enslade.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 5935
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="Javas cript">
// 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.innerWid th!='undefined' )
{ winWidth = window.innerWid th; var winHeight = window.innerHei ght; }
else
if (d.documentElem ent && typeof d.documentEleme nt.clientWidth! ='undefined' && d.documentEleme nt.clientWidth! =0)
{ winWidth = d.documentEleme nt.clientWidth; winHeight = d.documentEleme nt.clientHeight ; }
else
if (d.body && typeof d.body.clientWi dth!='undefined ')
{ winWidth = d.body.clientWi dth; winHeight = d.body.clientHe ight; }
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="Javas cript">
// 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=MySwitchTe st.class width=" +
Math.round(winW idth/2) +
" height=" + Math.round(winW idth/2) + "> </applet> <br>" );
document.write( "applet code=MySwitchTe st.class width=" +
Math.round(winW idth/2) +
" height=" + Math.round(winW idth/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
1825
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 solution to this is usually to use the following idiom: def write_stuff(stuff=None): """Function to write its argument. Defaults to whatever is in the variable "things" """
3
2570
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 and the MySQLdb module. In it they show an example of a recipe that lets you access fields in a MySQL row by name rather than by column number. For example, given a MySQL row object from a fetchone() call:
14
3547
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 sort of dynamically allocated array of : (1) void pointers, that must be cast into the desired types. (2) union of the desired pointers. (3) An Inheritance hierarchy (4) Possibly a union of the desired data types.
8
2942
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 after the class was modified. I need this to work for both old ('classic') and new style classes, at both 2.3 and 2.4. I of course want to avoid side effects, and to make the solution as light-weight as possible.
4
12064
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 work $results =$temparray doesnt work $results =$temparray doesnt work
0
1103
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 project. Thanks and Regards, Shiva.
46
3779
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 time. Therefore, my assumption that using Declare statement or DllImport attribute is NOT an option in such a case. I can use LoadLibrary() and GetProcAddress() from Kernel32 to get the addreses, but is there a way to actually call an API method...
5
8589
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 treeview nodes through an XML file. As part of each node in the XML, I'm using an attribute that indicates the name of a sub form to load. As part of all these little child forms, the main control is a panel, which I then assign its parent to the...
1
1629
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 web host maintains that we should pre-compile the site. I know that pre-compiling will help with the first-hit after an update to the site; but from that point forward, I wouldn't think it will
4
2971
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 while and it seems it's not possible because the row that gets added with each click won't get recreated after a post back. After all the reading it seems that any dynamically created controls must be created in the Init event to be recreated after...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.