Functions in applet classes
hi guys
can u tell me whether functions other than init(),paint(),action(),etc(which are the basic functions) are allowed in an applet class.
Thanks!
avichal167
He Maxx,then what's wrong in this one:
(Please tell me something about "exceptions" which I should give in the paint() method.)
I have written this code for a GUI which checks for 4 types of punctuation errors in .txt files.
The code compiles correctly and the Gui also appears nicely but when I Give a pathname in the space provided(also using the escape sequence '\\' for the '\' character ) it does not generate the "errors.txt"
file whhich it is supposed to do.
The code is as follows:
import java.io.*;
import java.awt.*;
import java.applet.*;
public class textcopy extends Applet
public void init()
Choice ch=new Choice();
ch.addItem("Click Next to continue.");
ch.addItem("Framework Properties");
Label l1=new Label(" ");
Label nm=new Label("Please specify the errors that you want to be checked for in the file:");
Label a1=new Label("Write the pathname here:");
ta=new TextArea(1,20);
B=new Button("OK");
Checkbox b1=new Checkbox("Punctuation errors");
Checkbox b2=new Checkbox("Finding whether a key string is misspelt");
Label l2=new Label("Please select the key string from one of these:");
add(a1);
add(ta);
add(B);
add(l1);
add(nm);
add(b1);
add(b2);
add(l2);
add(ch);
TextArea ta;
Button B;String str="";
public boolean action(Event e,Object obj)
if(e.target instanceof Button)
repaint();
return true;
return false;
public void paint(Graphics g)
String s=ta.getText();
try{
FileReader fin=new FileReader(s);
PrintWriter fout=new PrintWriter(new BufferedWriter(new FileWriter("errors.txt")));
parse(fin,fout);
fin.close();
fout.close();
catch(IOException e){}
//This is the code for the parser ------it is perfectly correct--so you dont need to check this.
public static void parse(FileReader fin,PrintWriter fout)throws IOException
String str="Punctuation Errors:\n"; /*Heading*/
fout.println(str);
fout.println("========================================================");
int i=0,j=0,k=0,l=0;
j=fin.read();
do{
do{
i=j;
j=fin.read();
}while((!((char)i=='('&&(char)j=='R'))&&(j!=-1));
if(j==-1)break;
j=fin.read();
j=fin.read();
j=fin.read();
j=fin.read();
j=fin.read();
j=fin.read();
j=fin.read();
char refnum[]=new char[5];
l=0;
while((char)j!=')')
j=fin.read();
if((char)j!=')')
refnum[l++]=(char)j;
fout.write("REF. NUM: ");
for(int a=0;a<l;a++)fout.write(refnum[a]);fout.write(": ");
j=fin.read();
l=0;
do{
i=j;
j=fin.read();
if((char)i=='\n')
k++;
//'k' gives the line no. and finally the no. of lines and neglects the lines before first occurence of "Ref Num
if(((char)i==',')&&((char)j!=' '))
l++;
String st=l+". error at line number "+ (k+1) + ": There should be "+
"a space after comma(,) \n";
fout.println(st);
if(((char)i=='.')&&((char)j!=' '))
l++;
String st=l+". error at line number "+ (k+1) + ": There should be "+
"a space after period(.) \n";
fout.println(st);
if(((char)i=='.')&&((char)j=='.'))
l++;
String st=l+". error at line number "+ (k+1) + ": There should not be "+
"two periods(.) together \n";
fout.println(st);
if(((char)i==' ')&&((char)j=='.'))
l++;
String st=l+". error at line number "+ (k+1) + ": There should not be "+
"a space before a period(.) \n ";
fout.println(st);
}while((!((char)i=='-' && (char)j=='T')) && j!=-1);
fout.println(" ");
/*if(l==0)
fout.println("No errors!!!!");*/
if(j==-1)break;
}while(j!=-1);
The html file I made for this is as follows:
<html>
<body bgcolor="Red">
<center>
<h1><b>Welcome to qch </b></h1>
<applet code=textcopy.class width=800 height=400 >
</applet>
</center>
</body>
</html>
N.B.:I have not used main() in the above program becoz it would not have been a pure GUI program
Please see what I did wrong in the above code.
Thanks in advance
Avichal
Similar Messages
-
Hi,
I am trying to record automation functional test script on Oracle Forms 11g using OpenScript.
Able to open the browser, but after accessing application URL, getting application error as "Bad Applet class name"
Java Plug-in 10.17.2.02
Using JRE version 1.7.0_17-b02 Java HotSpot(TM) Client VM
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
SSV dialog is suppressed........
cracked oracle.forms.engine.Main
Loading cached Forms Jars ...
Is this version (Oracle forms 11g, JRE 1.7.0_17) supported by OATS-OpenScript ?
Please advise if there is any work around here.
Thanks.From the last OATS release notes available in the C:\OracleATS\docs directory:
4.1 Oracle Functional Testing/OpenScript
Oracle Functional Testing’s OpenScript scripting platform has the following system
requirements:
■ Operating System (32-bit and 64-bit versions): Windows XP, Windows Vista,
Windows 2003, Windows 7, Windows 2008, Windows 2008 R2.
■ Memory: Minimum 1 GB
■ System: x86, 32-bit or 64-bit processor, 2.6 GHz or faster
■ Disk Space: 4 GB minimum
■ Browser: Internet Explorer 7.x, 8.x., 9.x; Firefox 3.5/3.6, 6.x, 10; Chrome 27+
(playback only).
■ Java Runtime Environment: JRE 1.6 minimum (up to build 38), JRE 1.7 (up to build
11) .
So basically, it's not supported... Can you try with another JRE version?
As always don't forget to run OpenScript as administrator on W7/8 or equivalent
JB -
Getting Bad Applet class name exception while opening applet.
Hi,
While opening an applet in my mac os x v10.6.8 machine i am getting "Bad Applet class name exception" which is working fine in mac os x v10.7.5.Java version in my mac is 1.6.0_43.Can anyone please help me to resolve this.Apple barred Java from running on Macs in order to safeguard users by blocking Java 7 Update 11 and adding it to the banned list in XProtect.
This was the second time in two weeks that Apple had blocked Oracle's code from running on Macs. The threat was so serious that the U.S. Department of Homeland Security had recommended that all Java 7 users disable or uninstall the software until a patch was issued. This time Java is blocked through Apple's XProtect anti-malware feature.
Java has come under fire as the means by which hackers have been able to gain control of computers. In April 2012 more than 600,000 Macs were reported to have been infected with a Flashback Trojan horse that was being installed on people's computers with the help of Java exploits. Then in August Macs were again at risk due to a flaw in Java, this time around, there was good news for Mac users: Thanks to changes Apple has made, most of us were safe from the threat.
Unwilling to leave its customers open to potential threats Apple decided it's safer to block Java entirely.
In order to block older versions of Flash, Apple has updated its "Xprotect.plist" file so that any versions that come before the current one (version 11.6.602.171) cannot be used on a Mac. Users who have older versions of Flash installed will be greeted with an alert that says "Blocked plug-in," and Safari will prompt the user to update to a newer version.
Macs running OS X Snow Leopard and beyond are affected.
UPDATE for those running Lion or Mountain Lion:
Oracle on Friday February 1 released a new version reportedly addressing vulnerabilities seen with the last build.
Apple disabled Java 7 through the OS X XProtect anti-malware system, requiring users to have at least version "1.7.0_10-b19" installed on their Macs. The release dated February 1 carries the designation "1.7.0_13-b20," meeting Apple's requirements.
Oracle "strongly recommends" applying the CPU fixes as soon as possible, saying that the latest Critical Patch Update contains 50 new security fixes across all Jave SE products.
Update for Snow Leopard users:
Apple issued update 12 for Java for OS 10.6:
http://support.apple.com/kb/DL1573
Note: On systems that have not already installed Java for Mac OS X 10.6 update 9 or later, this update will configure web browsers to not automatically run Java applets. Java applets may be re-enabled by clicking the region labeled "Inactive plug-in" on a web page. If no applets have been run for an extended period of time, the Java web plug-in will deactivate.
If, after installing Java for OS X 2013-002 and the latest version of Java 7 from Oracle, you want to disable Java 7 and re-enable the Apple-provided Java SE 6 web plug-in and Web Start functionality, follow these steps:
http://support.apple.com/kb/HT5559?viewlocale=en_US
Further update:
Apple issued this Java related security update No. 13 on February 19:
http://support.apple.com/kb/HT5666
and Update No. 14 on March 4: http://support.apple.com/kb/DL1573
http://support.apple.com/kb/HT5677
You should also read this:
https://support.apple.com/kb/HT5672
The standard recommendation is for users to turn off Java except when they have to use it on known and trusted websites (like their bank). Javascript, which is unrelated despite the name, can be left on.
Further useful comment in this article:
http://www.macworld.co.uk/macsoftware/news/?newsid=3435007&olo=email -
InitializeUpdate function of the class CardManager from com.ibm.jc
Hi,
I am currently trying to create an Applet loader for JavaCard and I am getting in trouble with the initializeUpdate function of the class CardManager. Bellow is the code I write to initialize the communication with the javacard/reader...
//list all the readers with a card present
readers = TerminalFactory.getDefault().terminals().list(State.CARD_PRESENT);
if(readers.isEmpty()){
return;
//establish connection with the reader
term = (PCSCJCTerminal)JCTerminal.getInstance("PCSC",readers.get(0).toString().substring(15));
term.open();
atr = new ATR(term.waitForCard(2000));
//connect to card
System.out.println("Getting card ...");
card = new JCard(term,atr,2000);
//select Cardmanager
System.out.println("Selecting card manager ...");
cardmanager = new CardManager(card, CardManager.daid);
cardmanager.select();
//setup keys
byte[] dfltKey = c2b("404142434445464748494a4b4c4d4e4f");
cardmanager.setKey(new OPKey(1, 1, OPKey.DES_ECB, dfltKey));
cardmanager.setKey(new OPKey(1, 2, OPKey.DES_ECB, dfltKey));
cardmanager.setKey(new OPKey(1, 3, OPKey.DES_ECB, dfltKey));
//authenticate to cardmanager
System.out.println("Authenticate to card manager ...\n");
* cardmanager.initializeUpdate(1, 0,CardManager.SCP_01_05);*
cardmanager.externalAuthenticate(OPApplet.APDU_CLR);
When I am launching the program, everything goes well until the initializeUpdate function which throw the exeption:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/jc/CL3
at com.ibm.jc.OPApplet.initializeUpdate(Unknown Source)
at com.jnet.tools.LoadApplet.initConnection(LoadApplet.java:80)
at com.jnet.tools.LoadApplet.load(LoadApplet.java:88)
at com.jnet.benchmarks.ClientBenchs.runTest(ClientBenchs.java:636)
at com.jnet.benchmarks.ClientBenchs.main(ClientBenchs.java:485)
Caused by: java.lang.ClassNotFoundException: com.ibm.jc.CL3
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Since I am quiet new in Java, I don't know what this exception means. I think that all the parameters of the function are good since I am using the same when I load "manually" the Applets on the card with the same parameters and it works. My JRE is 1.6 (but I also tried in 1.5), and the JCOP tools version is 3.2.7.
I also tried with a different card with a different AID and different SCP parameter but I always have the same error.
Thank in advance for the future replier862087 wrote:
Hi,
I am currently trying to create an Applet loader for JavaCard and I am getting in trouble with the initializeUpdate function of the class CardManager. Bellow is the code I write to initialize the communication with the javacard/reader...
//list all the readers with a card present
readers = TerminalFactory.getDefault().terminals().list(State.CARD_PRESENT);
if(readers.isEmpty()){
return;
//establish connection with the reader
term = (PCSCJCTerminal)JCTerminal.getInstance("PCSC",readers.get(0).toString().substring(15));
term.open();
atr = new ATR(term.waitForCard(2000));
//connect to card
System.out.println("Getting card ...");
card = new JCard(term,atr,2000);
//select Cardmanager
System.out.println("Selecting card manager ...");
cardmanager = new CardManager(card, CardManager.daid);
cardmanager.select();
//setup keys
byte[] dfltKey = c2b("404142434445464748494a4b4c4d4e4f");
cardmanager.setKey(new OPKey(1, 1, OPKey.DES_ECB, dfltKey));
cardmanager.setKey(new OPKey(1, 2, OPKey.DES_ECB, dfltKey));
cardmanager.setKey(new OPKey(1, 3, OPKey.DES_ECB, dfltKey));
//authenticate to cardmanager
System.out.println("Authenticate to card manager ...\n");
* cardmanager.initializeUpdate(1, 0,CardManager.SCP_01_05);*
cardmanager.externalAuthenticate(OPApplet.APDU_CLR);When I am launching the program, everything goes well until the initializeUpdate function which throw the exeption:
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/jc/CL3
at com.ibm.jc.OPApplet.initializeUpdate(Unknown Source)
at com.jnet.tools.LoadApplet.initConnection(LoadApplet.java:80)
at com.jnet.tools.LoadApplet.load(LoadApplet.java:88)
at com.jnet.benchmarks.ClientBenchs.runTest(ClientBenchs.java:636)
at com.jnet.benchmarks.ClientBenchs.main(ClientBenchs.java:485)
Caused by: java.lang.ClassNotFoundException: com.ibm.jc.CL3
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)Since I am quiet new in Java, I don't know what this exception means. I think that all the parameters of the function are good since I am using the same when I load "manually" the Applets on the card with the same parameters and it works. My JRE is 1.6 (but I also tried in 1.5), and the JCOP tools version is 3.2.7.
I also tried with a different card with a different AID and different SCP parameter but I always have the same error.
Thank in advance for the future replierRepost with code tags -
How to extend the JVue applet class using ActiveX Control
My SR recommendation was to post this here:
) How to Extend the JVue Applet class
This is the preferred solution. However, when using the ActiveX control, my derived JVue class that is specified in autovue.properties is not being instantiated.
Your ActiveX bridge looks like it's hard coding a "new JVue()" which means I have no integration hook using the ActiveX control.
To reiterate, if I extend JVue to add functionality and specify it in the autovue.properties, it is picked up when I run it standalone but if I use the ActiveX component, it is not being picked up.
I have already read all the documentation, have had web conferences with Mahmood and Jeff Chapman and the engineering staff who recommended this approach as the preferred option.We have a need to override certain VueBean/JVue method calls to meet our document handling(documents need to handle metadata information and hence change the document loading cycle, ie markup loading/XRef resolution is dynamic). Also the invokeAction/invokeSubAction do not allow parameter passing(which we have requirements for certain actions again due to metadata) so we would like to override the invokeAction method to include custom processing(we will encode the action with parameters).
We are already using Custom VueActions for other simpler UI event handling that don't have parameter requirements.
As I said above, these use cases were relayed to the engineering team and senior staff members in early December and we were told that we could proceed with overriding the main class in the autovue.properties file. I have SR(s) opened with a long thread detailing this so I really don't want to go through this again.
A custom VueAction does not seem to work because it binds to late in the object call/event stream. -
Browser doesn't display applets (classes)
hi all,
i am sure every beginner faced the same problem
though i am not a beginner, i am facing this strange problem, and i can't figure out where the proble is .
i just started developing simple swing applications. first i want to try the examples given in a tutorial.
most of them are japplets (applets created by swing components)
Strange thing is that none of htem works on my browser WHICH DRIVES ME CRAZY !!
let me make my situation clearer:
i put the Japplet class file and the html file whick invokes the applet under the same directory
as far as i know , since they are in the same directory i don't need t to set the classpath , am i right?
well, if i open the html file directly from that directory, it can find the Japplet and it works
but when i put them in another directory under the root of tomcat 4 and try to access them through :
http://<hostaddress>:8080/applet.html
applet.html opens but can't find my applet class saying that app.class not found
the relevant html code is as follows:
<html>
<body>
<applet code=app.class width=100 height=50>
</applet>
</body>
</html>
what am i supposed to do?where am i wrong?
by the way to make sure i also added .; to my classpath
my OS is win 2000,
i am using jdk1.3.1
do i need something else to make them work
thanks for helping in advance :)
cheers :)Is it a typing error or not.
Your html code is
<applet code=app.class width=100 height=50>Is this really the code you use?
I am missing the " "
<applet code="app.class" width=100 height=50>If you don't use the "", app.class can not be found. -
How to load function from derived class from dll
Dear all,
how to access extra function from derived class.
for Example
//==========================MyIShape.h
class CMyIShape
public:
CMyIShape(){};
virtual ~CMyIShape(){};
virtual void Fn_DrawMe(){};
// =========== this is ShapRectangle.dll
//==========================ShapRectangle .h
#include "MyIShape.h"
class DLL_API ShapRectangle :public CMyIShape
public:
ShapRectangle(){};
virtual ~ShapRectangle(){};
virtual void Fn_DrawMe(){/*something here */};
virtual void Fn_ChangeMe(){/*something here */};
__declspec (dllexport) CMyIShape* CreateShape()
// call the constructor of the actual implementation
CMyIShape * m_Obj = new ShapRectangle();
// return the created function
return m_Obj;
// =========== this is ShapCircle .dll
//==========================ShapCircle .h
#include "MyIShape.h"
class DLL_API ShapCircle :public CMyIShape
public:
ShapCircle(){};
virtual ~ShapCircle(){};
virtual void Fn_DrawMe(){/*something here */};
virtual void Fn_GetRadious(){/*something here */};
__declspec (dllexport) CMyIShape* CreateShape()
// call the constructor of the actual implementation
CMyIShape * m_Obj = new ShapCircle();
// return the created function
return m_Obj;
in exe there is no include header of of ShapCircle and ShapRectangle
and from the exe i use LoadLibrary and GetProcAddress .
typedef CMyIShape* (*CREATE_OBJECT) ();
CMyIShape*xCls ;
//===================== from ShapeCircle.Dll
pReg= (CREATE_OBJECT)GetProcAddress (hInst ,"CreateShape");
xCls = pReg();
now xCls give all access of base class. but how to get pointer of funciton Fn_GetRadious() or how to get access.
thanks in advance.could you please tell me in detail. why so. or any reference for it. i love to read.
i don't know this is bad way.. but how? i would like to know.
I indicated in the second sentence. Classes can be implemented differently by different compilers. For example, the alignment of member variables may differ. Also there is the pitfall that a class may be allocated within the DLL but deallocated in the client
code. But the allocation/deallocation algorithms may differ across different compilers, and certainly between DEBUG and RELEASE mode. This means that you must ensure that if the DLL is compiled in Visual Studio 2010 / Debug mode, that the client code is also
compiled in Visual Studio 2010 / Debug mode. Otherwise your program will be subject to mysterious crashes.
is there any other way to archive same goal?
Of course. DLL functionality should be exposed as a set of functions that accept and return POD data types. "POD" means "plain-ole-data" such as long, wchar_t*, bool, etc. Don't pass pointers to classes.
Obviously classes can be implemented within the DLL but they should be kept completely contained within the DLL. You might, for example, expose a function to allocate a class internally to the DLL and another function that can be called by the client code
to free the class. And of course you can define other functions that can be used by the client code to indirectly call the class's methods.
and why i need to give header file of ShapCircle and shapRectangle class, even i am not using in exe too. i though it is enough to give only MyIShape.h so with this any one can make new object.
Indeed you don't have to, if you only want to call the public properties and methods that are defined within MyIShape.h. -
Where should i put html with applet class embedded?thanks
Tomcat4.0 server
i put html and applet class in the root of my project(/webapps/test/)
when i hit the html file locally, it displays well. but it doesn't work when it comes to service.
plus:the applet class is developed with jdk1.1.8
any help is apprieciated!The first thing I would do is recompile the applet with a newer JDK. Second, you need to post more info on the problem. What do you mean by "service"?
-
How to include applet in jsp if applet.class file in another folder
hi,
i'm getting problem when my applet.class file is not with its appropriate jsp file. i'm using jsp :plugin tag.it work when jsp file n apllet.class file at same location.
in short my jsp file is at location /webapps/jsp-examples/myproject/includeDemo.jsp
n applet i want in a WEB-INF folder.
Plz help me to solve this..
or give me other way that an applet can be loaded in jsp page n applet should be in WEB-INF file..
Help me for thishttp://forum.java.sun.com/thread.jspa?threadID=5148764&messageID=9556205
-
Netscape 's inconsistency in the loading of applets/classes
Please I will appreciate any help.
I am using Netscape version 4.75 on a Windows NT platform to launch my application.
My application is a collection of java classes and applet classes and a gif file all zipped
into an archive ( zip -o ). These classes are written in the old java version 1.0.2
(unfortunately).The problem is that when it is launched from a netscape browser,
sometimes all the classes get loaded but other times the loading fails. The zip file is not compressed since we realized that it was failing more often with a compressed zip file.
SO we removed the zip file... This is how we are launching the application now but this,
too, creates a problem because there are incidents of partial or incomplete loading of
the classes. This application has been in use for over 3 years now, what can I do?
Please help!
Ike EkeThanks for you quick response.
I have not tried a jar. Can I jar these classes that were written in java 1.0.2?
I have recommended that the application be upgraded to 1.1.x but they say there is
no money to do that, The customer would not fund it.
This problem does not occur on IE but we do not support IE any way. We run on HP,SUN,
and Windows NT platforms but this problem occurs only on NT. This is a production problem
so it occurs very where there is an NT machine ( over 200 NT users out there).
This is the version of Netscape that was chosen by the customer and yes it occurs on other netscape versions as well. I thought that jar files came with the emergence of java 1.1.x.
If it is possible to jar this outdated version of java classes, then I am willing to try it but
what is required to do this?
Thanks again
Ike -
Hi.. can anybody help me.. with this age old problem?
I have an applet.. which generates a pie chart .. Pie.class. If i embed it in a normal HTML page.. it runs smoothly.
Now the problem is.. in my servlet i tried to do this
out.println("<applet code=Pie.class codebase=/mywebapp/ height=300 width=300">);etc..
but when the servlet runs.. the applet is not initalised .. so instead of having the applet i have a 'x' sign.. .. To diagnose the problem better.. i right click on the area that is supposed to be the applet and select 'Open Java Console' . ..there i see.. a ClassNotFound Exception.
I have kept the Pie.class in the WEB-INF -> classes Folder ( where all the other class files of the servlets are kept ).
Can anybody help me??
Thanks in advance
Hi guys sorry to bother u.. i have found the soln. myslef... my mistake was to place the applet class in web-inf-> class folder.. as soon as i placed it outside the folder.. it worked superbly. Thanks anyway
Message was edited by:
arijit_dattame also same problem...
this class path is included in server itself..
or we can set during compiling time...
then this is my compile.bat file please check
set classpath=%CLASSPATH%; ./WEB-INF/classes;
@echo off
javac -d ./WEB-INF/classes/ ./dev/beans/*.java
javac -d ./WEB-INF/classes/ ./dev/ContentManagement/beans/*.java
javac -d ./WEB-INF/classes/ ./dev/servlets/*.java
and my servlet file like this below..
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.deploy.servlet.*;
public class ControlServlet extends HttpServlet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Testing");
/* if (request.getParameter("pageName")=="CEOSpeak")
CEOBean CB = new CEOBean();
if (request.getParameter("actionType")=="add")
else if (request.getParameter("actionType")=="edit")
else if (request.getParameter("actionType")=="delete")
if(CB.deleteCEO(request.getParameter("CEOId")))
response.sendRedirect("CEO_Speaks.jsp"); -
Netscape.javascript.JSObject outside an applet class
Hi,
I need to evaluate some Javascript expressions inside my java code... BUT my code is not inside an Applet class. Does anyone know how to do it?
I chose to use the netscape.javascript package, it work well inside an applet.. but my application doesn't run inside an applet. When I try to run it inside a standalone application it fails (even if the application extends from the Applet class).
Here is part of the code:
public class Applet1 extends Applet {
public void init() {
try {
String out;
JSObject win = JSObject.getWindow(this);
out=win.eval("2+3;").toString();
jLabel1.setText(out);
System.out.print(out);
public static void main(String[] args){
Applet1 app=new Applet1();
app.init();
The code runs perfect inside Internet explorer, but it crashes when running in standalone mode.
Thanks.You can also use Rhino to execute JavaScript
http://www.mozilla.org/rhino/ -
Ok, I have found defining classes in .as files can be very
useful for me. I have a few functions that are being called over
and over again in different movies. There is what I want / need to
do in order to stream line the creating and updating of the flash
site. I want to see if I can put those same functions into a class
(.as file) so I can access them from anywhere in the flash movie.
The problem is when I just try to copy and paste the functions to
the .as file (func.as) and then call the function by,
func.FunctionName I get errors. The movie is calling the functions
when buttons are pressed. Any ideas? I will attach some functions I
am using that I would like to move to the func.as file.OK........ Couple of things I see....
func.as
package{
public class func{ // This is the name of your class and as
such, it needs a constructor.....
public function func() {
// Doesn't need to do anything
Your import should be inside your package but outside the
class definition
You need to import your package into your Flash shell before
you can call the BackToMenu funciton (this is the real reason for
the error).
If you get an error about not being able to nest packages,
you'll need to adjust things
package com.mysite.common {
the above line will assume that you have folders relative to
your flash shell of the same names.....
com \ mysite \ common \ func.as
If this doesn't make sense, just let me know. We'll get it
straightened out. -
Calling a function in another class that is not the App delegate nor a sngl
Hi all-
OK- I have searched and read and searched, however I cannot figure out an easy way to call a function in another class if that class is not the app delegate (I have that down) nor a singleton (done that also- but too much code)
If you use the method Rick posted:
MainView *myMainView = [[MainView alloc] init];
[MyMainView goTell];
That works, however myMainView is a second instance of the class MainView- I want to talk to the instance/Class already instantiated.
Is there a way to do that without making the class a singleton?
Thanks!I had some trouble wrapping my head around this stuff at first too.
I've gotten pretty good at letting my objects communicate with one another, however I don't think my method is the most efficient or organized way but I'll try to explain the basic idea.
When you want a class to be able to talk to another class that's initialized elsewhere, the class your making should just have a pointer in it to the class you want to communicate with. Then at some point (during your init function for example) you should set the pointer to the class you're trying to message.
for example in the app-delegate assume you have an instance of a MainView class
and the app-delegate also makes an instance of a class called WorkClass
If you want WorkClass to know about MainView just give it a pointer of MainView and set it when it's instantiated.
So WorkClass might be defined something like this
//WorkClass.h
@import "MainView.h"
@interface WorkClass : NSObject
MainView *myPointerToTheMainView;
@property (retain) myPointerToTheMainView;
-(void)tellMainViewHello;
@end
//WorkClass.m
@import "WorkClass.h"
@implementation WorkClass
@synthesize myPointerToTheMainView;//this makes getter and setter functions for
//the pointer and allows us to use the dot
//syntax to refrence it.
-(void)tellMainViewHello
[myPointerToTheMainView hello]; //sends a message to the main view
//assume the class MainView has defined a
//method -(void)hello
@end
now somewhere in the app delegate you would make the WorkClass instance and pass it a reference to the MainView class so that WorkClass would be able to call it's say hello method, and have the method go where you want (to the single instance of MainView owned by the app-delegate)
ex:
//somewhere in app-delegate's initialization
//assume MainView *theMainView exists and is instantiated.
WorkClass *myWorkClass = [[WorkClass alloc] init];
myWorkClass.myPointerToTheMainView = theMainView; //now myWorkClass can speak with
// the main view through it's
// reference to it
I hope that gets the basic idea across.
I'm pretty new to Obj-c myself so if I made any mistakes or if anyone has a better way to go about this please feel free to add
Message was edited by: kodafox -
Calling a function inside another class
I have the following two classes and can't seem to figure to figure out how to call a function in the top one from the bottom one. The top one get instantiated on the root timeline. The bottom one gets instantiated from the top one. How do I call functions between the classes. Also, what if I had another call instantiated in top one and wanted to call a function in the bottom class from the second class?
Thanks a lot for any help!!!
package
import flash.display.MovieClip;
public class ThumbGridMain extends MovieClip
private var grid:CreateGrid;
public function ThumbGridMain():void
grid = new CreateGrid();
public function testFunc():void
trace("testFunc was called");
package
import flash.display.MovieClip;
public class CreateGrid extends MovieClip
public function CreateGrid():void
parent.testFunc();kglad,
Although I agree that utilizing events the way you attempted in your suggestion is better for at least a reason of eliminating dependency on parent, still you code doesn't not accomplish what Brian needs.
Merely adding event listener to grid instance does nothing - there is no mechanism in the code that invokes callTGMFunction - thus event will not be dispatched. So, either callTGMFunction should be called on the instance (why use events - not direct call - in this case?), or grid instance needs to dispatch this event based on some internal logic ofCreateGrid AFTER it is instantiated - perhaps when it is either added to stage or added to display list via Event.ADDED. Without such a mechanism, how is it a superior correct way OOP?
Also, in your code in ThumbGridMain class testFunc is missing parameter that it expects - Event.
Am I missing something?
I guess the code may be (it still looks more cumbersome and less elegant than direct function call):
package
import flash.display.MovieClip;
import flash.events.Event;
public class ThumbGridMain extends MovieClip
private var grid:CreateGrid;
public function ThumbGridMain():void
grid = new CreateGrid();
grid.addEventListener("callTGMFunction", testFunc);
addChild(grid);
// to call a CreateGrid function named cgFunction()
public function callCG(){
grid.cgFunction();
public function testFunc(e:Event):void
trace("testFunc was called");
package
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.Event;
public class CreateGrid extends MovieClip
public function CreateGrid():void
if (stage) init();
else addEventListener(Event.ADDED, callTGMFunction);
// to call a TGM function
public function callTGMFunction(e:Event = null):void
// I forgot this one
removeEventListener(Event.ADDED, callTGMFunction);
this.dispatchEvent(new Event("callTGMFunction"));
public function cgFunction(){
trace("cg function called");
I think this is a case of personal preference.
With that said, it is definitely better if instance doesn't rely on the object it is instnatiated by - so, in this case, either parent should listen to event or call a function directly.
Maybe you are looking for
-
Installation of the patch 127576-03 for solaris 10 8/07 for Netra T2000
I am new in Solaris/Unix systems. I need to install a new patch for solaris 10 8/07, which is the 127576-03. I want to read the install information and I have seen in this website, where I downloaded the patch, that the install information is held in
-
I am unable to get past the invalid security certificate warning.
I get the message "Invalid security certificate" I click OK., and then the message disappears and I am not given the option to enter an exception and approve the site. It is the e-mail address for my office (state agency) and as a cost saving measure
-
Driver download link does not exsist!
Hey there, Hope this is the right forum since this is Services related I believe. Anyway, I thought my ATI HD 2400 could do with a Catalyst Control Centre update since the current version I have installed is from 07. My computer is an A200-2BO a Tesc
-
Older versions of Nano & Shuffle
My question: We have an older version of Shuffle purchased last summer and a new Nano (brand new, but it is an older model...the black 1GB model). The computer they are using is only 192MB RAM so they are using iTunes version 6.0.5.....since the newe
-
Search for data in server based database.
I have a web page (http://gosolivitahomes.com) where I can enter a search for data in my server based database. If I enter a value less than $100,000 in Min Price I get no response. For values >= $100,000 I get the correct response. Why? Please he