473,686 Members | 3,494 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 5926
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
1822
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
2565
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
3541
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
2940
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
12063
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
1100
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
3765
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
8583
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
1623
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
2966
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
8584
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8516
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,...
1
8768
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
8778
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
7599
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...
0
4308
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2945
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1934
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.