JApplet

How to use package key in JApplet to include another program function, please replay if any body knows

Not sure about anyone else, but I can't understand your question.

Similar Messages

  • Need to convert JApplet to JFrame

    I need to write code for where I have 60 balls bouncing around inside a window. The client will then be able to select a button and it will pull out a ball with the number 1-60 written on it. The user will be able to do this up to 7 times. Each time it is done the past numbers that have already appeared can not reappear. What I am stuck on right now is geting my balls into a JFrame. Can anyone give advice or show how to. I currently have my 60 balls running in a JApplet. Here is the JAVA code and the HTML code. Thanks!
    Here is the JAVA code
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import javax.swing.*;
    class CollideBall{
    int width, height;
    public static final int diameter=20;
    //coordinates and value of increment
    double x, y, xinc, yinc, coll_x, coll_y;
    boolean collide;
    Color color;
    Graphics g;
    Rectangle r;
    //the constructor
    public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c){
    width=w;
    height=h;
    this.x=x;
    this.y=y;
    this.xinc=xinc;
    this.yinc=yinc;
    color=c;
    r=new Rectangle(150,80,130,90);
    public double getCenterX() {return x+diameter/2;}
    public double getCenterY() {return y+diameter/2;}
    public void alterRect(int x, int y, int w, int h){
    r.setLocation(x,y);
    r.setSize(w,h);
    public void move(){
    if (collide){  
    double xvect=coll_x-getCenterX();
    double yvect=coll_y-getCenterY();
    if((xinc>0 && xvect>0) || (xinc<0 && xvect<0))
    xinc=-xinc;
    if((yinc>0 && yvect>0) || (yinc<0 && yvect<0))
    yinc=-yinc;
    collide=false;
    x+=xinc;
    y+=yinc;
    //when the ball bumps against a boundary, it bounces off
    if(x<6 || x>width-diameter){
    xinc=-xinc;
    x+=xinc;
    if(y<6 || y>height-diameter){
    yinc=-yinc;
    y+=yinc;
    //cast ball coordinates to integers
    int x=(int)this.x;
    int y=(int)this.y;
    //bounce off the obstacle
    //left border
    if(x>r.x-diameter&&x<r.x-diameter+7&&xinc>0&&y>r.y-diameter&&y<r.y+r.height){
    xinc=-xinc;
    x+=xinc;
    //right border
    if(x<r.x+r.width&&x>r.x+r.width-7&&xinc<0&&y>r.y-diameter&&y<r.y+r.height){
    xinc=-xinc;
    x+=xinc;
    //upper border
    if(y>r.y-diameter&&y<r.y-diameter+7&&yinc>0&&x>r.x-diameter&&x<r.x+r.width){
    yinc=-yinc;
    y+=yinc;
    //bottom border
    if(y<r.y+r.height&&y>r.y+r.height-7&&yinc<0&&x>r.x-diameter&&x<r.x+r.width){
    yinc=-yinc;
    y+=yinc;
    public void hit(CollideBall b){
    if(!collide){
    coll_x=b.getCenterX();
    coll_y=b.getCenterY();
    collide=true;
    public void paint(Graphics gr){
    g=gr;
    g.setColor(color);
    //the coordinates in fillOval have to be int, so we cast
    //explicitly from double to int
    g.fillOval((int)x,(int)y,diameter,diameter);
    g.setColor(Color.white);
    g.drawArc((int)x,(int)y,diameter,diameter,45,180);
    g.setColor(Color.darkGray);
    g.drawArc((int)x,(int)y,diameter,diameter,225,180);
    public class BouncingBalls extends Applet implements Runnable {
    Thread runner;
    Image Buffer;
    Graphics gBuffer;
    CollideBall ball[];
    //Obstacle o;
    //how many balls?
    static final int MAX=60;
    boolean intro=true,drag,shiftW,shiftN,shiftE,shiftS;
    boolean shiftNW,shiftSW,shiftNE,shiftSE;
    int xtemp,ytemp,startx,starty;
    int west, north, east, south;
    public void init() {  
    Buffer=createImage(getSize().width,getSize().height);
    gBuffer=Buffer.getGraphics();
    ball=new CollideBall[MAX];
    int w=getSize().width-5;
    int h=getSize().height-5;
    //our balls have different start coordinates, increment values
    //(speed, direction) and colors
    for (int i = 0;i<60;i++){
    ball=new CollideBall(w,h,50+i,20+i,1.5,2.0,Color.white);
    /* ball[1]=new CollideBall(w,h,60,210,2.0,-3.0,Color.red);
    ball[2]=new CollideBall(w,h,15,70,-2.0,-2.5,Color.pink);
    ball[3]=new CollideBall(w,h,150,30,-2.7,-2.0,Color.cyan);
    ball[4]=new CollideBall(w,h,210,30,2.2,-3.5,Color.magenta);
    ball[5]=new CollideBall(w,h,360,170,2.2,-1.5,Color.yellow);
    ball[6]=new CollideBall(w,h,210,180,-1.2,-2.5,Color.blue);
    ball[7]=new CollideBall(w,h,330,30,-2.2,-1.8,Color.green);
    ball[8]=new CollideBall(w,h,180,220,-2.2,-1.8,Color.black);
    ball[9]=new CollideBall(w,h,330,130,-2.2,-1.8,Color.gray);
    ball[10]=new CollideBall(w,h,330,10,-2.1,-2.0,Color.gray);
    ball[11]=new CollideBall(w,h,220,230,-1.2,-1.8,Color.gray);
    ball[12]=new CollideBall(w,h,230,60,-2.3,-2.5,Color.gray);
    ball[13]=new CollideBall(w,h,320,230,-2.2,-1.8,Color.gray);
    ball[14]=new CollideBall(w,h,130,300,-2.7,-3.0,Color.gray);
    ball[15]=new CollideBall(w,h,210,90,-2.0,-1.8,Color.gray);*/
    public void start(){
    if (runner == null) {
    runner = new Thread (this);
    runner.start();
    /* public void stop(){
    if (runner != null) {
    runner.stop();
    runner = null;
    public void run(){
    while(true) {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    try {runner.sleep(15);}
    catch (Exception e) { }
    //move our balls around
    for(int i=0;i<MAX;i++)
    ball[i].move();
    handleCollision();
    repaint();
    boolean collide(CollideBall b1, CollideBall b2){
    double wx=b1.getCenterX()-b2.getCenterX();
    double wy=b1.getCenterY()-b2.getCenterY();
    //we calculate the distance between the centers two
    //colliding balls (theorem of Pythagoras)
    double distance=Math.sqrt(wx*wx+wy*wy);
    if(distance<b1.diameter)
    return true;
    return false;
    private void handleCollision()
    //we iterate through all the balls, checking for collision
    for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++)
    if(i!=j)
    if(collide(ball[i], ball[j]))
    ball[i].hit(ball[j]);
    ball[j].hit(ball[i]);
    public void update(Graphics g)
    paint(g);
    public void paint(Graphics g)
    gBuffer.setColor(Color.lightGray);
    gBuffer.fillRect(0,0,getSize().width,getSize().height);
    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
    //paint our balls
    for(int i=0;i<MAX;i++)
    ball[i].paint(gBuffer);
    g.drawImage (Buffer,0,0, this);
    Here is the HTML code
    <html>
    <body bgcolor="gray">
    <br><br>
    <div align="center">
    <applet code="BouncingBalls.class" width="1000" height="650"></applet>
    </div>
    </body>
    </html>

    In the future, Swing related questions should be posted in the Swing forum.
    First you need to convert your custom painting. This is done by overriding the paintComponent() method of JComponent or JPanel. Read the Swing tutorial on [Custom Painting|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html].
    If you need further help then you need to create a [Short, Self Contained, Compilable and Executable, Example Program (SSCCE)|http://homepage1.nifty.com/algafield/sscce.html], that demonstrates the incorrect behaviour.
    Don't forget to use the [Code Formatting Tags|http://forum.java.sun.com/help.jspa?sec=formatting], so the posted code retains its original formatting.

  • How to update a JPanel in a JApplet

    Hi All,
    I'm trying to make my own sudoku JApplet. JApplet uses a BorderLayout() adding the sudoku Puzzle in the center, JButtons for New Games in a JPanel in the west and a GridLayout(3,3) to select the number to put in the puzzle in the east.
    The problem is: how can i update the sudoku puzzle in the center by clicking the "new game" JButton in the west?
    I use JButtons to represent numbers in the puzzle. this is how i create the JButton and set its ActionListener().
         public static JButton casella(String[] casella) {
              final JButton b = new JButton(casella[0]);
              b.setFont(new Font("SansSerif",Font.BOLD,33));
              if(casella[3].equals("1"))
                   b.setBorder(BorderFactory.createLineBorder(Color.orange));
              if(casella[3].equals("2"))
                   b.setBorder(BorderFactory.createLineBorder(Color.red));
              else
                   b.setBorder(BorderFactory.createLineBorder(Color.black));
              b.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        if(Sudoku.NUMERO_CORRENTE>=0)
                             b.setText(String.valueOf(Sudoku.NUMERO_CORRENTE));
                        else
                             b.setText("_");
              return b;
         }this is the main class:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Sudoku extends JApplet {
         static String[][][] MATRICE = MatriceCompleta.sudoku().getArrayMatrice();
         static JPanel PANNELLO_NUMERICO = OggettiGrafici.pannelloNumerico();
         static JPanel PANNELLO_EAST = new JPanel(new GridLayout(3,1));
         static JPanel PANNELLO_WEST = new JPanel(new GridLayout(6,1));
         static JPanel PANNELLO_CASELLE = new JPanel(new GridLayout(3,3));
         static JPanel PANNELLO = new JPanel(new BorderLayout());
         static int POSIZIONE_CASELLA_X = 0;
         static int POSIZIONE_CASELLA_Y = 0;
         static int NUMERO_CORRENTE = 0;
         static JLabel LABEL_NUMERO_CORRENTE = new JLabel(String.valueOf(NUMERO_CORRENTE), JLabel.CENTER);
         static JLabel LABEL_PARTITA = new JLabel("",JLabel.CENTER);
         static JLabel LABEL_NUOVA_PARTITA = new JLabel("NUOVA PARTITA",JLabel.CENTER);
         static JButton FACILE = new JButton("Livello Facile");
         static JButton NORMALE = new JButton("Livello Medio");
         static JButton DIFFICILE = new JButton("Livello Difficile");
         static JButton CONTROLLA_ERRORI = new JButton("Controlla Errori");
         static JButton CANCELLA_NUMERO = new JButton("Cancella Numero");
         static String DIFFICOLTA = "NORMALE";
         static int i, j, k;
         public void init() {
              String[][][][] divisaInPannelli = ComandiUtili.divisioneInPannelli(MATRICE);
              JPanel p0 = new JPanel(new GridBagLayout());
              JPanel p1 = new JPanel(new GridBagLayout());
              JPanel p2 = new JPanel(new GridBagLayout());
              JPanel p3 = new JPanel(new GridBagLayout());
              JPanel p4 = new JPanel(new GridBagLayout());
              JPanel p5 = new JPanel(new GridBagLayout());
              JPanel p6 = new JPanel(new GridBagLayout());
              JPanel p7 = new JPanel(new GridBagLayout());
              JPanel p8 = new JPanel(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.fill = GridBagConstraints.BOTH;
                    // creating the sudoku puzzle panel using JButtons
              for(i=0;i<9;i++) {
                   for(j=0;j<3;j++) {
                        for(k=0;k<3;k++) {
                             JButton b = OggettiGrafici.casella(divisaInPannelli[i][k][j]);
                             c.gridx = j;
                             c.gridy = k;
                             c.ipadx = 42;
                             c.ipady = 12;
                             if(i==0)
                                  p0.add(b,c);
                             else if(i==1)
                                  p1.add(b,c);
                             else if(i==2)
                                  p2.add(b,c);
                             else if(i==3)
                                  p3.add(b,c);
                             else if(i==4)
                                  p4.add(b,c);
                             else if(i==5)
                                  p5.add(b,c);
                             else if(i==6)
                                  p6.add(b,c);
                             else if(i==7)
                                  p7.add(b,c);
                             else if(i==8)
                                  p8.add(b,c);
              PANNELLO_CASELLE.add(p0);
              PANNELLO_CASELLE.add(p1);
              PANNELLO_CASELLE.add(p2);
              PANNELLO_CASELLE.add(p3);
              PANNELLO_CASELLE.add(p4);
              PANNELLO_CASELLE.add(p5);
              PANNELLO_CASELLE.add(p6);
              PANNELLO_CASELLE.add(p7);
              PANNELLO_CASELLE.add(p8);
              PANNELLO_EAST.add(PANNELLO_NUMERICO);
              PANNELLO_EAST.add(LABEL_NUMERO_CORRENTE);
              PANNELLO_EAST.add(LABEL_PARTITA);
              PANNELLO_WEST.add(LABEL_NUOVA_PARTITA);
              PANNELLO_WEST.add(FACILE);
              PANNELLO_WEST.add(NORMALE);
              PANNELLO_WEST.add(DIFFICILE);
              PANNELLO_WEST.add(CONTROLLA_ERRORI);
              PANNELLO_WEST.add(CANCELLA_NUMERO);
              PANNELLO.add(PANNELLO_CASELLE, BorderLayout.CENTER);
              PANNELLO.add(PANNELLO_EAST, BorderLayout.EAST);
              PANNELLO.add(PANNELLO_WEST, BorderLayout.WEST);
              add(PANNELLO);
         public void paint(Graphics g) {
              super.paint(g);
    }How can i update the sudoku puzzle (JPanel with 9x9 JButtons) by clicking on a "new game" JButton?
    Thank You very much in advance!

    Hi SD,
    How are you drawing the image on the JPanel?
    Are you using JLabel with image and adding it to Panel or using
    drawImage to get the image on the panel (Only jpeg and gif formats are supported here).
    DrawImage should automatically refresh, if not call repaint().
    That should refresh the Screen.
    Regards
    Chandra Mohan

  • Is correct? Application (JFrame) to Applet (JApplet)

    I need to convert a java application (JFrame) into an applet (JApplet), and I have seen a few "big steps":
    1�: make the class extends to JApplet instead of a JFrame
    2�: To replace the construction method by init ()
    3�: To comment the main method
    Is correct?, because I have some doubts that later I�ll explain
    Thanks

    I think in the init method (in a JApplet) I cannot call the super method. but my problem is how to change this? if in others files (in Files.java) I have calls to super metod, because thus it constructs a dialog box, asking for a file.
    In file Files.java I have a class called "Abort" (extends to JDialog) in whitch:
    /* class Files.java */
    class Abort extends JDialog
              boolean abort = true;
              JTextArea mensage = null;
              JButton acept = new JButton("Acept");
              JButton cancel = new JButton("Cancel");
              Abort(String nanemFile)
                   super(MainClassFile.mainWindow, " Attention!", true);
    /* clas Files.java */Please help

  • Please let me know what steps need to take to convert JApplet to JFrame

    I have an application which needs to convert from JApplet to JFrame....Please let me know what are the steps need to take for this

    I have an application which needs to convert from
    JApplet to JFrame....The topic of this forum is web-start, and it
    can be used to launch both applets and
    applications. An applet deployed using
    web-start avoids a lot of the browser related
    problems that affect 'embedded' applets.
    This leads me to..
    Please let me know what are the steps need to take for this You do not need to convert it, to launch it
    using web-start, but if you are determined to
    make it into a frame, it would be best to ask
    how to do that on a forum where the subject
    being talked about, is closer to what you are
    doing.
    For more closely related forums, try here
    http://forum.java.sun.com/category.jspa?categoryID=5
    (More the first two of the Available Forums:)

  • How to Serialize a JPanel which is inside a JApplet

    Hi..
    I have a JApplet where i have a JPanel which contains some JLabels and JTextFields,now i have to Serialize that full Panel so that i can retrived it later on with the labels and textfields placed in the same order,for that i tried serializing the full panel on to a file but it is giving me NotSerializeException,i dont know how to tackel it..
    public SaveTemplate(JPanel com) {
    try {
    ObjectOutputStream os=new ObjectOutputStream(new FileOutputStream("Temp1.temp"));
    os.writeObject(com);
    catch(Exception e) {
    e.printStackTrace();
    This is the code..plz help me with that..

    Actually its forming a Template which client will generate and that has to saved on the serverside..So what i thought that once when the client has designed a template,i can save the full template which is a panel into a file and later on when he want to open the template i just have to read the file and create an object of JPanel and add to the frame,so i dont need to apply much effort for that...But now serialization in Applet is giving problem.

  • Cannot access file from JApplet

    I have used the swingall.jar file with my JApplet for any
    version of IE. It gives one error
    i.e
    Cannot access file c:\prog\project
    I want to create a directory within c:\prog and also i want
    to write some files there. Pls help me.

    try this my friend!
    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
    save this to write.jp
    keystore "/home/ray/raystore";
    // A sample policy file that lets a JavaTM program
    // create newfile in user's home directory
    // Satya N Dodda
    grant {
    permission java.security.AllPermission;
    save this to signedAppletDemo.java
    * File: @(#)SignedAppletDemo.java     1.1
    * Comment:     Signed Applet Demo
    * @(#)author: Satya Dodda
    * @(#)version: 1.1
    * @(#)date: 98/10/01
    import java.applet.Applet;
    import java.awt.Graphics;
    import java.io.*;
    import java.awt.Color;
    * A simple Signed Applet Demo
    public class SignedAppletDemo extends Applet {
    public String test() {
    setBackground(Color.white);
         System.out.println(System.getProperty("user.home"));
         String fileName = System.getProperty("user.home") +
                        System.getProperty("file.separator") +
                        "newfile";
         String msg = "This message was written by a signed applet!!!\n";
         String s ;
         try {
         FileWriter fos = new FileWriter(fileName);
         fos.write(msg, 0, msg.length());
         fos.close();
         s = new String("Successfully created file :" + fileName);
         } catch (Exception e) {
         System.out.println("Exception e = " + e);
         e.printStackTrace();
         s = new String("Unable to create file : " + fileName);
         return s;
    public void paint(Graphics g) {
    g.setColor(Color.blue);
    g.drawString("Signed Applet Demo", 120, 50);
    g.setColor(Color.magenta);
    g.drawString(test(), 50, 100);

  • Swing layout/size problem with JFrame and JApplet.

    I have a class that extends a JFrame, the classes layout is BorderLayout. I then have a class that extend JApplet, this classes layout is GridBagLayout (this class has a JTabbedPane - which contains JPanels). The problem I'm having is no matter how big I make the size of the applet or frame (using setSize), the applet/frame stays the same size - no matter how large I make it.
    Can anyone please help?
    Thanks,
    dosteov

    Here is the basic code:
    Thanks in advance,
    dosteov
    public class EADAdm extends JApplet
    EADAdmFrame theFrame = new EADAdmFrame(this);
         public void init()
              // Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
    //          symantec.itools.lang.Context.setApplet(this);
              // This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
              getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
              // This code is automatically generated by Visual Cafe when you add
              // components to the visual environment. It instantiates and initializes
              // the components. To modify the code, only use code syntax that matches
              // what Visual Cafe can generate, or Visual Cafe may be unable to back
              // parse your Java file into its visual environment.
              //{{INIT_CONTROLS
              getContentPane().setLayout(new GridBagLayout());
              setEnabled(false);
              getContentPane().setBackground(java.awt.Color.lightGray);
              setSize(800,800);
              getContentPane().add(AdmTab, new com.symantec.itools.awt.GridBagConstraintsD(0,1,2,1,0.5,0.5,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.HORIZONTAL,new Insets(3,12,4,14),120,120));
              AdmTab.setFont(new Font("Dialog", Font.PLAIN, 12));
              titleLbl.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
              titleLbl.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
              titleLbl.setText("EAD Administration");
              getContentPane().add(titleLbl, new com.symantec.itools.awt.GridBagConstraintsD(0,0,1,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(12,36,0,0),307,15));
              titleLbl.setForeground(java.awt.Color.blue);
              titleLbl.setFont(new Font("Dialog", Font.BOLD, 15));
              exitBtn.setText("Exit EAD Administration");
              exitBtn.setActionCommand("Exit EAD Administration");
              getContentPane().add(exitBtn, new com.symantec.itools.awt.GridBagConstraintsD(0,2,2,1,0.0,0.0,java.awt.GridBagConstraints.CENTER,java.awt.GridBagConstraints.NONE,new Insets(6,371,10,14),66,8));
              exitBtn.setFont(new Font("Dialog", Font.PLAIN, 12));
         //theFrame.setVisible(false);
         login();
         AdmTab.addTab("Administration", new LogoPanel() );
         userPanel = createUserPanel();
         AdmTab.addTab("Edit Users", userPanel );
         fpoPanel = createFPOPanel();
         AdmTab.addTab("Edit FPO", fpoPanel );
         regulationPanel = createRegulationPanel();
         AdmTab.addTab("Edit Regulations", regulationPanel );
         rolloverPanel = createRolloverPanel();
         AdmTab.addTab("Rollover", rolloverPanel );           
              //{{REGISTER_LISTENERS
         SymMouse aSymMouse = new SymMouse();
              this.addMouseListener(aSymMouse);
              SymAction lSymAction = new SymAction();
              exitBtn.addActionListener(lSymAction);
              SymKey aSymKey = new SymKey();
              this.addKeyListener(aSymKey);
         theFrame.getContentPane().add(this);
    public class EADAdmFrame extends JFrame
    EADAdm theApplet;
    public EADAdmFrame(EADAdm theMainApplet)
              //{{INIT_CONTROLS
         //     theApplet = theMainApplet;
         //     this.getContentPane().add(theApplet);
              getContentPane().setLayout(new BorderLayout(0,0));
              getContentPane().setBackground(java.awt.Color.lightGray);
              setSize(1000,1000);
              setVisible(false);
         theApplet = theMainApplet;
              //{{REGISTER_LISTENERS
              SymWindow aSymWindow = new SymWindow();
              this.addWindowListener(aSymWindow);
              SymComponent aSymComponent = new SymComponent();
              this.addComponentListener(aSymComponent);

  • I can't view my JApplet in appletviewer. Why?

    I tried writing a simple program on my own and i compiled them in JPadpro 3.6. there is no error. no warnings too.
    but when i run the JApplet thr. appletviewer,
    the comments stated in the viewer was:
    Start: applet not initialized
    i can't find what's the mistake i've made in my program. can u pls help me spot it and how it should be coded?
    //------------------my tried out login program--------//
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class login extends JApplet
         //initialize
         JLabel loginTitle, loginLabel, passLabel;
         JTextField loginText, passText;
         JButton loginBut, cancelBut, resetBut;
         public void init()
         resize(400,300);
         Container content = getContentPane();
         content.setLayout(new FlowLayout());
         // create & add title
         loginTitle = new JLabel("Policyholder Login");
         content.add(loginTitle);
         //create & add labels and textfields
         loginLabel = new JLabel("Login name:");
         loginText = new JTextField(9);
         content.add(loginLabel);
         content.add(loginText);
         //create & add buttons
         loginBut = new JButton("Login");
         cancelBut = new JButton("Cancel");
         resetBut = new JButton("Clear All");
         content.add(loginBut);
         content.add(cancelBut);
         content.add(resetBut);
    thanks in advance for your contribution of knowledge....
    Canis

    The error message printed to the console quite clearly states the problem: applet not public, cannot access applet with modifiers ""
    change your declaration of "class login extends JApplet" to "public class login extends JApplet", and you'll find it works fine.

  • Problem with Thread in JApplet

    Hi,
    I am working on a project on pseudo random functions, and for that matter I have written a problem. Now I am working on a user interface (JApplet) for my program. Because some heavy calculations can occur, I want to keep track of the progress, and show that in my JApplet. To do so, I start a Thread in which the calculations take place. In my JApplet I want to show every second how far the proces is done. The strange thing is, that the status JLabel only appears when the whole proces is done, and the start button keeps pressed during the proces. If I run this in the applet viewer, I can see the status every second in my command box. You can see the applet here : applet
    The code concerning the start button's actionlistener (entire appletcode: [applet code|http://www.josroseboom.nl/PseudoRandomClusteringApplet.java]) :
              if(e.getSource()==start)
                   int[][] randomFuncties = new int[current+1][5];
                   int puntenHuidige, g, q, y, m, f;
                   boolean done;
                   Kern k;
                   for(int i = 0;i<=current;i++)
                        randomFuncties[i] = functies.getValues();
                   invoer.remove(knopjes);
                   startTijd = System.currentTimeMillis();
                   proces.setBounds(25,(current+4)*25, 2*this.getWidth()/3,75);
                   invoer.add(proces);
                   this.validate();
                   this.repaint();
                   for(int i = 0;i<=current;i++)
                        puntenHuidige = 0;
                        f = randomFuncties[i][0]; // important for instantiation of k, which is cut out here
                        done = false;
                        k.start();     // k is a Thread where heavy calculations are done
                        ((JLabel)(proces.getComponent(2))).setText("points done of current (" + q + ")");
                        this.repaint();
                        while(!done)
                             ((JLabel)(proces.getComponent(1))).setText("" + convertTime(System.currentTimeMillis() - startTijd));
                             ((JLabel)(proces.getComponent(3))).setText("" + k.getPuntenGehad()); // get the point done so far
                             ((JLabel)(proces.getComponent(5))).setText("" + ((100*k.getPuntenGehad())/q) + "%");
                             debug("q: " + q);
                             debug("point done: " + k.getPuntenGehad());
                             if(k.getPuntenGehad()==q)     //if all points are considered
                                  done=true;
                             this.validate();
                             this.repaint();
                             try
                                  Thread.sleep(1000);
                             catch(InterruptedException exception)
                                  debug("foutje met slapen: InterruptedException");
                             catch(IllegalMonitorStateException exception)
                                  debug("foutje met wachten: IllegalMonitorStateException");
                             debug("IN APPLET: yet another loop walk");
                        stringResultaten.add(k.geefResultaat());
                   klaarLabel.setBounds(this.getWidth()/4,(current+8)*25, this.getWidth()/2,25);
                   naarResultaat.setBounds(25+this.getWidth()/4,(current+9)*25, this.getWidth()/4,25);
                   invoer.add(klaarLabel);
                   invoer.add(naarResultaat);
                   this.validate();
                   this.repaint();
    Edited by: Jos on Sep 19, 2007 1:22 AM

    Never do anything that takes more than a fraction of a second in an actionPerformed method or similar GUI callback.
    The GUI stuff is all handled by a single thread called the "AWT Dispatcher" thread. That includes code in such callbacks. While it's executing your callback it can't do any kind of screen updating or response to other user events.
    Instead your actionPerformed should work with a separater "worker" thread, either it should launch a new thread, or release one you create (using wait and notify). Then, it returns without waiting. When the worker thread wants to update the GUI it uses EventQueue.invokeLater() or invokeAndWait() to run some (fast) code on the Dispatcher thread.

  • Avoiding the repaint of all components in an JApplet

    Hello everyone,
    Thannks to all who gave me advices for the two JComboBoxes I had...finally I found two "if" conditions in the actionPerformed of the first JComboo which restricted the list of elements posted in the second one.
    I have a much bigger problem now....The Applet contains an object which is an extension of JPanel, and in this extension there is a "paintComponent()" that creates a certain number of JButtons in a "for" loop. The problem I have is :
    How could I avoid this panel to be repainted every time the page containing the Applet is resized? Is it even possible( because from what I've been reading a "paint()" of the applet always calls for all the components' "repaint()".....I haven't even definned a "paint()" for the applet, .....and then, each button has an action listener that simply won't work after a repaint() of the whole applet. And honestly i'm starting to lose my mind a bit over all this......Oh, I had almost forgotten....the problem after re-sizing is that within the borders of the Panel there are always buttons created by the "for" loop ....and they are smaller and appear high up "north" in the panel...it's horrible!!!!!
    This is my code for the paintComponent() of the extension of the JPanel:
    public void paintComponent(Graphics g){
           g.drawLine (130,50,130,450);
           g.drawLine (129,50,129,450);
           g.drawLine (270,50,270,450);
           g.drawLine (271,50,271,450);
           g.drawString("Plateau no.", 80,40);
           g.setColor(ballon);
           g.fillArc(100,434,200,100,45,-270);
           System.out.println("I've been through paint");
        for(int i=0;i<13;i++)
           System.out.println("buton ok"+i);
           plateaux=new JButton();
    plateaux[i].setEnabled(true);
    plateaux[i].addActionListener(this);
    Color cri=new Color(240-15*i,0,0);
    plateaux[i].setBounds(130,60+30*i,139,15);
    plateaux[i].setBackground(cri);
    add(plateaux[i], null);
    g.drawString(" "+ (13-i),105,70+30*i);
    There's nothing else in the extension....only the paint ...it implements ActionListener.....
    Thankx in advance....I'd really apreciate it if someone could help me.....
    Ruxi

    To clear the background for each repaint add a call to super or use clearRect or fillRect (with the background color set, of course). If you don't do this you will get artifacts in your graphics.
    class GraphicComponent extends JPanel {
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            // carry on...
    }Paint code is the place to render graphics and images, not for adding components. Add your components to the GUI in or via init. Generally is is useful to keep your drawing component separate from your other components.
    class GUIClass extends JApplet implements ActionListener {
        public void init() {
            JPanel buttonPanel = getButtonPanel();
            getContentPane().setLayout(new BorderLayout());
            getContentPane().add(buttonPanel, "South");
            getContentPane().add(new GraphicComponent());  // default center section
        private JPanel getButtonPanel() {
            JPanel panel = new JPanel(null);
            JButton[] plateaux = nw JButton[13];
            for(int i=0;i<plateaux.length;i++) {
                System.out.println("buton ok"+i);
                plateaux=new JButton("button " + i);
    plateaux[i].setEnabled(true);
    plateaux[i].addActionListener(this);
    Color cri=new Color(240-15*i,0,0);
    plateaux[i].setBounds(130,60+30*i,139,15);
    plateaux[i].setBackground(cri);
    panel.add(plateaux[i]);

  • Japplet with imageicon

    Hi, im working on a simple paint program in a Japplet. I'm stuck right now on getting an icon on a button by giving the ImageIcon constructor a file path. I get an error when I try to run the applet with the imaging code in, not without.
    I've read in a few places that this won't work for general applets or jar files. Is there anyway that i can get it to load from my computer without resorting to having to load the .gif files from a internet site?
    // i have this (which doesn't work)
          JButton draw = new JButton(new ImageIcon("images/0.gif"));
          draw.addActionListener(canvas);
          toolsPanel.add(draw);
    //as compared to this (which does without an image)
          JButton line = new JButton("Line");        
          line.addActionListener(canvas);            
          toolsPanel.add(line);

    JButton draw = new JButton(new ImageIcon(new java.net.URL(getCodeBase(),"images/0.gif")));

  • Need help importing animated gif by ImageIcon in Japplet

    Hello. Im new to Java, but I want to import this animated gif with Java in a Japplet using ImageIcon, but it does not work and I would really appreciate if anyone could help me with this.
    import java.applet.*;                                   
    import java.awt.*;   
    import java.net.*;
         public class Bilder extends Japplet{                               
         public ImageIcon(java.net."http://pixelninja.se/kappawin.gif");
      Image[] bild = new Image[1];                            
      int nr=0;                                                
      public void init(){                                     
        setBackground(Color.black);                         
        bild[0] = getImage(getCodeBase(),"4a.gif");     
      public void paint(Graphics g){
        g.drawImage(bild[0],50,50,212,282,this);
    }

    You cant do animated gifs this way.
    Also you should remember that you cannot load images in to an applet if it is hosted somewere else than the host that hosts the applet.
    Esiast way to display an image icon with a animated gif will be creating a Image Label and adding it to the applet.
    Ex:-
    public class MyImageApplet extends JApplet{
       public void init(){
          getConentPane().setLayout(new BorderLayout());
           URL imageURL = getClass().getResource("/myImage.gif"); 
          // Above image file should be in the code base or in the archive file of the applet
          getConentPane().add(new JLabel(new ImageIcon(imageURL)));
    }

  • Open a JDialog from an JApplet

    Hello,
    I have an applet and I want to open a separate window. The problem is that I want this window to be modal, and therefore I have to use a JDialog, but a JDialog needs an owner that can only be a JFrame or a JDialog, so I cannot use the JApplet as an owner. I tried to set the owner to null, but then if the user changes the focus to another window in his/her OS, and then returns to the browser, the JDialog does not reappear, so the applet is stuck!
    Does anybody have an idea how I can solve this problem?
    Thanks very much.

    Yes, cuz all applets have a frame....
    Frame f =
    (Frame)SwingUtilities.getAncestorOfClass(Frame.class,
    this);Thank you very much. I will try this solution.

  • How to open web pages from japplet??

    Hi
    Does anybody know how to open web pages from java japplet??
    Any help is apreciated!
    zick

    the getAppletContext() method of the Applet class will get you an AppletContext, with which you can call the ShowDocument(URL url) or ShowDocument(URL url, String target) method...
    check it out at http://java.sun.com/j2se/1.4/docs/api/java/applet/AppletContext.html
    have a good one :)
    Jay

  • Communication between JApplet and Applet on the same web page

    Hi Freinds
    I have a JSP page containing two applets as follows :-
    <jsp:plugin type="applet" code="TreePageJavaClass.class" codebase="/MYOA" width="200" height="300" name="Applet1">
    </jsp:plugin>
    <jsp:plugin type="applet" code="TreePageJavaClass2.class" codebase="/MYOA" name="Applet2" width="200" height="300">
    </jsp:plugin>
    First applet extends JApplet class and has a tree constructed using swing.
    Second applet extends Applet class.
    Now I want to call a method in second applet on selecting a particular tree node on first applet. I can call method on second applet from first applet when both extends Applet class (not JApplet)
    So please tell me what's the problem here and how it can be solved.
    Thanks

    There is a Middle Eastern version of Adobe Dreamweaver CS4-ME, with full support
    of Hebrew, Arabic, Farsi and other languages,
    see http://www.fontworld.com/me/dreamweaverme.html

Maybe you are looking for

  • How to change the Number of IVR ports in a UCCX?

    I know this question has been asked before but it needs to be asked again, as previous answers do not seem to apply.   The simple quesiton is:  If you have a UCCX and if after install you check you check License information and you note that you have

  • How to hide devices on Find My phone with Family Sharing?

    So we have ios8 family sharing activated. My kids have their own Apple ID's so when they log in to icloud.com and go to Find My Iphone, all our devices show up there so any person in our family can see them and also Erase data from a device. I really

  • Unable to "double-click"

    After having issues with Leopard and FCP, I downgraded back to Tiger but now I am unable to use my double click feature, as well as the "right click" feature on my touch pad. Therefore I am unable to open my links in new tabs or save pictures, etc. I

  • Impersonation using javascript in MS CRM 2013

    Could it be possible to retrieve records on behalf of another user in MS CRM 2013/2015 using javascript. Is there any way to use ActOnBehalfOf privilege using javascript? 

  • Procedure didn't  insert to table TBLorder

    Hi all I have a procedure as this following. I would like to insert data to table TBLorder by this procedure CREATE OR REPLACE PROCEDURE ORDERADD I_MEMID IN VARCHAR2, I_CARTID IN VARCHAR2, I_ORDERDATE IN DATE, O_ORDERID OUT VARCHAR2 AS ADD_ORDERID TB