473,385 Members | 1,907 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,385 software developers and data experts.

accessing java methods in javascript

13
hi
i have the following java applet progam and the javascript
the problem is that when the javascript tries to access the applet method it gives me an error as follows
document.form1.myApplet is null or not an object. plz provide me a soln for this. the code is as
html file
Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <SCRIPT type="text/javascript">
  4. function getScreenDim() {
  5. alert(document.form1.hello.value);
  6. str = document.form1.myApplet.getScreen();
  7. alert(str);
  8. }
  9. </SCRIPT>
  10. </HEAD>
  11. <BODY>
  12. <FORM name="form1">
  13. <INPUT type="button" name="hello" value="call JAVA"  onClick="getScreenDim()">
  14. <applet code="javascriptTest\InJava2" name="myApplet" width="20" height="20">
  15. </applet>
  16.  
  17.  
  18. </FORM>
  19. </BODY>
  20. </HTML>

java file
Expand|Select|Wrap|Line Numbers
  1. package javascriptTest;
  2.  
  3.  
  4. import java.applet.Applet;
  5. import java.awt.Toolkit;
  6. //(IE and Netscape ok)
  7. public class InJava2 extends Applet {
  8.   public String getScreenWidth() {
  9.         return String.valueOf(Toolkit.getDefaultToolkit().getScreenSize().width);
  10.       }
  11.       public int getScreenHeight() {
  12.         return Toolkit.getDefaultToolkit().getScreenSize().height;
  13.       }
  14.       public static int getScreen() {
  15.             return 25;
  16.           }
  17.     }
thanks
mansoor
Aug 13 '07 #1
2 1436
pbmods
5,821 Expert 4TB
Heya, mansoor. Welcome to TSDN!

I award 8 points for creative use of [b] tags, but I have to deduct 8 points for not using [code] tags. Better luck next time.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Aug 13 '07 #2
acoder
16,027 Expert Mod 8TB
See this link.

Move the applet out of the form.
Aug 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

54
by: Jerry | last post by:
What are the advantages and disadvantages of using Object Oriented PHP vs Java?
0
by: Kookymon1 | last post by:
This is an attempt to respond to an older question (several months). Date: 2002-03-07 13:10:23 PST Subject: On the Common DOM API and Applets. The original message was: >LiveConnect and the...
2
by: Brice Laurencin | last post by:
My code is like that : <jsp:useBean id="vConf" type="cat.eur.tb.eleccard.datatypes.Config" scope="session" /> <jsp:useBean id="equNo" type="java.lang.Integer" scope="session" /> <script...
2
by: annie | last post by:
Hi all. Can Java classes/objects be used from within the javascript code on the HTML page? I.e., can I call a Java method from the javascript function? Thanks in advance Anna
2
by: mikelsmith | last post by:
I have a javascript function that needs to access methods of a java object(localTag). In my JSP I'm trying to include hidden fields for the Strings returned from the getter method calls of the...
7
by: David Laub | last post by:
I've also posted this issue to a Sun/java formum, but since it appears to be an integration issue, this may be the better place to posr: I have written a dot net/c# Web Services doesn't fully...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: ozzii | last post by:
Hi, Does any body know if it is posible to access Java methods in a .NET environment using C#? E.g. In Java I would access Java methods as follows: import my.formats.*; import my.struc.*;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...

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.