Setting MenuBar in an Applet
Hi
I am trying to add a MenuBar to an Applet. The setMenuBar () does not work.
Thank You,
Salil.
setLayout(new BorderLayout());
MenuBar mb=new MenuBar();
setMenuBar(mb);
Similar Messages
-
Hello,
Basically i wanna do all of the function listend in this code with an applet in the background. however it seems that I can't run any JOptionPane's simotaneously with the applet. Is there any way i can run teh applet, set the variables, and run back and forth from files like I want to do?
import java.*;
import javax.swing.*;
import java.awt.*;
public class FinalJava extends Object{
String choicestring,twodchoicestring, intersectionchoicestring;
String linexonestring, lineyonestring, linextwostring, lineytwostring;
int choice,twodchoice,intersectionchoice;
int linexone,lineyone,linextwo,lineytwo;
public static void main(String [] args)
FinalJava g = new FinalJava();
g.Choice();
public void Choice()
choicestring = JOptionPane.showInputDialog("Enter 0 to chooose 2D shapes to draw\nEnter 1 to plot some intersections\nEnter 2 to draw some 3D shapes");
choice = Integer.parseInt(choicestring);
if(choice == 0)
LineDraw ld = new LineDraw();
ld.VariablesEnter();
else if (choice == 1)
this.PlotIntersectionsChoice();
else if (choice == 2)
//ThreeDShapesChoice(); not made yet
}//end Choice() void
public void PlotIntersectionsChoice()
//see waht type of intersection the user wants
intersectionchoicestring = JOptionPane.showInputDialog(null,"Enter one to intersect between line and line\n Enter two for line and circle\nEnter three for circle and circle");
intersectionchoice = Integer.parseInt(intersectionchoicestring);
if (intersectionchoice == 1)
LineIntersect li = new LineIntersect();//go to my line-line intersect class
li.VariablesEnter();
else if (intersectionchoice == 2)
LineCircleIntersect lci = new LineCircleIntersect();//go to my line circle intersect class
lci.EnterVariables();
else if (intersectionchoice == 3)
CircleIntersect ci = new CircleIntersect();//go to my circle-circle intersect calss
ci.CircleDefinition();
}Also....I want to be able to run taht applet in the FinalJava program so taht i can draw the line in the linedrawing program below...Also is tehre a way to tell it to jump from VariablesEnter() to the paint void?
Also.....it would be better if i could run an applet from this class....and still have the capability of moving back to my origial file after the appelt draws the line....so basically...how do i run an applet from this class; while still bieng able to go extend my FinalJava that i posted above.
import java.*;
import javax.swing.*;
import java.awt.*;
public class LineDraw extends JApplet {
String xonestring, yonestring,xtwostring,ytwostring;
int xone, yone, xtwo, ytwo;
public static void main(String args [])
LineDraw ld = new LineDraw();
ld.VariablesEnter();
public void VariablesEnter()
xonestring = JOptionPane.showInputDialog(null, "Please enter x1");
yonestring = JOptionPane.showInputDialog(null, "Please enter y2");
xtwostring = JOptionPane.showInputDialog(null, "Please enter x2");
ytwostring = JOptionPane.showInputDialog(null, "Please enter y2");
xone = Integer.parseInt(xonestring);
yone = Integer.parseInt(yonestring);
xtwo = Integer.parseInt(xtwostring);
ytwo = Integer.parseInt(ytwostring);
public void paint(Graphics g)
super.paint(g);
g.drawLine(xone,yone,xtwo,ytwo);
FinalJava fj = new FinalJava();
fj.Choice();
} -
How to set the size of applet when invoking forms through formsserver
HI,
I m using forms server to display my forms in browser, my
problem is to change the size of applet at runtime so that the
entire forms is displayed.
right now the forms whose size is more r displayed with
scrollbars.
and thats giving me problem with printing.
Sreekant- The HEIGHT and WIDTH parameters in the HTML file are
responsible for the size
of the applet area. This is documented in the Forms online
manuals. The
manual also states that these values are in pixels.
Tip
This value can be set to a percentage of the browser's available
work space.
This means that if the browser is resized or the DISPLAY
resolution is changed
the applet area will adjust to those changes.
Example
Instead of the following:
WIDTH=800
HEIGHT=600
Change to:
WIDTH=100%
HEIGHT=100%
This will make the applet use 100% of the browser's work space.
If you
change the values to 50%, the applet will use 50% or the
browser's space.
The HEIGHT and WIDTH values can be defined in your FORMSWEB.CFG
or your own
static html file. These values can also be added to the URL when
using CGI.
NOTE: THIS WILL NOT WORK IF SEPARATEFRAME=TRUE
Regards
Grant Ronald
Forms Product Management -
PROXY SETTING ERROR - LOADING JAVA APPLET FAILED
I have the most current version of Java (confirmed) installed l.5.0. When I do the Java Virtual Test, I fail at the proxy setting with the red X. I have tried everything recommended at "Configuration Check List" and I have also chatted with microsoft techs who recommended that I register certain .dll's among other things. Nothing has worked. Is the Java Control Panel the same thing as the Java Plug-in Control Panel? I only have the JCP. Could that be the problem? I also get a message in other areas that scripting is not enabled. Is this all related?
Thought I should add this to further explain what is happening ... Hope you can help!
Java Plug-in 1.5.0_06
Using JRE version 1.5.0_06 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Compaq_Owner
network: Loading user-defined proxy configuration ...
network: Done.
network: Loading proxy configuration from Internet Explorer ...
network: Done.
network: Loading direct proxy configuration ...
network: Done.
network: Proxy Configuration: No proxy
basic: Cache is enabled
basic: Location: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\cache\javapi\v1.0
basic: Maximum size: unlimited
basic: Compression level: 0
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
p: reload proxy configuration
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>
basic: Registered modality listener
liveconnect: Invoking JS method: document
liveconnect: Invoking JS method: URL
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@f73c1, refcount=1
basic: Added progress listener: sun.plugin.util.GrayBoxPainter@19a0c7c
basic: Loading applet ...
basic: Initializing applet ...
basic: Starting applet ...
network: Connecting http://www.java.com/applet/testvm.class with proxy=DIRECT
network: Connecting http://www.java.com/applet/testvm.class with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/applet/testvm.class from cache
TestVM 3.1 kc
Copyright (c) 2005 Sun Microsystems, Inc.
All Rights Reserved.
basic: Loaded image: http://www.java.com/en/img/download/t1.gif
basic: Loaded image: http://www.java.com/en/img/download/t2.gif
basic: Loaded image: http://www.java.com/en/img/download/t3.gif
basic: Loaded image: http://www.java.com/en/img/download/t4.gif
basic: Loaded image: http://www.java.com/en/img/download/t5.gif
basic: Loaded image: http://www.java.com/en/img/download/t6.gif
basic: Loaded image: http://www.java.com/en/img/download/t7.gif
network: Connecting http://www.java.com/en/img/download/t1.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t1.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t1.gif from cache
network: Connecting http://www.java.com/en/img/download/t2.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t2.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t2.gif from cache
network: Connecting http://www.java.com/en/img/download/t3.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t3.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t3.gif from cache
network: Connecting http://www.java.com/en/img/download/t4.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t4.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t4.gif from cache
network: Connecting http://www.java.com/en/img/download/t5.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t5.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t5.gif from cache
network: Connecting http://www.java.com/en/img/download/t6.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t6.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t6.gif from cache
network: Connecting http://www.java.com/en/img/download/t7.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t7.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t7.gif from cache
basic: Stopping applet ...
basic: Removed progress listener: sun.plugin.util.GrayBoxPainter@19a0c7c
basic: Finding information ...
basic: Releasing classloader: sun.plugin.ClassLoaderInfo@f73c1, refcount=0
basic: Caching classloader: sun.plugin.ClassLoaderInfo@f73c1
basic: Current classloader cache size: 1
basic: Done ...
basic: Joining applet thread ...
basic: Destroying applet ...
basic: Disposing applet ...
basic: Quiting applet ...
basic: Joined applet thread ...
basic: Unregistered modality listener
basic: unique id: com_sun_deploy_AboutJava-1.5.0
basic: server port at: 2309
basic: getSingleInstanceFilename: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2309
basic: waiting connection
network: Connecting socket://127.0.0.1:2309 with proxy=DIRECT
basic: recv: javaws.singleinstance.stop
basic: getSingleInstanceFilename: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2309
basic: getSingleInstanceFilename: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2309
basic: removed SingleInstanceFile: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2309
basic: Registered modality listener
liveconnect: Invoking JS method: document
liveconnect: Invoking JS method: URL
basic: Referencing classloader: sun.plugin.ClassLoaderInfo@f73c1, refcount=1
basic: Added progress listener: sun.plugin.util.GrayBoxPainter@1e228bc
basic: Loading applet ...
basic: Initializing applet ...
basic: Starting applet ...
TestVM 3.1 kc
Copyright (c) 2005 Sun Microsystems, Inc.
All Rights Reserved.
basic: Loaded image: http://www.java.com/en/img/download/t1.gif
basic: Loaded image: http://www.java.com/en/img/download/t2.gif
basic: Loaded image: http://www.java.com/en/img/download/t3.gif
basic: Loaded image: http://www.java.com/en/img/download/t4.gif
basic: Loaded image: http://www.java.com/en/img/download/t5.gif
basic: Loaded image: http://www.java.com/en/img/download/t6.gif
basic: Loaded image: http://www.java.com/en/img/download/t7.gif
network: Connecting http://www.java.com/en/img/download/t1.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t1.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t1.gif from cache
network: Connecting http://www.java.com/en/img/download/t2.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t2.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t2.gif from cache
network: Connecting http://www.java.com/en/img/download/t3.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t3.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t3.gif from cache
network: Connecting http://www.java.com/en/img/download/t4.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t4.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t4.gif from cache
network: Connecting http://www.java.com/en/img/download/t5.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t5.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t5.gif from cache
network: Connecting http://www.java.com/en/img/download/t6.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t6.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t6.gif from cache
network: Connecting http://www.java.com/en/img/download/t7.gif with proxy=DIRECT
network: Connecting http://www.java.com/en/img/download/t7.gif with cookie "JSESSIONID=E4C78C2C09A916295DDBD9EAEE101C10.tomcat4; s_cc=true; s_sq"
basic: Loading http://www.java.com/en/img/download/t7.gif from cache
basic: unique id: com_sun_deploy_AboutJava-1.5.0
basic: server port at: 2335
basic: getSingleInstanceFilename: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2335
basic: waiting connection
basic: Modality pushed
network: Connecting socket://127.0.0.1:2335 with proxy=DIRECT
basic: Modality popped
basic: recv: javaws.singleinstance.stop
basic: getSingleInstanceFilename: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2335
basic: getSingleInstanceFilename: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2335
basic: removed SingleInstanceFile: C:\Documents and Settings\Compaq_Owner\Application Data\Sun\Java\Deployment\tmp\si\com_sun_deploy_AboutJava-1.5.0_2335 -
Set MenuBar component margin sizes
Hello everyone,
I use mx:MenuBar component in my application. I'm gonna create an options window for my search button. I'll set options for search property.
as you see in the image, I couldn't set the size near the arrow down character(v). Also could'n not set the blue color. I checked all properties and style options but not found any solution to set these.
Please any idea about this issue or any other solution to mysettings window solution.For those that are interested, I was able to find a solution. I manually set my margins to 0.5" all around. Here is a snippet below:
PrinterJob job = PrinterJob.getPrinterJob( );
PageFormat format = job.defaultPage( );
Paper paper = new Paper();
double margin = 36; //72 is the default which equals to an inch
paper.setImageableArea( margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2 );
format.setPaper( paper );
job.setPrintable( this, format );
I hope that helps. -
Set Java 1.6 applet memory
I posted this on the Safari board but it might get a quicker answer here.
The latest Java control panel no longer allows users to set applet memory. Apple has posted a workaround for those using JRE 1.5 <http://support.apple.com/kb/HT3210>. Is there a similar workaround for those use JRE 1.6?On further testing it seems the Safari applet always uses JRE 1.5. I guess this is because JRE 1.6 is 64 bit and Safari is 32 bit. Anyway there is no need to alter the JRE1.6 applet parameters
-
Look&Feel setting partially effective in applet, why?
I have set the applet look&feel in method init() by doing this.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeel());There are a JTree in a JScrollPane and some JButtons on the Applet.
But when browsed by IE, the tree is displayed in a Windows style, but the
buttons and outside the JScrollPane are all in a Metal style. Why this happens?
And how to solve it? Thanks.I have find many questions in the forum like mine, but they are not the same.
And I find that this kind of questions are very common, can anybody give a total
solution? Maybe everyone is tired of replying this. And is there any tech FAQs
in the forum? -
Why do Java teachers set problems requiring an Applet solution?
Applets are very hard to debug, they have a slow development cycle, Web caches cause problems and the security restrictions limit what can be achieved.
My guess is because there's a fear of the command
line. I'll bet those same teachers tend to make
their students use IDEs as well.Part of the problem is that most courses are too short to get into some of these things. There is such a spectrim of things to try and teach to people in such a short amount of time. Personally I would actually prefer to see the first course be a logic course complete with flow charts. The language is much easier to pick up than the algorithms, and I also suspect it would be easier to pick up a language when they realize how linear computers really are.
>
Or maybe they think an applet will feel more "real"
to the students because it's contained in a browser,
which is an application they recognize. -
I know that it is not allowed programmatically but what is syntex of the command to set max jvm. Which class name muste given in the command. I tried :
java -Xmx128m
if I write just like that, a screen shows as I write -help.
Thank youI suspect you can't
anything like that is restricted as it allows you
access to the system.
this prevents against the possibility overflow.
though having said that , I don't know much about native methods in JAVA. -
Does anyone know how to set policy file, so applet can connect other host?
I have an signed applet, it may connect to other host.
The applet should display a HTML pages, which may contains image tag points to a picture stored anywhere. I use a JTextPane to display this HTML page, but when it is loaded. a error occurs.
java.lang.SecurityException
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at sun.awt.image.URLImageSource.checkSecurity(Unknown Source)
at sun.awt.image.ImageRepresentation.imageComplete(Unknown Source)
at sun.awt.image.InputStreamImageSource.errorConsumer(Unknown Source)
at sun.awt.image.InputStreamImageSource.setDecoder(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
I have those kind of error (connection refused) before I signed my applet and write policy file to granr socketpermission to the codebase of my class files. But this error still occurs. I suppose it is because the sun.awt.image.* is Java standard class, so my policy file has no effect on them. But how can I make it works?you need to install the jre, and place the win32.dll at JavaSoft\JRE\1.3.1_06\bin, that properties file place at JavaSoft\JRE\1.3.1_06\lib, comm.jar at JavaSoft\JRE\1.3.1_06\lib\ext\
and in ur code try to use it to open ur com port
public String test() {
String drivername = "com.sun.comm.Win32Driver";
try
CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
catch (Throwable th)
{* Discard it */}
drivername = "javax.comm.*";
try
CommDriver driver = (CommDriver) Class.forName(drivername).newInstance(); driver.initialize();
catch (Throwable th)
{* Discard it */}
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM2")) {
//if (portId.getName().equals("/dev/term/a")) {
try {
serialPort = (SerialPort)
portId.open("SimpleWriteApp", 2000);
} catch (PortInUseException e) {}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {}
int i=0;
while(true)
try {
messageString="hi";
System.out.println(i++);
outputStream.write(messageString.getBytes());
} catch (IOException e)
System.out.println(e);
messageString=String.valueOf(e);
return messageString;
and yet u need to signed the applet
1. Compile the applet
2. Create a JAR file
3. Generate Keys
4. Sign the JAR file
5. Export the Public Key Certificate
6. Import the Certificate as a Trusted Certificate
7. Create the policy file
8. Run the applet
Susan
Susan bundles the applet executable in a JAR file, signs the JAR file, and exports the public key certificate.
1. Compile the Applet
In her working directory, Susan uses the javac command to compile the SignedAppletDemo.java class. The output from the javac command is the SignedAppletDemo.class.
javac SignedAppletDemo.java
2. Make a JAR File
Susan then makes the compiled SignedAppletDemo.class file into a JAR file. The -cvf option to the jar command creates a new archive (c), using verbose mode (v), and specifies the archive file name (f). The archive file name is SignedApplet.jar.
jar cvf SignedApplet.jar SignedAppletDemo.class
3. Generate Keys
Susan creates a keystore database named susanstore that has an entry for a newly generated public and private key pair with the public key in a certificate. A JAR file is signed with the private key of the creator of the JAR file and the signature is verified by the recipient of the JAR file with the public key in the pair. The certificate is a statement from the owner of the private key that the public key in the pair has a particular value so the person using the public key can be assured the public key is authentic. Public and private keys must already exist in the keystore database before jarsigner can be used to sign or verify the signature on a JAR file.
In her working directory, Susan creates a keystore database and generates the keys:
keytool -genkey -alias signFiles -keystore susanstore -keypass kpi135 -dname "cn=jones" -storepass ab987c
This keytool -genkey command invocation generates a key pair that is identified by the alias signFiles. Subsequent keytool command invocations use this alias and the key password (-keypass kpi135) to access the private key in the generated pair.
The generated key pair is stored in a keystore database called susanstore (-keystore susanstore) in the current directory, and accessed with the susanstore password (-storepass ab987c).
The -dname "cn=jones" option specifies an X.500 Distinguished Name with a commonName (cn) value. X.500 Distinguished Names identify entities for X.509 certificates.
You can view all keytool options and parameters by typing:
keytool -help
4. Sign the JAR File
JAR Signer is a command line tool for signing and verifying the signature on JAR files. In her working directory, Susan uses jarsigner to make a signed copy of the SignedApplet.jar file.
jarsigner -keystore susanstore -storepass ab987c -keypass kpi135 -signedjar SSignedApplet.jar SignedApplet.jar signFiles
The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.
5. Export the Public Key Certificate
The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.
The -storepass ab987c and -keystore susanstore options specify the keystore database and password where the private key for signing the JAR file is stored. The -keypass kpi135 option is the password to the private key, SSignedApplet.jar is the name of the signed JAR file, and signFiles is the alias to the private key. jarsigner extracts the certificate from the keystore whose entry is signFiles and attaches it to the generated signature of the signed JAR file.
5: Export the Public Key Certificate
The public key certificate is sent with the JAR file to the whoever is going to use the applet. That person uses the certificate to authenticate the signature on the JAR file. To send a certificate, you have to first export it.
In her working directory, Susan uses keytool to copy the certificate from susanstore to a file named SusanJones.cer as follows:
keytool -export -keystore susanstore -storepass ab987c -alias signFiles -file SusanJones.cer
Ray
Ray receives the JAR file from Susan, imports the certificate, creates a policy file granting the applet access, and runs the applet.
6. Import Certificate as a Trusted Certificate
Ray has received SSignedApplet.jar and SusanJones.cer from Susan. He puts them in his home directory. Ray must now create a keystore database (raystore) and import the certificate into it. Ray uses keytool in his home directory /home/ray to import the certificate:
keytool -import -alias susan -file SusanJones.cer -keystore raystore -storepass abcdefgh
7. Create the Policy File
The policy file grants the SSignedApplet.jar file signed by the alias susan permission to create newfile (and no other file) in the user's home directory.
Ray creates the policy file in his home directory using either policytool or an ASCII editor.
keystore "/home/ray/raystore";
// A sample policy file that lets a JavaTM program
// create newfile in user's home directory
// Satya N Dodda
grant SignedBy "susan"
permission java.security.AllPermission;
8. Run the Applet in Applet Viewer
Applet Viewer connects to the HTML documents and resources specified in the call to appletviewer, and displays the applet in its own window. To run the example, Ray copies the signed JAR file and HTML file to /home/aURL/public_html and invokes Applet viewer from his home directory as follows:
Html code :
</body>
</html>
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="600" height="400" align="middle"
codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,1,2">
<PARAM NAME="code" VALUE="SignedAppletDemo.class">
<PARAM NAME="archive" VALUE="SSignedApplet.jar">
<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
</OBJECT>
</body>
</html>
appletviewer -J-Djava.security.policy=Write.jp
http://aURL.com/SignedApplet.html
Note: Type everything on one line and put a space after Write.jp
The -J-Djava.security.policy=Write.jp option tells Applet Viewer to run the applet referenced in the SignedApplet.html file with the Write.jp policy file.
Note: The Policy file can be stored on a server and specified in the appletviewer invocation as a URL.
9. Run the Applet in Browser
Download JRE 1.3 from Javasoft
good luck! [email protected]
i already give u many tips, i use 2 weeks to try this to success, hopw that u understand that, a result of success is not important, the process of how to get things done is most usefull! -
How to set mime types for applet in iAS sp3?
Hi,
Please refer to Adding Mime types and let me know if that address to solve your problem.
Regards
Ganesh .R
Developer Technical Support
Sun Microsystems
http://www.sun.com/developers/support -
How to set the Size to an extension of an applet?
Greetings,
I have a frame that i added to ti a class that extends from applet, on this extension there are two pannels.
i want that when i resize the frame aslo the apllet will be resized. i added to the frame a compenentlistener and when the frame gets an resize event i call the setSize method of the applet with the frame's dimention, but it doesnt work. How do i do it correctly?I have not tried this yet but maybe it works:
At the applet tag set size of the applet to "100%"
and use HSPACE and WSPACE.
Don't know, if it'll work. -
How do You set -noverify in an HTML page that calls an applet
I have an applet which runs fine from inside JBuilder when I specify a
-noverify switch in the debugger. (java -noverify myapplet.class)
Without this switch, I get a verification exception.
So I need to specify the -noverify switch from inside a webpage so that when the client runs it, he does not get the same exception.
The question is how do you pass -noverify to JVM from an HTML page that uses <applet> tag and javascript?
ThanksOdd, because I work on an applet that gets built with 1.4. We have 30,000+ clients who use it every day, and I'm sure we don't tell them about setting -noverify switches in their plug-in control panel, and we don't (cuz we can't) set it in the applet (object/embed, actually) tag.
Of course, I suppose it could be a backwards compatibility issue going from compiling in newer version than it's run in. -
Setting properties to applets...
hi This is a new comer to developing applets.
Can i set properties to an applet? i mean i have an applet running and for that applet the user shoud be able to right clik on it and see set of properties scroll down like change font color etc.....how can i make it possible.
I'd appreciate if anybody can help me with some links so that i can get to work more on it or some sample code.
Thanks in advance..hai
hope the below link find some solution
rajesh
http://java.sun.com/docs/books/tutorial/uiswing/components/list.html -
Errors running converted application (from applet)
I've converted some codes (applet) into an application. When I run the application, I can see the GUI, but the application reports error as follows:
Exception occurred during event dispatching:
java.lang.NullPointerException
at swarmCanvas.paint(Swarm.java:192)
at sun.awt.RepaintArea.paint(RepaintArea.java:298)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:196)
at java.awt.Component.dispatchEventImpl(Component.java:2663)
at java.awt.Component.dispatchEvent(Component.java:2497)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
What I see is only the GUI less the animation that occurs when it was an applet. Could anyone offer me any suggestions or help? Thanks a lot.Here's my codes, many thanks:
* Swarm.class
* This is the major class of the swarm animation. The Swarm class is
* responsible for initialising and coordinating the Flock, swarmCanvas,
* and swarmPanel classes.
* @see Flock.class
* @see Bird.class
* @see Barrier.class
* @author Duncan Crombie
* @version 2.02, 20 September 1997
import java.awt.*;
public class Swarm extends java.applet.Applet implements Runnable {
Thread animator; // animation thread
swarmCanvas arena; // display canvas
swarmPanel controls; // control panel
static int NUMBLUE = 15, NUMRED = 5, MAXPOP = 20;
static double SPEED = 5.0;
static int TURN = 15, MINDIST = 30, MAXDIST = 60;
boolean paused = false;
public void init() { // initialise applet components
arena = new swarmCanvas();
controls = new swarmPanel(NUMBLUE, NUMRED, MAXPOP);
setLayout(new BorderLayout());
add("Center", arena); // add canvas to applet at 'Center'
add("South", controls); // add panel to applet at 'South'
arena.requestFocus();
public void start() { // start thread when applet starts
if (animator == null) {
animator = new Thread(this);
animator.start();
public void stop() { // stop thread when applet stops
if (animator != null) {
animator.stop();
animator = null;
public void run() {
boolean flocking = false;
while (true) {
if (!flocking && arena.unpacked) { // once canvas component is unpacked
Bird.setBoundaries(arena.w, arena.h); // set swarm boundaries
arena.flock = new Flock(NUMBLUE, NUMRED, SPEED, TURN, MINDIST, MAXDIST);
flocking = true;
} else if (flocking) {
Bird.setBoundaries(arena.w, arena.h);
if (!paused)
arena.flock.move(); // animate the flock
arena.repaint(); // update display
try {
Thread.sleep(20); // interval between steps
} catch (InterruptedException e) {}
public boolean handleEvent(Event ev) { // check for control panel actions
if (ev.id == Event.ACTION_EVENT && ev.target == controls.reset) {
resetApplet(); // reset button pressed in controls
return true;
if (ev.id == Event.ACTION_EVENT && ev.target == controls.pause) {
paused = !paused; // toggle paused status
controls.pause.setLabel((paused) ? "Continue" : "Pause");
return true;
if (ev.target == controls.sbRed) {
if (ev.id == Event.SCROLL_LINE_UP)
arena.flock.removeBird(Color.red); // remove a red Bird from flock
else if (ev.id == Event.SCROLL_LINE_DOWN)
arena.flock.addBird(new Bird(Color.red)); // add a red Bird
return true;
if (ev.target == controls.sbBlue) {
if (ev.id == Event.SCROLL_LINE_UP)
arena.flock.removeBird(Color.blue); // remove a blue Bird from flock
else if (ev.id == Event.SCROLL_LINE_DOWN)
arena.flock.addBird(new Bird(Color.blue)); // add a blue Bird
return true;
return super.handleEvent(ev); // pass on unprocessed events
public boolean keyDown(Event e, int x) { // check for key press
boolean shiftKeyDown = ((e.modifiers & Event.SHIFT_MASK) != 0);
if (shiftKeyDown) {
if (x == Event.DOWN) Flock.minDISTANCE -= 5; // less separation
if (x == Event.UP) Flock.minDISTANCE += 5; // more separation
if (x == Event.LEFT) Flock.maxDISTANCE -= 5; // lower detection
if (x == Event.RIGHT) Flock.maxDISTANCE += 5; // higher detection
Barrier.minRANGE = Flock.minDISTANCE;
Barrier.maxRANGE = Flock.maxDISTANCE;
} else {
if (x == Event.DOWN) Bird.maxSPEED -= 1.0; // slower
if (x == Event.UP) Bird.maxSPEED += 1.0; // faster
if (x == Event.LEFT) Bird.maxTURN -= 5; // less turning
if (x == Event.RIGHT) Bird.maxTURN += 5; // more turning
return true; // all key events handled
public void resetApplet() {
arena.flock = new Flock(NUMBLUE, NUMRED, SPEED, TURN, MINDIST, MAXDIST);
controls.sbBlue.setValue(NUMBLUE); // initialise scrollbars
controls.sbRed.setValue(NUMRED);
* swarmPanel.class
* A Panel holding two scrollbars and two buttons for controlling the
* Swarm applet.
* @see Swarm.class
* @author Duncan Crombie
* @version 2.01, 20 September 1997
class swarmPanel extends Panel { // class defines applet control panel
Button reset, pause;
Scrollbar sbBlue = new Scrollbar(Scrollbar.HORIZONTAL);
Scrollbar sbRed = new Scrollbar(Scrollbar.HORIZONTAL);
Label label1, label2;
* The construction method creates and adds control panel components
swarmPanel(int numRed, int numBlue, int maxBoid) {
setLayout(new GridLayout(2, 3)); // define 2 x 3 grid layout for controls
label1 = new Label("Blue #");
label1.setFont(new Font("Dialog", Font.PLAIN, 12)); add(label1);
label2 = new Label("Red #");
label2.setFont(new Font("Dialog", Font.PLAIN, 12)); add(label2);
reset = new Button("Reset"); add(reset);
sbBlue.setValues(numRed, 1, 0, maxBoid);
add(sbBlue);
sbRed.setValues(numBlue, 1, 0, maxBoid);
add(sbRed);
pause = new Button("Pause");
add(pause);
* swarmCanvas.class
* A Canvas for displaying the Flock and Swarm parameters.
* @see Swarm.class
* @author Duncan Crombie
* @version 2.01, 20 September 1997
class swarmCanvas extends Canvas {
Flock flock;
Image offScrImg;
boolean unpacked = false;
int w, h;
/* Double buffered graphics */
public void update(Graphics g) {
if (offScrImg == null || offScrImg.getWidth(this) != w || offScrImg.getHeight(this) != h)
offScrImg = createImage(w, h);
Graphics og = offScrImg.getGraphics();
paint(og);
g.drawImage(offScrImg, 0, 0, this);
og.dispose();
public void paint(Graphics g) {
Dimension d = this.preferredSize();
if (!unpacked) {
this.w = d.width;
this.h = d.height;
unpacked = true;
g.setColor(Color.white);
g.fillRect(0, 0, w, h); // draw white background
g.setColor(Color.black); // set font and write applet parameters
g.setFont(new Font("Dialog", Font.PLAIN, 10));
g.drawString("Bird Speed: " + Bird.maxSPEED, 10, 15);
g.drawString("Bird Turning: " + Bird.maxTURN, 10, 30);
g.drawString("Minimum Distance: " + Flock.minDISTANCE, 10, 45);
g.drawString("Maximum Distance: " + Flock.maxDISTANCE, 10, 60);
flock.display(g); // draw Flock members
if (this.w != d.width || this.h != d.height)
unpacked = false;
public boolean mouseDown(Event ev, int x, int y) {
int radius = Barrier.maxRANGE;
boolean top, bottom;
flock.addBird(new Barrier(x, y)); // place Barrier at click coordinates
top = (y < radius);
bottom = (y > h-radius);
if (x < radius) { // if left
flock.addBird(new Barrier(w + x, y));
if (top) flock.addBird(new Barrier(w + x, h + y));
else if (bottom) flock.addBird(new Barrier(w + x, y - h));
} else if (x > w-radius) { // if right
flock.addBird(new Barrier(x - w, y));
if (top) flock.addBird(new Barrier(x - w, h + y));
else if (bottom) flock.addBird(new Barrier(x - w, y - h));
if (top) flock.addBird(new Barrier(x, h + y));
else if (bottom) flock.addBird(new Barrier(x, y - h));
return true;
===================================================================
* Bird.class
* This class defines the appearance and behaviour of a Bird object.
* @see Swarm.class
* @see Flock.class
* @see Barrier.class
* @author Duncan Crombie
* @version 2.02, 21 September 1997
import java.awt.*;
class Bird {
int iX, iY, iTheta;
Color cFeathers;
static int arenaWIDTH, arenaHEIGHT; // canvas dimensions
static double maxSPEED; // speed of Bird
static int maxTURN; // maximum turn in degrees
Bird(int x, int y, int theta, Color feath) {
iX = x;
iY = y;
iTheta = theta;
cFeathers = feath;
Bird(Color feath) {
this((int)(Math.random() * arenaWIDTH),
(int)(Math.random() * arenaHEIGHT),
(int)(Math.random() * 360),
feath);
public void move(int iHeading) {
int iChange = 0;
int left = (iHeading - iTheta + 360) % 360;
int right = (iTheta - iHeading + 360) % 360;
if (left < right)
iChange = Math.min(maxTURN, left);
else
iChange = -Math.min(maxTURN, right);
iTheta = (iTheta + iChange + 360) % 360;
iX += (int)(maxSPEED * Math.cos(iTheta * Math.PI/180)) + arenaWIDTH;
iX %= arenaWIDTH;
iY -= (int)(maxSPEED * Math.sin(iTheta * Math.PI/180)) - arenaHEIGHT;
iY %= arenaHEIGHT;
public void display(Graphics g) { // draw Bird as a filled arc
g.setColor(this.cFeathers);
g.fillArc(iX - 12, iY - 12, 24, 24, iTheta + 180 - 15, 30);
public int getDistance(Bird bOther) {
int dX = bOther.getPosition().x-iX;
int dY = bOther.getPosition().y-iY;
return (int)Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2));
static void setBoundaries(int w, int h) {
arenaWIDTH = w;
arenaHEIGHT = h;
public int getTheta() {
return iTheta;
public Point getPosition() {
return new Point(iX, iY);
public Color getFeathers() {
return cFeathers;
=================================================================
* Flock.class
* This class creates and coordinates the movement of a flock of Birds.
* @see Swarm.class
* @see Bird.class
* @see Barrier.class
* @author Duncan Crombie
* @version 2.02, 21 September 1997
import java.util.Vector;
import java.awt.*;
class Flock { // implement swarming algorithm on flock of birds
private Vector vBirds;
static int minDISTANCE, maxDISTANCE;
Flock(int nBlue, int nRed, double speed, int turn, int minDist, int maxDist) {
vBirds = new Vector(5, 5);
for (int i=0; i < nBlue + nRed; i++)
addBird(new Bird((i < nBlue) ? Color.blue : Color.red));
Bird.maxSPEED = speed;
Bird.maxTURN = turn;
Barrier.minRANGE = minDISTANCE = minDist;
Barrier.maxRANGE = maxDISTANCE = maxDist;
public void addBird(Bird bird) { // add Bird to vector
vBirds.addElement(bird);
synchronized void removeBird(Color col) { // remove Bird from vector
for (int i=0; i < vBirds.size(); i++) { // loop through vector of Birds
Bird bTemp = (Bird)vBirds.elementAt(i);
if (bTemp.getFeathers() == col) { // search for Bird of given colour
vBirds.removeElementAt(i); // if found, remove Bird..
break; // ..and stop searching
* The move function simply tells each Bird in the Vector vBirds to move
* according to the resultant Point of generalHeading.
synchronized public void move() {
for (int i=0; i < vBirds.size(); i++) {
Bird bTemp = (Bird)vBirds.elementAt(i);
bTemp.move(generalHeading(bTemp));
* The display function simply draws each Bird in the Vector vBirds at its
* current position.
public void display(Graphics g) { // display each Bird in flock
for (int i=0; i < vBirds.size(); i++) {
Bird bTemp = (Bird)vBirds.elementAt(i);
bTemp.display(g);
public Point sumPoints(Point p1, double w1, Point p2, double w2) {
return new Point((int)(w1*p1.x + w2*p2.x), (int)(w1*p1.y + w2*p2.y));
public double sizeOfPoint(Point p) {
return Math.sqrt(Math.pow(p.x, 2) + Math.pow(p.y, 2));
public Point normalisePoint(Point p, double n) {
if (sizeOfPoint(p) == 0.0) return p;
else {
double weight = n / sizeOfPoint(p);
return new Point((int)(p.x * weight), (int)(p.y * weight));
* The generalHeading function determines the point a Bird will turn towards
* in the next timestep. The Bird b checks for all Birds (other than self)
* that fall within the detection range. If the Bird is of a different colour
* or closer than the separation distance then they are repulsed else the
* Birds are attracted according to the flocking algorithm.
private int generalHeading(Bird b) {
if (b instanceof Barrier) return 0;
Point pTarget = new Point(0, 0);
int numBirds = 0; // total of Birds to average
for (int i=0; i < vBirds.size(); i++) { // for each Bird in array
Bird bTemp = (Bird)vBirds.elementAt(i); // retrieve element i
int distance = b.getDistance(bTemp); // get distance to Bird
if (!b.equals(bTemp) && distance > 0 && distance <= maxDISTANCE) {
* If the neighbour is a sibling the algorithm tells the boid to align its
* direction with the other Bird. If the distance between them differs from
* minDISTANCE then a weighted forces is applied to move it towards that
* distance. This force is stronger when the boids are very close or towards
* the limit of detection.
if (b.getFeathers().equals(bTemp.getFeathers())) { // if same colour
Point pAlign = new Point((int)(100 * Math.cos(bTemp.getTheta() * Math.PI/180)), (int)(-100 * Math.sin(bTemp.getTheta() * Math.PI/180)));
pAlign = normalisePoint(pAlign, 100); // alignment weight is 100
boolean tooClose = (distance < minDISTANCE);
double weight = 200.0;
if (tooClose) weight *= Math.pow(1 - (double)distance/minDISTANCE, 2);
else weight *= - Math.pow((double)(distance-minDISTANCE) / (maxDISTANCE-minDISTANCE), 2);
Point pAttract = sumPoints(bTemp.getPosition(), -1.0, b.getPosition(), 1.0);
pAttract = normalisePoint(pAttract, weight); // weight is variable
Point pDist = sumPoints(pAlign, 1.0, pAttract, 1.0);
pDist = normalisePoint(pDist, 100); // final weight is 100
pTarget = sumPoints(pTarget, 1.0, pDist, 1.0);
* In repulsion the target point moves away from the other Bird with a force
* that is weighted according to a distance squared rule.
else { // repulsion
Point pDist = sumPoints(b.getPosition(), 1.0, bTemp.getPosition(), -1.0);
pDist = normalisePoint(pDist, 1000);
double weight = Math.pow((1 - (double)distance/maxDISTANCE), 2);
pTarget = sumPoints(pTarget, 1.0, pDist, weight); // weight is variable
numBirds++;
if (numBirds == 0) return b.getTheta();
else // average target points and add to position
pTarget = sumPoints(b.getPosition(), 1.0, pTarget, 1/(double)numBirds);
int targetTheta = (int)(180/Math.PI * Math.atan2(b.getPosition().y - pTarget.y, pTarget.x - b.getPosition().x));
return (targetTheta + 360) % 360; // angle for Bird to steer towards
======================================================================
* Barrier.class
* This class creates and coordinates the movement of a flock of Birds.
* @see Swarm.class
* @see Flock.class
* @see Bird.class
* @author Duncan Crombie
* @version 2.01, 21 September 1997
import java.awt.*;
class Barrier extends Bird {
static int minRANGE, maxRANGE;
Barrier(int x, int y) {
super(x, y, 0, Color.black); // position Barrier and define color as black
public void move(int dummy) {
// do nothing
public void display(Graphics g) { // paint Barrier
g.setColor(Color.black);
g.fillOval(this.iX-5, this.iY-5, 10, 10);
g.setColor(Color.gray); // paint separation circle
g.drawOval(this.iX-minRANGE, this.iY-minRANGE, 2*minRANGE, 2*minRANGE);
g.setColor(Color.lightGray); // paint detection circle
g.drawOval(this.iX-maxRANGE, this.iY-maxRANGE, 2*maxRANGE, 2*maxRANGE);
=====================================================================
import java.awt.*;
import java.awt.event.*;
public class SwarmFrame extends Frame implements ActionListener {
public SwarmFrame() {
super("Flocking Bird");
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu fileMenu = new Menu("File");
mb.add(fileMenu);
MenuItem exitMenuItem = new MenuItem("Exit");
fileMenu.add(exitMenuItem);
exitMenuItem.addActionListener(this);
Swarm swarmApplet = new Swarm();
add(swarmApplet, BorderLayout.CENTER);
swarmApplet.init();
public void actionPerformed(ActionEvent evt) {
if(evt.getSource() instanceof MenuItem) {
String menuLabel = ((MenuItem) evt.getSource()).getLabel();
if(menuLabel.equals("Exit")) {
dispose();
System.exit(0);
=====================================================================
import java.awt.*;
public class SwarmApplication {
public static void main(String[] args) {
Frame frame = new SwarmFrame();
frame.setBounds(10, 10, 600, 400);
frame.setVisible(true);
Maybe you are looking for
-
Hi. How i can suppress the applet view status bar when deploying form6i on Web. Thanks. null
-
Hide cell in alv-grid on certain rows
Hi all, I wonder if it is possible to hide certain cells in an ALV-grid ? e.g the data in cell1 row1 is visible, but the data in cell1 on row2 has to be invisible...
-
Using vb.net in Business One SDK is there a variable from which the user internal-key can be established ?
-
How many times was a specific function module triggered?
Hi, is there a transaction in SAP where i can get some information about function modules "how many times is a function module triggered". regards
-
Is there a way to pull images from an slideshow?
how do i pull images from a slideshow and bring them back to normal iphoto album?