Confusion in applets

Hi all
When iam using applets iam really confused how can we use methods of a class with out creating a object yes if its static then its fine ,
look at below
public void paint(Graphics g){
g.drawString("hello",10,10);
Now how can i use draw sting method with out creating object and interestingly Graphics is a Abstract class and drawstiring is a abstract method. It is same with evenr listeners also...
Plese make me clear about it.
thanks
Jeevan

Graphics g is a reference to not an abstract class that extends Graphics. Applet container (if you use a web browser container is built in) creates not an abstract class that extends Applet or JApplet. And this class calls paint(Graphics g) with parameter of a Graphics instance associated with an applet.

Similar Messages

  • Confusion about applet

    sir
    i have confusion about applet that if an applet compile successfully but on running it shows a exception message about "main"that no such method exist.help me out please

    The full text of the error message would make it easier for us to see what is wrong BUT it sounds like you are trying to run the Applet as an applicaiton from the comand line rather than through an HTML tag in an HTML page loaded into your browser!
    Though you can make Applets run as applications it not normal to do so.

  • Confused: easy applet has a bug I cant fix

    //This program requires the user to guess a number between 1 and
    //1000(that had been generated by random function).
    //Integer.parseInt method seems to generate an exception but i
    //don't get why cause everything seems fine.
    //please help!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class GuessTheNumber extends JApplet implements ActionListener {
    JLabel guess;
    JTextField userNoT;
    JButton guessB;
    int number, userNo = 0;
    int tries;
    boolean guessed = false;
    boolean continuePlay = false;
    public void init()
    Container c=getContentPane();
    c.setLayout(new FlowLayout());
    guess = new JLabel("Guess a number between 1 and 1000");
    c.add(guess);
    userNoT= new JTextField(8);
    c.add(userNoT);
    guessB = new JButton("Guess!");
    guessB.addActionListener(this);
    c.add(guessB);
    }//end method init
    public void actionPerformed(ActionEvent e)
    if (continuePlay == false)
    number = 1+ (int)(Math.random()*1000);
    tries=1;
    else
    tries++;
    play();
    }//end method actionPerformed
    public void play()
    String userNoS = userNoT.toString();
    userNo = Integer.parseInt( userNoS );
    if (userNo == number)
    guessed = true;
    else if (userNo < number)
    showStatus(userNoS + " is too high. Try again!");
    userNoT.setText("");
    else
    showStatus(userNoS + " is too low. Try again!");
    userNoT.setText("");
    if(guessed==true)
    if (tries < 10)
    showStatus(Integer.toString(userNo) + "is correct!Either you know " +
    "the secret or you got lucky!");
    else if (tries==10)
    showStatus(Integer.toString(userNo) + "is correct!Ahah! You know " +
    "the secret!");
    else
    showStatus(Integer.toString(userNo) + "is correct!You should be able to"+
    " do better!");
    userNoT.setText("");
    continuePlay=false;
    guessed = false;
    }//if(guessed==true)
    else if (continuePlay==false)
    continuePlay=true;
    }//end method play
    }//end class

    What exception is it throwing?Exception occurred during event dispatching:
    java.lang.NumberFormatException: javax.swing.JTextField[,65,30,88x21,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=null,alignmentY=null,border=javax.swing.plaf.basic.BasicBorders$FieldBorder@46c1d4,flags=1184,maximumSize=,minimumSize=,preferredSize=,caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=0,g=132,b=255],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],selectedTextColor=javax.swing.plaf.ColorUIResource[r=255,g=255,b=255],selectionColor=javax.swing.plaf.ColorUIResource[r=255,g=156,b=112],columns=8,columnWidth=11,command=,horizontalAlignment=LEADING]
         at java.lang.Integer.parseInt(Integer.java:405)....

  • Applets and accessing files confusion

    Hi
    I am confused about applets and their abilty to access files.
    I know that applets cannot access files on a users hard drive until given pemission but if i design an applet that needs access to files on the server where it is running will it be able to read and write those files in the same location as the applet without the need to set permissions?
    Any feedback would be great
    Neil

    The applet is very much able to read files from the server. This is easiest done by creating a URL and opening a stream to it:
    URL url = new URL(getCodeBase(), "file.dat");
    InputStream in = url.openStream();
    // read from the stream...
    in.close();
    Saving files to the server is also possible without setting permissions but it's a bit harder. In short, you need some sort of server that accepts a connection and saves what you send it to disk. The server can be eg. a servlet, a database or a FTP server.

  • Applet Usage

    Hi,
    I'm new to Java Tech.
    I'm very much confused with Applet...
    I know that this is a basic q'n..still i'm not clear enough...
    Applets are the programs which run on the clients side....
    In which situations will i be using a applet...
    can i use a JSP in the place of a Applet and give the data to the jSP Page....
    Kindly anyone clear me the concepts of Applet..where it shud be used???in which situation???
    Thanks,
    Ram

    As you said applets are the programs that run on the client side. Yes and there are certain limitations to it. Usually many browsers that may not support applets. Servlets is an optimum solution when you are working with a client-server application as servlet are very dynamic. Because servlets can also produce html with javascript set in.
    Applets may give you a cosmetic graphic look. But they are poorly supported to my knowledge. And if you want to write an applet that communicates to a servlet. You need to do huge home work on that.
    From Sun:
    An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled browser to view a page that contains an applet, the applet's code is transferred to your system and executed by the browser's Java Virtual Machine (JVM). For information and examples on how to include an applet in an HTML page, refer to this description of the <APPLET> tag.

  • Why some coms not able to load certain JSP pages?

    Hi according to above,
    was thinking of creating jsp pages, but there seems to be occasional problems of not able to view jsp pages even though the computer has the updated JRE and has also try other browsers and had also reinstall JRE for a few times.
    Anyone know how to resolve this issue? The only method is I know is to format the computer and reinstall windows. Is this a windows issue or a jsp issue?

    i think you're confused. Applets need to have a local JRE on the client, JSP and servlets do not. All the java action in a JSP is performed on the SERVER, not the CLIENT. The server merely spits back to the client HTML (and possibly javascript) code just like any other static HTML page.
    Therefore, no web browser have ever not been able to view a JSP page. There may have been JSP pages that used JavaScript that doesn't work in all browsers, or JSP pages that returned invalid or browser specific HTML pages. But that's not JSPs fault.
    JSP --> No client JRE required.

  • Cards vs Applet confusion

    Does single Visa applet contain many cards or for each card there is an Applet in SE?

    Your question is not clear.
    - Does single Visa applet con tain many cards? I don't understand what you mean?
    - For each card, there is an applet in SE? it depends!!!
    1. Visa applet is an on-card application. So it can not contain any card. Basically, it's a EMV-compatible payment application approved by Visa
    2. Card has multiple flavors. It can be mono-application computing platform where resides only one cardlet or multi-application computing platform (JavaCard, .Net card, MULTOS etc.) which can host many applets but only one can be active. Smartcard is considered as secure element (SE) but it can be something different from a secure element in some ecosystem where you can see a smartcard and a secure element in the same schema.
    Hope this information is useful.
    BR,
    JDL

  • Confusing problem with applet

    hello!
    i want to write a web-forum as a java-applet. i use a toolbar with togglebuttons and a desktop all within a jframe. each button has an itemStateChangedListener which creates an internalFrame and adds it to the JDesktop, each time the togglebutton is activated. now that i have some visible stuff, i tried to write a class that connects to a php-site to get some data from my mysql-database. the class works fine, but when i try to use it in the itemStateChanged method of my toggleButton to add content to my internalFrame, no internalFrames get created any more... is it good to create the internalFrame and to request data from the phpSite all within the Listener?! i have no idea. i tried to extend internalFrame and added the requestData to the constructor - same result: they were not shown either. why?
    thanks for any idea!
    please help me!

    thanks! well validate() and co. didn't help much...
    my girlfriend suggested to just first show the iframe and then do the dataRequest and the frames are shown! if everything was so easy...
    still don't understand why the other way round didn't work.
    since i haven't got my own server i can't make it a webapp because the provider of my webspace has no jnlp installed. so i decided to build everything up as an applet and as soon as i see the possibility make it a webapp. many classes will be reuseable...
    thnx for your ideas

  • Java Applet......confused....

    Dear all,
    I am trying to draw mutiple images in one applet frame....
    and each images are to behave like buttons......any one have any idea?
    thank you,
    Dan

    i just want to do one thing at a time!!! Ok, slowly but steadily.
    the implementation of getGraphics().....whats the
    purpose....Graphics represents a graphics context that can be drawn on. Every displayable component has one.
    In your applet you should have the void paint( Graphics g) method somewhere, in order to get anything displayed on the screen.
    Now in this method you can just do something along these lines:
    void paint( Graphics g )
    Image myImage1 = getImage( "http://foo.com/images/image1.jpg" );
    Image myImage2 = getImage( "http://foo.com/images/image2.jpg" );
    /* Graphics object g supplied as parameter represents this applet's graphics context. */
    g.drawImage( myImage1, 100, 100, null );
    g.drawImage( myImage2, 300, 200, null );
    /* No you should have two images on the screen, depending on their size, as they may be overlapping each other */
    and in order to display all the images onto the
    frame....do i have to
    drawImage() for every single image? or is thereBasically yes.
    another way to get this done more efficently?Yes, there is. It's called double buffering. With this, you create an offscreen (that is, nondisplayable) Image, that matches the size of your applet window. Then you draw all your images into that (class Image has a getGraphics() method that can be used to acquire its graphics context) as above. After that you can just draw the offscreen image into screen with one drawImage()-method call. This increases performance and reduces the flickering the user experiences when drawing separate images directly to the screen.
    .P.

  • Confused about signed applets

    Hello!
    I've been reading the documentation on signing applets and I'm having trouble with a few concepts.
    I'm working on an internal project that involves an applet. This applet needs access to other hosts, therefore I need to sign it. Am I on the right track? But, there will be a fairly large number of people who need to use the applet. Will I need to do something on each individiual machine, or is there a way to sign the applet and have it automatically give the users the option to allow it to do its thing?
    Also, the jar files that the applet uses, do they need to be signed also? Tanks in advance for your help.
    -jeff

    Hi jousley,
    a Java applet needs to be signed in order to be permitted to cary out a number of security related functions such as opening a TCP/IP connection to another machine than the one it was loaded from, storing files on the client machine etc. If your applet needs to do this, you have to sign all the jar files that contain Java classes that need this unrestricted access.
    If one of the users of your applet launches it the first time, the Java Plugin will present the user a dialog, declaring that your signed applet wants to gain unrestricted access to the client machine. The dialog allows the user to inspect the digital certificate you have used to sign the Java archives making up the applet. Then the user has to decide if he wants your applet to have the desired rights. He can decide if he wants to give your applet the permission for only one session, for all subsequent sessions or never.
    If permission 'always' is granted, your certificate will be added to the store of trusted certificates manageable via the Java Plugin panel. If deleted from there, the user has to grant permission again while starting the applet the next time.
    I hope this is of some help for you
    Mikno

  • Convert applet to swing

    Hi;
    Could anyone help me to convert my example code from applet to swing,please, thank
    import java.awt.*;
    import java.applet.*;
    import java.lang.Math;
    import java.awt.Font;
    import java.lang.Integer;
    /*** Main class == Applet  ***/
    public class Suffix extends Applet implements Runnable {
       private Thread main;
       public s_tree _tree=null;
       public node nd=null;
       public boolean userPause=false,resumed=false;
       private String str[]={"GOOGOL$","Paused","Resumed","Compacting","Done"};
       public Color bl=Color.blue,rd=Color.red;
       public Font fnt;
       public int mode=3,delay=3000;
       private char alph[]={'$','Q','W','E','R','T','Y','U','I','O',
                        'P','A','S','D','F','G','H','J','K','L',
                        'Z','X','C','V','B','N','M'};
    /*** initialisation function. It is the first Funct to be called ***/
       public void init() {
    // Temp data
          int temp=0,nxx=30;
    // Ini. of fnt , the font size + style used by this applet.
          fnt=new Font("Denis",1,25);
    /*** parsing command parameters ***/
    //      try {
    //DELAY VALUE PARAM
             String param=getParameter("DELAY");
             if (param!=null) {
                temp=Integer.parseInt(param);
                if ((temp>500)&&(temp<6000)) delay=temp;
    //x LEFTMOST coordinate
             param=getParameter("X");
             if (param!=null) {
                temp=Integer.parseInt(param);
                nxx=temp;
    //Base String parameter
             param=getParameter("STRING");
             if ((param!=null)&&(param.length()<15)) {
                str[0]=param;
    //      } catch (ParseException e) { showParseError(e); }
    // Allocating mem for _tree + initialize it .
          _tree=new s_tree(str[0],fnt);
    // Override xx (left_bound) by the caller's or the default value
          _tree.xx=nxx;
    /*** "animation loop is controled here" ***/
       public void run() {
         while(true) {
             try {
    //delay the process for time==delay
                Thread.sleep(delay);
             } catch (InterruptedException e) {}
    //controls animation loop
          repaint();
    /*** override APPLET's paint function ***/
       public void paint (Graphics g) {
    //Output graphics
          update(g);
    /*** Updates the graphics ***/
       public void update (Graphics g) {
    // Set font
          if (g.getFont()!=fnt) g.setFont(fnt);
          if ((userPause==false)&&(resumed==false)) // Is the applet paused ?
             g.clearRect(0,0,1024,768); //clears the screen
             if (_tree==null) {     // if tree is not initialised
                init();
                //_tree.show(g);
             } else {
                if (mode==3) {      // if graphics output mode is 3
                   if (nd!=null) nd._to_rd(false);
                   nd=_tree.step_compact(nd);  //compacts the tree one step further
                   if (nd==null)  // if tree is totally compacted ...
                      mode=4;   //change the ani. mode to 4 (don't call compact)
                   else
                      nd._to_rd(true);  //colors the next node to compact in red
    // Draw the "titleviewport's" comment
             g.setColor(bl);
             g.drawString(str[mode],10,15);
             _tree.show(g);     //show tree
          } else {
             g.clearRect(0,0,200,25);  //clears the "titleviewport to update it"
             g.setColor(rd);
             if (resumed==true){
                resumed=false;
                g.drawString(str[2],10,15);
             else g.drawString(str[1],10,15);
    /*** restart the animation process ***/
       public void start() {
          main=new Thread(this);
          main.start();
    /*** stops the animation ***/
       public void stop() {
          main.stop();
          main=null;
    /*** Handles the user's events (mouse , kbd , ... ***/
       public boolean handleEvent(Event evt) {
          if (evt.id==Event.MOUSE_DOWN) { //if mouse button have been pushed ...
                if (main!=null && main.isAlive()) {
                   if (userPause) {
                      main.start();
                      resumed=true;
                   } else {
                      main.stop();
                   userPause= !userPause;
                } else {
                   main= new Thread(this);
                   main.start();
                   userPause=false;
                   resumed=true;
                repaint();
             return true;
          } else {
             return super.handleEvent(evt);
    /*** Linked List of node(s) ***/
    class nodelist{
       nodelist next=null;
       node ptr=null;
       public void nodelist(){};
    /*** node of a structure tree ***/
    class node {
    // Relatives
       public nodelist children=null;
       public node parent=null;
    // variables
       public int maxchild=12,childnum=0,level=0;
       public int center[]={0,0};
       public int xlen=20,ylen=10,vspace=15,hspace=8;
       public int x[]={0,0};
       public boolean _ishidden=false;
       private Color bk=Color.black,wh=Color.white,rd=Color.red;
    // Node==red toggle variable
       public boolean to_rd=false;
    // node's text
       public String label=null;
    /*** initialisation of the node ***/
       public node(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,String nstr){
          x[0]=nx; x[1]=ny;
          xlen=nxl; ylen=nyl;
          parent=nparent;
          level=nlevel;
          label=new String(nstr);
          children=new nodelist();
    /*** destroys the node ***/
       public void destruct() {
    // NOTE : not like C++ destructors . Do not confuse .
          delete_subtree();
          children=null;
          parent=null;
          bk=wh=rd=null;
          label=null;
    /*** Node to red toggle switch ***/
       public void _to_rd(boolean b) {to_rd=b;};
    /*** Adds a child to this node ***/
       public void add_child(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
                                String nstr) {
          if (childnum<maxchild) {    // if 'legal' space left ...
             if (children==null) {    // if no nodelist attached ...
                children=new nodelist(); //init. children
                children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create node
                childnum++;
             } else {
                nodelist dummy=children;
    // search for the last nodelist
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist(); //adds a nodelist
                dummy=dummy.next;
                dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr); //create child
                childnum++;
    // Tree needs to be realigned
    /*** adds a child and returns its address ***/
       public node add_child_ret(int nx,int ny,int nxl,int nyl,node nparent,int nlevel,
                                String nstr) {
          if (childnum<maxchild) {
             if (children==null) {
                children=new nodelist();
                children.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
                childnum++;
                return(children.ptr);
             } else {
                nodelist dummy=children;
    // search for the last child
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist();
                dummy=dummy.next;
                dummy.ptr=new node(nx,ny,nxl,nyl,nparent,nlevel,nstr);
                childnum++;
                return(dummy.ptr);
        return(null);
    // Tree needs to be realigned
    /*** adds the node nchild as a new children ***/
       public void add_child(node nchild) {
          nodelist dummy=null;
          dummy=children;
          if (childnum<maxchild) {
             if (children==null) {
                children=new nodelist();
                children.ptr=nchild;
                childnum++;
             } else {
                while (dummy.next!=null) dummy=dummy.next;
                dummy.next=new nodelist();
                dummy=dummy.next;
                dummy.ptr=nchild;
                childnum++;
    //Tree needs to restructured.
    /*** deletes all childrens ***/
       public void delete_subtree() {
          while (childnum>0 && children!=null) { //while child exists , kill it
             if (children.ptr!=null) {
                children.ptr.destruct();
                children.ptr=null;
                children=children.next;
             } else children=null;
             childnum--;
    /*** moves this node and its children horizontally ***/
       public void move_tree(int nx) {
          nodelist dummy=children;
          x[0]+=nx;
          while (childnum>0 && dummy!=null) {
             if (dummy.ptr!=null) {
                dummy.ptr.move_tree(nx);
                dummy=dummy.next;
    /*** removes the node from the tree (do not preserve order of ordered tree ) ***/
       public void remove_node() {
          nodelist dummy=children;
          while(dummy!=null) {
             if (dummy.ptr!=null){
                parent.add_child(dummy.ptr);
             dummy=dummy.next;
          children=null;
    //could call restructure tree here .
    //don't forget to change the node's levels !!!
    /*** show all nodes ***/
       public void show_all(Graphics g) {
          if (_ishidden==false) { //if not hidden
             if (children!=null) {  //if child exist
                nodelist dummy=children; //temp var.
                while(dummy!=null) { //while there is a child...
                   if (dummy.ptr!=null)
                      dummy.ptr.show_all(g);
                   dummy=dummy.next;
             show_node(g);
    /*** show nodes in preorder ***/
       public int preorder_show(Graphics g,int label){
          if (_ishidden==false) {
             show_node(g/*,label++*/);
             if (children!=null) {
                nodelist dummy=children;
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.preorder_show(g,label);
                   dummy=dummy.next;
          return(label);
    /** show nodes in postorder ***/
       public int postorder_show(Graphics g,int label){
          if (_ishidden==false) {
             if (children!=null) {
                nodelist dummy=children;
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.postorder_show(g,label);
                   dummy=dummy.next;
             show_node(g/*,label++*/);
          return(label);
    /*** show nodes in inorder ***/
       public int inorder_show(Graphics g,int label){
          if (_ishidden==false) {
             if (children!=null) {
                nodelist dummy=children;
                if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
                dummy=dummy.next;
                show_node(g/*,label++*/);
                while(dummy!=null) {
                   if (dummy.ptr!=null) label=dummy.ptr.inorder_show(g,label);
                   dummy=dummy.next;
             } else show_node(g/*,label++*/);
          return(label);
    /*** Restructure the coordinates of all nodes ***/
       public int align(int min,Font fnt,int lev,Graphics g){
          int i=min; //left bound
          FontMetrics fntm=g.getFontMetrics(fnt); //used to know the text size
          level=lev;
    // node x and y radius are computed here
          xlen=4+(int)(fntm.stringWidth(label)/2);
          ylen=4+(int)(fntm.getHeight()/2);
          if (children!=null) {      //if child present ...
             nodelist dummy=children;
             while(dummy!=null) {
                if (dummy.ptr!=null) i=dummy.ptr.align(i,fnt,lev+1,g); //align them
                   dummy=dummy.next;
          x[0]=min+(int)((i-min)/2); //could be underflow so will be checked
          x[1]=lev*(vspace+(ylen*2))+26;
    // overflow should happen only when the parent node is larger than its children
          if ((x[0]-xlen)<min) { //check uf underflow occurs.
             move_tree(min+xlen-x[0]+1);
             i=x[0]+xlen+5;
          if (childnum==0) x[0]+=2;
        return(i);
    /*** returns the child following nd ***/
    /*** if nd==null -> return 1st child ***/
    /***  if nd==last children -> return null***/
       public node next_child(node nd) {
          nodelist dummy=null;
          if (children==null) return(null);
          if (nd==null) return(children.ptr);
          dummy=children;
          while (dummy.ptr!=nd) {
             if (dummy.next!=null)
                dummy=dummy.next;
             else
                return(null);
          dummy=dummy.next;
          if (dummy!=null) return(dummy.ptr);
             else return(null);
    /*** returns child with first letter==nh ***/
       public node get_childd(char ch) {
          nodelist dummy=null;
          dummy=children;
          while (dummy!=null) {
             if (dummy.ptr!=null) {
                if (dummy.ptr.label.charAt(0)==ch)
                   return(dummy.ptr);
             dummy=dummy.next;
        return(null);
    /*** returns the nodelist containing nd ***/
       public nodelist get_child(node nd) {
          nodelist dummy=children;
          while (dummy!=null) {
             if (dummy.ptr==nd) return(dummy);
             dummy=dummy.next;
        return(null);
    /*** outputs the node to Screen ***/
       public void show_node(Graphics g) {
          if (_ishidden==false) {
             if (level>0) {  //if it is not a root then draw link-line
                g.setColor(bk);
                g.drawLine(x[0],x[1]-ylen,parent.x[0],parent.x[1]+parent.ylen); //from this node to parent node
             if (to_rd==false)
                g.setColor(wh);
             else
                g.setColor(rd);
             g.fillOval(x[0]-xlen,x[1]-ylen,xlen*2,ylen*2); //draws an oval
             g.setColor(bk);
             g.drawString(label,x[0]-xlen+4,x[1]+ylen-12);  //output the text
    /*** class which uses nodes to create a SUFFIX TREE ***/
    class s_tree {
       node root=null;    // root node.
       String str=null;   // 'search' string
       Font fnt=null;     // font type
       int xx=30;         // left limit for graphics
    /*** initialize a SUFFIX TREE with string==nstr and Font==nfnt ***/
       public s_tree(String nstr,Font nfnt) {
          str=new String(nstr);
          fnt=nfnt;
          create();
    /*** uninitialize the structure **/
       public void destruct() {
          root.destruct();
          str=null;
          fnt=null;
    /*** show the tree ***/
       public void show(Graphics g) {
          root.align(xx,fnt,0,g);   // restructure node's coordinates
          root.show_all(g); //show tree
    /*** creates a tree structure from String=str ***/
       public void create() {
          node dummy=null;
          root=new node(0,0,0,0,dummy,0," "); //create root
          root.parent=null; //just to make sure ...
          for (int i=0;i<str.length();i++) {
    // Create subtree of root in the following way :
    //    create subtree ("ASDF$");
    //        "     "    ("aSDF$");
    //       "    "      ("asDF$"); ...
    // where : the UPPERCASE letters is the part of the string sent to insert_string
             insert_string(str.substring(i));
          //root.align(0,fnt,0); //align root now ?
    /*** creates a subtree of ROOT with String=nstr ***/
       public void insert_string(String nstr) {
          node dummy2=null,dummy=null;
          int i=0;
          dummy=root;
          dummy2=root;
    // As long as a children of dummy2 have the letter nstr[i] , dummy==thischildren
    // It is used to make sure that a node does not have two children with the
    // same letter
          while (dummy2!=null) {
             dummy2=dummy2.get_childd(nstr.charAt(i));
             if (dummy2!=null) {
                i++;
                dummy=dummy2;
    //create the nodes for the rest of the string
          for(;i<nstr.length();i++) {
             if (dummy!=null) dummy=dummy.add_child_ret(0,0,0,0,dummy,1,nstr.substring(i,i+1));
    // Compacts the tree node by node and returns the next node to compact
    // if node==null , compacts the first node ...
    //Works in POST-ORDER
       public node step_compact(node nd) {
          node dummy=nd,dummy2=null;
          nodelist ndlst=null;
    // GOES TO THE LOWER LEFT CHILDREN
          if (nd==null) { //first call !
             dummy=root;
             while(dummy.children!=null) {
                if (dummy.children.ptr==null)
                   dummy.children=dummy.children.next;
                else
                   dummy=dummy.children.ptr;
    //*** tries to find a 'compactable' node ***
    //*** It uses the POST-ORDER method      ***
    // if this node is not the last children then try to find next compactable node
    // in the next children.
          if (dummy.parent.childnum!=1) dummy=next_chain(dummy);
          if (dummy==null) return(null); //fully optimized
    //remove parent node.
    /*** THIS IS WHERE COMPACTING TAKES PLACE  **/
          dummy2=dummy.parent.parent;
          ndlst=dummy2.get_child(dummy.parent);
          if (ndlst==null) return(null); //we've got a beeeeg problem if this happens ...
    //*** merges the parent string with this one and delete parent .
          dummy.label=dummy.parent.label.concat(dummy.label);
          ndlst.ptr=dummy;
          //delete parent .
          dummy.parent=null;
          dummy.parent=dummy2;
    //      root.align(0,fnt,0);
        return(dummy);
    /*** finds the next chain in the tree (i.e. the next compactable node) ***/
       public node next_chain(node nd){
          node dummy=null;
          if (nd.parent==null) return(null); //finished ! This is the root
          if (nd.parent.childnum==1) return(nd); //can be optimized
    // finds the nd.parent's child following nd
          dummy=nd.parent.next_child(nd);
          if (dummy==null)  // if OLD_nd==last child
             return(next_chain(nd.parent));      //tries to find a chain upwards
          else {
                 // OLD_nd was not the last child . nd==OLD_nd's next brother
    // GOES TO THE LOWER LEFT most child of nd's subtree.
             while(dummy.children!=null) {
                if (dummy.children.ptr==null)
                   dummy.children=dummy.children.next;
                else
                   dummy=dummy.children.ptr;
             return(next_chain(dummy)); // returns the next compactable node
    };

    First, show me the rupees! Show me the rupees!

  • Retrieving .txt file from jar for an applet

    I guess this is a newbie question but i checked the tutorial sessions and i am doing exactly what it says there but still...no luck:
    I'm trying to access a .txt. file stored in the .jar file where my applet .class file is stored. I'm using:
    String s = "myfile.txt";
    // get current Class loader
    ClassLoader cl = this.getClass().getClassLoader();
    FileInputStream is = new FileInputStream((cl.getResource(s)).toString());
    BufferedReader in = new BufferedReader(new InputStreamReader(is));But when the applet is viewer from the browser or from the appletviewer, i'm getting the FileNotFoundException:
    java.io.FileNotFoundException: jar:file:\C:\FeatureSelection\sFeatureSelection.jar!\myfile.txt (The filename, directory name, or volume label syntax is incorrect)
    I tried to use the following instead:
    FileInputStream is = new FileInputStream((myApplet.class.getResource(s)).toString());orFileInputStream is = new FileInputStream((getClass().getResource(s)).toString());but the same exception is still there.
    The jar file and the html file are all stored in this directory C:\FeatureSelection\
    The signed jar file is called sFeatureSelection.jar
    Any help would be greatly appreciated!
    Thanks.

    One way to get at files in a jar is to put the jar in the CLASSPATH and then just refer to the resource by its path in the jar. If the same path occurs in two different jars, then you only get the first one, based on the order of the jars in CLASSPATH, I think.
    The classloader is involved, which can be confusing, but an easy way to try this is:
    String s = "myfile.txt";
    URL u = this.class.getClassLoader().getResource(s);
    Object o = u.getContent();Now, you only really know that something matched that path and now it is in a URL.
    I think the Object will be a stream and you have to read() it or something.
    BTW: I encourage you to examine the URL, but it is not necessary to do so.
    If you have somehitng like a GIF image, then here is an example of how to work with that:
    http://www.devx.com/tips/Tip/5697
    Here is a way to get the bytes without involved the ClassLoader:
    http://www.javaworld.com/javaworld/javatips/jw-javatip49.html
    Take your pick.

  • Applet very slow and shows no activity, but its running

    I have a new applet for the users, but I am reluctant to implement until I get some others opinions. It is very slow (30 - 40 seconds)
    Before it outputs a screen with about 20 lines, it reads 90 different html files. It looks at the forth rec of each to extract a name. It also gets the file size to determine if the record needs to be on the screen.
    Anyway, it does 4 reads on 90 files. = 360 reads. Oops, it also reads and loads a 80 record file at the beginning. So total is 440 reads.
    It takes 30 - 40 seconds. Which is not horrible, but it is not good. What really bothers me is that the applet screen shows no activity. At the bottom is shows "done" and "100%". Task Manager shows no activity. But if you just let it sit there, it will finally fill the screen. Pretty amazing to me. I would much rather see a "progress bar" moving on the bottom like other screens. Actually, a progress bar would solve it, because the users are not in a big hurry anyway.
    I am using "openStream" and "readLine" for the files.
    Any opinions?
    import javax.swing.*;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class urlaa extends JApplet
    //zz  implements Runnable, ActionListener
          implements ActionListener
    // zz added
        private JLabel item;
        private JList itemList;
      int par;
      int errorflag = 0 ;
      int orgsize = 14900 ;
      String par1;
      String s;
      String e1;
      String e2;
      String e3;
      String w1;
      String w2;
      String w3;
      String w4;
      int i = 0;
      int len ;
      int size ;
      String stringsize ;
      URLConnection conn ;
      int i2 = 0 ;
      int k = 0;
      int current = 0;
      String s1 ;
      String s6 ;
      String s7 ;
      String s8 ;
      String printline ;
      String pageLink;
      String arr[]  = new String[150] ;
      String arr2[] = new String[150] ;
      String arr3[] = new String[150] ;
      int arr4[] = new int[150] ;
      String inputLine;
      Thread runner;
      public void init()
             String parameter = getParameter("par1");
             if (parameter != null)
                 par = Integer.parseInt(parameter);
             else
                 par = 99;
    // zz         Button goButton = new Button("Go");
    // zz         goButton.addActionListener(this);
    // zz         add(goButton);
    // zz   added
            this.item = new JLabel();
            this.addButton();
            Container container = this.getContentPane();
            this.itemList = this.getList();
            container.add(this.getPanel());
            URL u;
            InputStream wis = null;
            DataInputStream dis;
            int rcnt = 0;
            int rcn2 = 0;
           //    1)  read filelist.txt file
           //         and load into a table.
           //    2)  close the filelist.txt file
           //    3)  Use the tabled file names to
           //         read and see if the bio
           //         has been done
           //  1) Read filelist.txt and load table
            try
            u = new URL("http://www.classof1961.mysite.com/filelist.txt");
            catch (MalformedURLException e)
              errorflag = 1 ;  // set error flag to stop while loops
              e1 = ("FILELIST.TXT MalformedURLException: " + e.getMessage()) ;
            try
                u = new URL("http://www.classof1961.mysite.com/filelist.txt");
                wis = u.openStream();
            catch (IOException ioe)
              errorflag = 1 ;  // set error flag to stop while loops
              e1 = ("FILELIST.TXT IOException : " + ioe.getMessage()) ;
    //      does not work     size = wis.getContentLength() ;
                // Convert the inputStream to a buffered DatainputStream.
                dis = new DataInputStream(new BufferedInputStream(wis));
                // Read 1st record to set up while loop
                   try
                     s1 = dis.readLine() ;  // get 1st rcd
                   catch (IOException ioe)
                     errorflag = 1 ;  // set error flag to stop while loops
                     e3 = ("FILELIST.TXT IOException : " + ioe.getMessage()) ;
                   while (s1 !=  null)
                   {  // load file names loop
                   if (errorflag == 0)
                   {  // if errors
                    arr[i] = s1 ;
                    i++ ;
                    try
                    s1 = dis.readLine() ;
                    catch (IOException ioe)
                      errorflag = 1 ;  // set error flag to stop while loops
                      s1 = null ; // force end of loop
                      e3 = ("load table read failed" + ioe) ;
                    rcnt++ ;
                    if (rcnt > 100)  // test code
                    {                // test code
                      errorflag = 1;
                      s1 = null ;
                      e3 = "Load table is looping!!" ;
                   }  // end of error check loop
                   }  // end of table load loop
               int lasttableentry = i ;  //
                   // CLOSE the filelist.txt file
                   try
                    wis.close();
                   catch (IOException ioe)
                    errorflag = 1 ;  // set error flag to stop while loops
                    e3 = ("close of filelist.txt file failed" + ioe) ;
    //   End of filelist read and load and close
    //      ptr to whats new names in table arr
            i = 0 ;
    //      While more names in table,
    //        Connect and Open file
    //        Read file until 4th rcd (rel 3rd rcd)
    //          if rcd has date, then move it to table
    //          else
    //          bump to next file name
              w1 = arr[i] ;
              w2 = w1.substring(1, 4) ;   // ONLY USED FOR CHK FOR XXXX
    //    ______________  start of major loop  _____________
            boolean morenames = true ;
            while (morenames)
            {  // Name table loop
            if (errorflag == 0)
            {  //if no errors
              try
                u = new URL(w1);
                try
                  URLConnection conn ;
                  conn = u.openConnection();
                  size = conn.getContentLength();
                catch (IOException e)
                  errorflag = 4 ;
                  morenames = false ;
                  e1 = ("file size logic failed " + w1) ;
              catch (MalformedURLException e)
                    errorflag = 1 ;  // set error flag to stop while loops
                    morenames = false ;
                    e1 = ("next whats new url error : " + w1) ;
    // compile error                break ;
              try
                  u   = new URL(w1) ;
                  wis = u.openStream();
              catch (IOException e)
                errorflag = 1 ;  // set error flag to stop while loops
                morenames = false ;
                e2 = ("next whats new open error :  " + w1) ;
    //   compile error            break ;
    //            Convert the inputStream to a buffered DatainputStream.
                  dis = new DataInputStream(new BufferedInputStream(wis));
                if (errorflag == 0)
                {  //if no errors
                       try
    //  does not work                       String s2 = dis.readLine(3) ;
                         s1 = dis.readLine() ;
                         s1 = dis.readLine() ;
                         s1 = dis.readLine() ;
                         s1 = dis.readLine() ;
                       catch (IOException e)
                         errorflag = 1 ;  // set error flag to stop while loops
                         morenames = false ;
                         e2 = "whats new file MalformedURLException: " ;
                       // file is larger than original non-bio file size
                       if (size > orgsize)  //  if file size > original file size
                       String s2a = s1.substring(0, 5);
                       String s3 = "                       " ;
    //                 Only look at title records to get the name
                       if (s2a.equals("<titl"))
                          int k2 = 7 ;
                          int l = k2 + 1 ;
                            while (!s1.substring(k2, l).equals("<"))
                              k2++ ;
                              l++ ;
                          s3 = s1.substring(7, k2) ;
                       else
                          s3 = "               " ;
    //                 s3 now has blanks or the name
                       arr2[k] = w1 ;    // move name into arr2 (link to bio)
                       arr3[k] = s3 ;    // move name into arr3 (bio name)
                       arr4[k] = size ;  // move in file size
                       k++ ;
                       } // end of if length > 36
                } // end of chk for error flag zero (no errors)
                  //  now we have to close this whats new file
                   // CLOSE the current whats new file
                   try
                    wis.close();
                   catch (IOException ioe)
                    errorflag = 1 ;  // set error flag to stop while loops
                    morenames = false ;
                    e3 = ("close of the current whats new file failed" + ioe) ;
                  //  end of the close
              rcn2++ ;
              if (rcn2 > 100)  // test code
              {                // test code
                 errorflag = 2;
                 morenames = false ;
                 e3 = "Searching files is looping!!" ;
              i++ ;           // bump to next whats up name
              w1 = arr[i] ;   // load it into work string
              if (i > lasttableentry)
                morenames = false ;
              } // end of error checking loop
             else
                  morenames = false ;
            } // end major name table loop
                   // CLOSE the last whats new file
                   try
                    wis.close();
                   catch (IOException ioe)
                    errorflag = 1 ;  // set error flag to stop while loops
                    e3 = ("close of last whats new file failed" + ioe) ;
    // end of init
    //     _________________ other methods  ______________________
    // zz added
        private JList getList() {
            // Create a List
            JList tempList = new JList(arr3);
            tempList.setVisibleRowCount(3);
            // Enable single selection
            tempList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            return tempList;
        private JButton addButton() {
            JButton button = new JButton("Select Item below and click here to go to the bio");
            button.addActionListener(this);
            return button;
        private JPanel getPanel() {
            // set layout to GridLayout 3 rows and 1 columns, no separations
            JPanel panel = new JPanel(new GridLayout(3,1,0,0));
            JScrollPane spane1 = new JScrollPane(this.itemList);
            panel.add(this.addButton());
            panel.add(spane1);
            panel.add(this.item);
    //       panel.add(new JLabel("Example List"));
            return panel;
    //   _______________  actionPerformed method  ____________________
         public void actionPerformed(ActionEvent evt)
           s8 = "actionPerformed";
    // zz added
            String command = evt.getActionCommand();
            // Get the selected value from the list and update the JLabel
            item.setText((String)itemList.getSelectedValue());
    //  try to redirect to selected url
      try
             int idx  = itemList.getSelectedIndex() ;
             String urlvalue = this.arr2[idx] ;
             URL u = new URL(urlvalue);
             this.getAppletContext().showDocument(u, "_self");
         catch(Exception e)
    }

    jagossage wrote:
    But if you just let it sit there, it will finally fill the screen. Pretty amazing to me. The onus is on you, the developer, to decide how to distract your users as they wait for your code to finish. Why should you expect something to do it for you?
    I would much rather see a "progress bar" moving on the bottom like other screens.Ah, I think I see where you're confused. The progress bar and applet loading subtitles, etc are Java's way of presenting the progress of loading the applet. Once it's fully loaded, though (which it is when your code starts running), it hands off control to you. It's in your hands at that point.

  • Closing browser window from an Applet?

    I've written a series of applets that perform different functions. I placed a button on each applet with the purpose to close the window in which that applet is running. However I don't even know where to start looking to find out how to make my applet close it's own browser window. I know how to open a new browser window from an applet but not vice versa.
    Can anyone help please?
    Mark.

    Right, I sort of tracked down some code that uses getMethods to allow me to invoke a Javascript command. It is not pretty and took a little bit of editing to get to work but it does the job without putting JS stuff into my HTML.
    However it is causing some problems. If I open one of my other applets it will only let me close that window and the previous applets ceases to respond at all. I think this may be because the invoke gets the JSObject which is the window and somehow having more than one applet open in different windows is causing it to get confused and is locking the first window and only responding to the second.
    I have seen a much simpler method that uses:
    import netscape.javascript.*;
    and JSObject to get the window but my compiler complains about the import. Any further suggestions or an example would be welcome as my current solution is a bit limited as you can effectively only have one window open at a time which doesn't suit my needs.
    Many thanks.
    Mark.

  • How to writing an image from my applet to my apache webserver

    hi everyone,
    i have a big problem, writing an image from my applet to my apache
    webserver. i tried three way's of writing that file. every way was
    described in forums to solve this problem, but non of them worked and
    i don't know why. i'll give you the code of my writing-methods and
    describe, what happen when i test them, in order someone of you can
    give me an usefull tip, where the problem is.
    as inputparameter i give my method a new URL referring to
    http://localhost/test.jpg (this is the same directory, where my applet
    is loaded from, so i should have reading and writing permission,
    havn't i? while i'm developing, my applet runs on the same pc as my
    webserver, just in case you're wondering about localhost) and a
    selfmade BufferedImage (i already testet if it is not null and shows
    the correct things ... all ok).
    1. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    URLConnection urlConnection = fileURL.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream urlout = urlConnection.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(urlout);
    ImageIO.write(img,"jpg",out);
    out.close(); // i also tried without this line -> same result
    // additionally a question: do i need
    out.close()?
    catch( IOException e ){
    e.printStackTrace();
    result:
    test.jpg doesn't appear in the webroot. but some very strange messages
    in the error.log of my apacheserver:
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageOutputStreamSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageReaderSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageInputStreamSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageWriterSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageTranscoderSpi
    i cannot explain this lines to myself, because my apache should have
    nothing to do with java. all my javacode is executed on the client
    side in the browser. do this messages mean i have to add the ImageIO
    package from the sdk to my jar-applet. the jre, used by my iexplorer,
    doesn't contain this files in the meta-inf/services directory of
    rt.jar, but that's version 1.4.2_03, the same as my sdk, and the
    rt.jar contains the corresponding classfiles at javax.imageio.spi. so
    i'm realy confused by this messages.
    2. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    URLConnection urlConnection = fileURL.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream urlout = urlConnection.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(urlout);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(img);
    out.close(); // same comments as above
    catch( IOException e ){
    e.printStackTrace();
    result:
    nothing. no error-messages in the error.log, no exceptions in the
    java-console and no test.jpg in the webroot. i searched my whole
    harddrives for it: nothing. isn't this the way, the JPEGImageEncoder
    works?
    3. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    File file = new File(fileURL.toString);
    file.createNewFile();
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream(file));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(img);
    out.close(); // same comments as above
    catch( Exception e ){
    e.printStackTrace();
    result:
    the SecurityManager denies this action with "access denied" while
    calling createNewFile(). well, this way was dedicated to run from an
    application, not from an applet. i'd have to sign my applet to get the
    rights to do this, or i can edit java.policy on my client, what i
    don't want, because i cannot do this on every client, the applet will
    run, when i'm finished with it. this brings me to the question: does
    anybody know's how to sign my applet and give it full access to the
    harddrive and the webserver without paying 400$ to VeriSign for a
    commercial CA? i want to do this by myself, without paying anything
    and without giving a lot of information to another company.
    i would realy appreciate, if someone could give me a hint where i am
    wrong or how to do this correct.
    thank you very much
    [email protected]

    You hold several misconceptions. The first is that an applet can write to a server without help from the server. That will never work on a real server (though it might work in testing, if the server is on the same PC as the applet). Applets cannot get a File object that points to any place on the server.
    If you write a servlet designed for accepting image uploads, the applet can communicate back to that servlet and feed it the bytes of the image. There are other technologies that can replace the servlet, of course (PHP, ASP..) but I mention that because you say you are running Apache - and that is very Java oriented.
    For more help on servlets, try the [Web Tier APIs - Java Servlet|http://forums.sun.com/forum.jspa?forumID=33] forum.

Maybe you are looking for

  • Process of moving TR from Quality to Production

    Dear Experts, we are in a process of moving TR from Quality to Production. While moving we faced transport incositencies like some old requests have been overwritten into the new one and dependant objects were failed during import in PRD. Now product

  • Re: Network connection, but no internet connection

    I have a MacBook Pro, 10.6.8. I am set up ith Airport Extreme, and everything has worked great. All of a sudden I have no internet. I open up Airport Utilities and there is no Airport to be seen. I gave the Airport a Hard Reboot ( 5 seconds on the bu

  • Single session for all Application Modules

    Hello, I've got an application that has several Application Modules. All these modules need some data that are set from time to time. I've written some code that calls getSession().getUserData().put("myData",myData). After this method was called in a

  • Values in sample editor

    This may be a stupid question but in the sample editor what do the values on the side of the wave represent? I would think its a measure in mV but I'm not sure, I need to find out the decibel level of a recording I made so any help doing this would b

  • Problems using Adobe Application Manager

    I'm having problems signing in with Adobe Application Manager. Was working fine until yesterday, now it says it can't contact Adobe. I went through the help page (was able to access the adobe server site, etc.) but I was not able to resolve the issue