SerialVersionUID of a class that extends a serializable object

I have class Foo that implements Serializable. In Foo, I have manually hardcoded the serialVersionUID as: private static long serialVersionUID = -7589377069041161459L;Now I created a class SubFoo that extends Foo, but I have not overrided the serialVersionUID. However, when I run serialver command on SubFoo I get 2152116903368641813L, instead of my hardcoded serialVersionUID. Shouldn't I be getting my hardcoded value?
This is important to me because I am running into a Serialization Mismatch on about 100+ subclasses of Foo. So I was hoping to fix this by adding a hardcoded serialVersionUID into the one parent class and hoping not to manually change 100+ subclasses.

Now I created a class SubFoo that extends Foo, but I
have not overrided the serialVersionUID.When the compiler calculates the serialVersionUID, it hashes many things, including the fully qualified class name.
So, even though you may not have added any member variables, the serialVersionUID has changed because the class name has changed from Foo to SubFoo.
You need to manually specify / hardcode the serialVersionUID in all subclasses.
You can see section 12.24.4 of The Java Programming Language, 2nd Ed. for more details.
Best,
Garrett

Similar Messages

  • JEditorPane (or subclasses) and a class that extends JPanel

    hello to all,
    i'm realizing an application with Swing.
    i have realized a class that extends JPanel(called "PanelLayer") and, other to draw a ruler as Office 2003, it must contain an other subclass of JPanel (called "PanelLayer") that, in turn, will contain a JEditorPane.
    the problem is strange: i should continue in moviment the mouse to look well the JEditorPane (or subclasses)
    the URL is a image of the result that i get...
    URL : http://phantom89.helloweb.eu/img/img.jpg
    codes:
    public class Layer extends JPanel implements ComponentListener{
        private static final long serialVersionUID = 1L;
        private Rectangle2D.Double areaCentrale = new Rectangle2D.Double(100,100,850,1285);
        private double larghFoglio = 21.0*50;
        private double altFoglio = 29.7*50;
        private double zoom = 1.0;
        private JScrollPane sp = new JScrollPane(this);
        private Rectangle2D.Double posFoglio = new Rectangle2D.Double();
        private int lastX,lastY;
        private PanelLayer pl;
        private Point mouse = null;
        private JEditorPane text;
        public Layer(PanelLayer pl){
            this.setLayout(null);
            this.pl = pl;
            this.setPreferredSize(new Dimension((int)(40+larghFoglio*zoom), (int)(100+altFoglio*zoom)));
            areaCentrale = new Rectangle2D.Double(100*zoom,100*zoom,850*zoom,1285*zoom);
                sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
            sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            //try{
                text = new JEditorPane();
                text.setBounds(50,50,200,200);
                this.add(text);
            //}catch(IOException e){}
            lastX = sp.getHorizontalScrollBar().getValue();
            lastY = sp.getVerticalScrollBar().getValue();
            this.addComponentListener(this);
            this.addMouseListener(this);
            this.addMouseMotionListener(this);
        public void paintComponent(Graphics g){
            if(posFoglio.height + posFoglio.width == 0){
                this.posFoglio = new Rectangle2D.Double((this.getWidth()-larghFoglio*zoom)/2,50,larghFoglio*zoom,altFoglio*zoom);       
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(Color.lightGray);
            g2d.fillRect(0,0,this.getWidth(),this.getHeight());
            g2d.translate((this.getWidth()-larghFoglio*zoom)/2,50);
            g2d.setPaint(Color.black);
            g2d.draw(new Rectangle2D.Double(0,0,larghFoglio*zoom,altFoglio*zoom));
            g2d.setPaint(Color.white);
            g2d.fill(new Rectangle2D.Double(1,1,larghFoglio*zoom-1,altFoglio*zoom-1));
            g2d.setPaint(Color.blue);
            g2d.draw(areaCentrale);
        public JScrollPane getJScrollPane(){
            return sp;
        public Rectangle2D.Double getDimFoglio(){       
            return this.posFoglio;
        public double getCmWidth(){
            return larghFoglio*zoom/50+((larghFoglio*zoom/50)%1 <= getIncr() ? 0 : getIncr());
        public double getCmHeight(){
            return altFoglio*zoom/50+((altFoglio*zoom/50)%1 <= getIncr() ? 0 : getIncr());
        public Point getPointMouse(){
            return mouse;
        public void refresh(){
            lastX = sp.getHorizontalScrollBar().getValue();
            posFoglio.x = (this.getWidth()-larghFoglio*zoom)/2-lastX;
        public double getIncr(){
            return zoom/2;
        public void mouseClicked(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {}
        public void mouseExited(MouseEvent e) {}
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseDragged(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {
            mouse = e.getPoint();
            mouse.x -= sp.getHorizontalScrollBar().getValue();
            mouse.y -= sp.getVerticalScrollBar().getValue();
            pl.repaint();
        public void componentHidden(ComponentEvent e) {}
        public void componentMoved(ComponentEvent e) {
            lastX = sp.getHorizontalScrollBar().getValue();
            posFoglio.x = (this.getWidth()-larghFoglio*zoom)/2-lastX;
            lastY = sp.getVerticalScrollBar().getValue();
            posFoglio.y = 50-lastY;
            pl.repaint();
        public void componentResized(ComponentEvent e) {
            this.repaint();
            pl.repaint();
        public void componentShown(ComponentEvent e) {}
    public class PanelLayer extends JPanel implements MouseWheelListener,MouseInputListener{
        private static final long serialVersionUID = 1L;
        private Layer layer;
        private JScrollPane sp = null;
        private boolean visualizzaMouse = false;
        public PanelLayer(){
            this.setLayout(null);
            layer = new Layer(this);
            layer.addMouseListener(this);
            layer.addMouseMotionListener(this);
        public void paintComponent(Graphics g){
            if(layer.getDimFoglio().getWidth()+layer.getDimFoglio().getHeight() == 0){
                layer.setSize(50,50);
            if(sp == null){
                sp = layer.getJScrollPane();
                sp.addMouseWheelListener(this);
                sp.setBounds(30,30,this.getWidth()-30,this.getHeight()-30);
                this.add(sp);
            }else{
                layer.refresh();
            sp.setBounds(30,30,this.getWidth()-30,this.getHeight()-30);
            Graphics2D g2d = (Graphics2D)g;
            g2d.setPaint(new Color(153,255,153));
            g2d.fill(new Rectangle2D.Double(0,0,this.getWidth(),30));
            g2d.fill(new Rectangle2D.Double(0,0,30,this.getHeight()));
            g2d.setPaint(Color.black);
            g2d.drawLine(0,0,this.getWidth(),0);
            g2d.drawLine(0,30,this.getWidth(),30);
            g2d.drawLine(0,0,0,this.getHeight());
            g2d.drawLine(30,0,30,this.getHeight());
            for(double i=0,j=0;i<=layer.getCmWidth();i+=layer.getIncr(),j++){
                if(j%2==0){
                    g2d.drawLine((int)(layer.getDimFoglio().x+31+i*50), 15,(int)(layer.getDimFoglio().x+31+i*50), 30);
                    g2d.drawString(String.valueOf((int)(j/2)), (float)(layer.getDimFoglio().x+31+i*50), 13);               
                }else{
                    g2d.drawLine((int)(layer.getDimFoglio().x+31+i*50), 22,(int)(layer.getDimFoglio().x+31+i*50), 30);
            for(double i=0,j=0;i<=layer.getCmHeight();i+=layer.getIncr(),j++){
                if(j%2==0){
                    g2d.drawLine(15, (int)(layer.getDimFoglio().y+31+i*50),30,(int)(layer.getDimFoglio().y+31+i*50));
                    g2d.drawString(String.valueOf((int)(j/2)),5,(float)(layer.getDimFoglio().y+31+i*50));
                }else{
                    g2d.drawLine(22, (int)(layer.getDimFoglio().y+31+i*50),30,(int)(layer.getDimFoglio().y+31+i*50));
            if((layer.getPointMouse() != null)&&(visualizzaMouse)){
                g2d.drawLine(layer.getPointMouse().x+30,0,layer.getPointMouse().x+30,30);
                g2d.drawLine(0,layer.getPointMouse().y+30,30,layer.getPointMouse().y+30);
            g2d.setPaint(new Color(153,255,153));
            g2d.fillRect(1,1,29,29);
            int largh = layer.getJScrollPane().getVerticalScrollBar().getWidth();
            g2d.fillRect(this.getWidth()-largh, 1, largh, 29);
            g2d.fillRect(1, this.getHeight()-largh, 29, largh);
        public void mouseWheelMoved(MouseWheelEvent e) {
            JScrollBar vsb = layer.getJScrollPane().getVerticalScrollBar();
            vsb.setValue(vsb.getValue()+20*e.getWheelRotation());
        public void refresh(){
            if((layer != null)&&(sp != null)){
                layer.setSize(this.getWidth()-30,this.getHeight()-30);
                sp.setViewportView(layer);
                this.repaint();
        public void mouseClicked(MouseEvent e) {}
        public void mouseEntered(MouseEvent e) {
            visualizzaMouse = true;
            repaint();
        public void mouseExited(MouseEvent e) {
            visualizzaMouse = false;
            repaint();
        public void mousePressed(MouseEvent e) {}
        public void mouseReleased(MouseEvent e) {}
        public void mouseDragged(MouseEvent e) {}
        public void mouseMoved(MouseEvent e) {}
    }(my english isn't very good)

    Don't really understand what the posted code does and I can't execute the code so I don't have much to offer.
    But I did notice that you don't invoke super.paintComponent(...) which means you may have garbage being painted on the panels.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html

  • Can I invoke a class that extends JAppl from another class extends JAppl

    Can I invoke a class that extends JApplet from another class that extends JApplet. I need to invoke an applet then select an action which opens another applet. Thanks in advance.

    Nobody is able to solve this problem, i cant even
    think this things. i have hope so plz try and get
    result and help.Did you understand what Sharad has said???
    Yep, you can forward to specific error page from servlet when even error occured in JSP. In order to achieve you have to open jsp file from servlet say example by using reqdisp.forward.
    handle exception in the part where you are forwarding. And forward to the specific error page inside catch block.

  • Portlets development: When to use the class that extends PortletBridge...

    When I create some Portlet (.jspx based) JDeveloper generate some resources. One of those is a class (with the name that I´ve configured) that extends PortletBridge...
    Ok. So, I want to know if I use JSF standards should I put my actions into this class or should I create another Managed bean to handle that? What to do with this generated class?
    Thank you.

    So you want to create a portlet that uses JSF instead of JSP?
    You can JDev do that for you. When you create a new portlet there is a step where you can specify the default page for the portlet mode (view, edit).
    On the right hand side you can select ADF JSF (or something like that).
    JDev will then create a class that extends the PortletBridge class and you don't have to do anything more. Just edit the jspx like it's a normal page.

  • Can any one change this Applet into a class that extends Jpanel.....

    Hi,
    I need this applet as a class that extends JPanel, I will be very very thankful to you if any one kindly change this Applet code into a class that extends JApplet.
    I will be very thankful to you if some one can reserve few minutes & do this favor early.
    Thanks a lot for any help.
         My Pong Code
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.awt.event.*;
    public class Class1 extends Applet implements Runnable
    {     private final int APPLET_WIDTH = 900;
         private final int APPLET_HEIGHT = 600;
         private int px = 15;
         private final int py = 560;
         private final int ph = 10;
         private final int pw = 75;
         private int old_px = px;
         private int bx = 450;
         private int by = 15;
         private final int bh = 20;
         private final int bw = 20;
         private int move_x = 2;
         private int move_y = 2;
         private boolean done = false;
         Thread t;
         private final int delay = 25;
         public void init()
         {     setBackground(Color.black);
              setSize(APPLET_WIDTH, APPLET_HEIGHT);
              requestFocus();
              addKeyListener(new DirectionKeyListener());
             (t = new Thread(this)).start();
         public void run()      {
        try      {     while((t == Thread.currentThread()) && (done == false))           {     
                   if ((bx < 15) || (bx > APPLET_WIDTH-30))                     move_x = -move_x;                                if ((by < 15) ||                    ((by > APPLET_HEIGHT-60)&&                     ((px<=bx)&&(bx<=px+pw))))
                        move_y = -move_y;
                   if (by > APPLET_HEIGHT)
                        done = true;
                                   bx = bx + move_x;
                   by = by + move_y;                                                repaint();
                   t.sleep(delay);
         catch(Exception e)      {}
         }//end run
         /*public void move_paddle(int amount)
              old_px = px;
              //if (amount > 0)
                //if (px <= APPLET_WIDTH-15)
                   px = px + amount;
              //else if (amount < 0)
               // if (px >= 15)
                   px = px + amount;
         public void paint(Graphics page)
              //     page.setColor(Color.black);
              //     page.drawRect(old_px, py, pw, ph);
                   page.setColor(Color.blue);
                   page.drawRect(px, py, pw, ph);
                   page.setColor(Color.white);
                   page.drawOval(bx, by, bw, bh);
                   if ((done == true) && (by > APPLET_HEIGHT))
                        page.drawString("LOSER!!!", APPLET_WIDTH/2, APPLET_HEIGHT/2);
                   else if (done == true)
                        page.drawString("Game Over, Man!", APPLET_WIDTH/2-10, APPLET_HEIGHT/2);
         private class DirectionKeyListener implements KeyListener               
              public void keyPressed (KeyEvent event)
                   switch (event.getKeyCode())
                   case KeyEvent.VK_LEFT:
                        old_px = px;
                        if (px >=15)
                             px -=10;
                        break;
                   case KeyEvent.VK_RIGHT:
                        old_px = px;
                        if (px+pw <= APPLET_WIDTH-15)
                             px += 10;
                        break;
                   case KeyEvent.VK_Q:
                        done = true;
                   default:
                   }  //end switch
                   repaint();
              }//end keyPressed
              public void keyTyped (KeyEvent event)
              public void keyReleased (KeyEvent event)
         }  //end class 
    }

    thank you sir for your advice.
    Its not like that I without any attempt, just past code here & asked for its conversion. I spent about 5 hours on it, can say spoil whole day but to no avail. You then just guide me, give some hint so that I do it. I will most probably wanted to do it by myself but asked for help when was just disappointed.
    I try to put all init() in default constructor of identical copy of this applet that extends JPanel. Problem.....ball tend to fell but pad not moving. Also out out was not getting ant color input. That was like my best effort.....other tried that I found by search like just do nothing only extend panel OR frame in spite of applet, start applet from within main of another class.... these are few I remember what I tried.
    I will be very very thankful to you if you can help/guide me how can I do it. Behavior of the Applet is like a normal PONG game with on pad controlled by arrow keys, & one ball colliding with walls of boundary & falling down.
    Thanks a lot again for your attention & time.

  • Using the UI editor  for a class that extends an abstract class

    Hi,
    At the moment it's unfortunately impossible to use the UI editor to edit a class that extends a certain abstract class. There is a way to circumvent this problem, by using a proxy class. Does anyone know how to create a proxy class for this purpose and how to register it?
    Hopefully a future JDeveloper release will solve this problem. Is this a planned feature?
    Regards,
    Peter

    I hope it works for you now (why using , but not indentation?).                                                                                                                                                                                           

  • Closing a class that extends JPanel

    Hi, i have a class that extends JPanel(lets call it class A). In that class, if the user click the logout button, i want class A to close and display class B that extends JFrame. right now, i am able to call class B, but i cannot close class A.
    I uses remove() to close class A, but it doesnt work... could u tell me what to do??
    I put this code in class A...
    if (e.getSource() == logoutButton)     {
         remove(this);
         new Rest_Login1();
         String [] ar = null;
         Rest_Login1.main(ar);
    } Thx

    so i want to remove the CustomerPanel3 and display the Rest_Login1...
    some of my code look like this.
    thx
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class CustomerPanel3 extends JPanel implements ActionListener
    // some JButton, JLabel n etc
         public void actionPerformed (ActionEvent e)
              if (e.getSource() == logoutButton)     {
                   remove(this);
                   new Rest_Login1();
                   String [] ar = null;
                   Rest_Login1.main(ar);
    public class Rest_Login1 {
         public static void main(String args[])
              JFrame login1 = new JFrame("Login User Interface");
              JFrame.setDefaultLookAndFeelDecorated(true);
              RestaurantLogin userpan = new RestaurantLogin();
              login1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              login1.setSize(600, 250);
              login1.setLocation(230,192);
              login1.getContentPane().add(userpan);
              login1.setVisible(true);
    }

  • How to call a class that extends a frame from a panel ?

    How to call a class that extends a frame from a panel ?
    I am trying to create an application say "Videoshow"
    Videoshow has a panel which in turn consists of 2 components : 1]a textarea( to show the contents of a page) and 2] a mediaclip(to show the video).
    Now I have an application "MediaApplication"(to show the videoclip) which extends Frame (Code from Java 2 Unleashed, Chap 21). I want to show this MediaApplication in Component 2 of the above panel. But when I do this, I only see the MediaApplication frame instead of the whole SlideShow.
    I want to do something likethis.
    VideoShow :
    |---------------------------------|-------------------|
    | |
    | (Comp 1) | (Comp 2)
    | TEXTAREA | Video Clip
    | |(MediaApp entends Frame)
    |---------------------------------|-------------------|
    What is the best way to achieve this ? Also which component can I use to show the videoclip ?

    im not familiar with the code you mention from Java 2 Unleashed, but your best bet is to read up on Swing a bit - so you get an idea of how Swing containers and components work - then im sure you'll find a solution to your problems. Then if you encounter any difficulties whilst your attempting to do that, post your code in the Swing forum and im sure someone will help you.

  • Xml Serializing a class that extends JPanel

    Alright I am getting an Exception saying java.
    java.lang.reflect.InvocationTargetException
    Continuing ...
    java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(JpanelScreen);
    Continuing ...
    is anyone familiar with this... It ocurrs when I try to Serialize my class object that extends JPanel...

    any examples of how to do this?
    try {
    java.beans.XMLEncoder out = new java.beans.XMLEncoder( new BufferedOutputStream( new java.io.FileOutputStream(getFilename())));
    out.writeObject(Screen);
    out.close();
    }catch (Exception exc) {System.err.println(exc.getMessage());}

  • Calls to methods in a class that extends Thread

    Hello,
    I have some code that I am initiating from within an ActionListener that is part of my programs GUI. The code is quite long winded, at least in terms of how long it takes to perform. The code runs nicely, however once it is running the GUI freezes completely until operations have completed. This is unacceptable as the code can take up to hours to complete. After posting a message on this forum in regard to the freezing of the GUI it was kindly suggested that I use multi-threading to avoid the unwelcome program behaviour.
    The code to my class is as follows:
    public class FullURLAddress
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    I have changed the above code to make use of multithreading by making this class extend Thread and implementing the run() method as follows:
    public class FullURLAddress extends Thread
      private boolean success_flag = true;
      private BufferedReader iN;
      private Document dT;
      private EditorKit kT;
      private Element lmNt;
      private ElementIterator lmIterate;
      private XURL[] compAddress;
      private int countX = 0;           //Tracks Vector vT's size.
      private int countY = 0;           //Tracks Vector vS's size.
      private int xURLcount = 0;        //Tracks XURL objects instantiated by this FullURLAddress object.
      private SimpleAttributeSet simpAtSet;
      private String aURL;              //Contains original (Xtended) URL!
      private String fileType;
      private String indexContent;
      private String[] parseURL;
      private String[] finalStrings;
      private String[] sortStrings;
      private URL indexConnect;
      private URLConnection iconn;
      private Vector vT;            //Stores href information, from targeted URL's HTML souce code.
      private Vector vS;            //Stores sorted HREF info ".jpg" and ".gif" only (no: png, tiff, etc).
      public FullURLAddress(String aURL)
        this.aURL = aURL;
      public void run()
        try{
          indexConnect = new URL(aURL);
          iconn = indexConnect.openConnection();
          iN = new BufferedReader(new InputStreamReader(iconn.getInputStream()));
            /* Document creation, analysis objects instantiated */
          vT = new Vector();
          vS = new Vector();
          kT = new HTMLEditorKit();
          dT = kT.createDefaultDocument();
          dT.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
            /* Iterate through document and store all HREF values */
          kT.read(iN, dT, 0);
          lmIterate = new ElementIterator(dT);
          while((lmNt = lmIterate.next()) != null)
            simpAtSet = (SimpleAttributeSet)lmNt.getAttributes().getAttribute(HTML.Tag.A);
            if(simpAtSet != null)         //As long as there are A tags to be read...
              vT.addElement(simpAtSet.getAttribute(HTML.Attribute.HREF));
              countX++;//Tracks number of HREF occurences occur, giving better control of the Vector.
        }catch(MalformedURLException e){
          success_flag = false;
          System.out.println("FullURLAddress object has encountered a "+
                             "MalformedURLException at: "+aURL);
        }catch(IOException e){
          e.getMessage();
          success_flag = false;
        }catch(BadLocationException e){
          e.getMessage();
          success_flag = false;
        /* Searches through all HREF attributes that are now stored in Vector
           vT for occurences of the character string ".htm" */
        sortStrings = new String[countX];
        for(int i=0;i<countX;i++)
          sortStrings[i] = (String)vT.elementAt(i); //Vector Strings transfered into array.
          if(sortStrings.endsWith("gif")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("GIF"))
    vS.addElement(sortStrings[i]);
    countY++;
    if(sortStrings[i].endsWith("jpg")) // Does href value end with ".jpg"?
    vS.addElement(sortStrings[i]); // If so add it to the sorted Vector vS.
    countY++;
    if(sortStrings[i].endsWith("JPG"))
    vS.addElement(sortStrings[i]);
    countY++;
    finalStrings = new String[countY];
    for(int j=0;j<countY;j++)
    finalStrings[j] = (String)vS.elementAt(j);
    /* What happens with these methods, will they need to have their
    own treads also? */
    public int getCount()
    return countY; //Returns number of instances of htm strings
    } //ending with either "jpg" or "gif".
    public String[] xurlAddressDetails()
    return finalStrings;
    Are there any special things that I need to do in regard to the variables returned by the getCount() and xurlAddressDetails() methods. These methods are called by the code that started the run method from within my GUI. I don't understand which thread these methods are running in, obviously there is an AWT thread for my GUI and then a seperate thread for my FullURLAddress objects, but does this new thread also encompass the getCount() and xurlAddressDetails() methods?
    Please explain.
    This probably sounds a little wack, but I don't understand what thread is responisble for the methods in my FullURLAddress class aside of course from the run() method which is obvious. Any help will be awesome.
    Thanks
    Davo

    Threads are part of code that allows you to run multiple operations "simultaneously". "Simultaneously", because threads are not run actually simultaneously in any one-CPU machine. Since you most propably have only one CPU in your system, you can only execute one CPU instruction at time. Basically this means that your CPU can handle only one java-operation at time. It does not matter if you put some code in thread and start it, it will still take up all CPU time as long as the thread runs.
    So you would need a way to let other threads run also, for that purpose thread contains a yield feature that allows you to give time for other threads to run.
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Thread.html#yield()
    You need to use thread's yield() method in your thread code, in a place you want to give other threads time to run. Also bear in mind that if you yield your first thread run to allow second thread to run, you also need to add yield to the second thread also. If you don't, after yielding the first thread, the second thread will eat up all CPU time until it finishes, thus meaning the rest of your first thread will be run after second thread is done.
    One good place to execute yield() is usually at the end of a loop, for example 'for' or 'while' loop. This way you prevent for example while-deadlocks.
    Here is a java thread tutorial, worthy reading:
    http://java.sun.com/docs/books/tutorial/essential/threads/

  • How to set the size of a class that extends JDialog

    Hi,
    I was trying to set the size of my dialog window to be 600 by 600, but couldn't change it. Here is my code:
    public class alii extends JDialog {
    /** Creates new form alii */
    public alii(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    private void initComponents() {
    Container contentPane = getContentPane();
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    closeDialog(evt);
    pack();
    public static void main(String args[]) {
    JFrame frame = new JFrame();
    alii a = new alii(new javax.swing.JFrame(), true);
    frame.setSize(600,500);
    frame.setLocation(200,200);
    frame.setVisible(true);}}
    Please help me with this and explain to me what is the problem and what needs to be changed.
    Cheers

    Hi,
    The code you sent me doesn't work, and the code I posted wasn't a complete, but there is the complete one. You can see now what the code does.
    * alii.java
    * Created on 15 November 2003, 13:31
    * @author Ali
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.sql.*;
    import java.util.*;
    import java.io.*;
    import java.applet.*;
    import java.net.*;
    public class sun extends JDialog {
    int x[] = new int[4];
    int y[] = new int[4];
    int w[] = new int[4];
    int h[] = new int[4];
    int Y_ax = 310;
    double DrawGraf[][] = new double[4][4];
    String line[] = new String[9];
    double Perc[] = new double[4];
    double Sum=0;
    GUICanvas can;
    double graphvalue[] = new double [5];
    /** Creates new form alii */
    public sun(Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    //setVisible(true);
    //setSize(600,500);
    //setLocation(200,200);
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {
    //Container contentPane = getContentPane();
    addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
    closeDialog(evt);
    //contentPane.setSize(700,700);
    //pack();
    public void drawthegraph(String s)
    /* try {
    URL url = new URL(
    "http://localhost:111/test/servlet/Compare?value="+s);
    BufferedReader in = new BufferedReader(
    new InputStreamReader(url.openStream()));
    for (int c = 0; c<9; c++)
    line[c] = in.readLine();
    in.close();
    }catch (Exception e){
    e.printStackTrace();
    graphvalue[0] = 200;
    graphvalue[1] = 200;
    graphvalue[2] = 100;
    graphvalue[3] = 300;
    graphvalue[4] = 20;
    //graphvalue[4] = can.d2i(graphvalue[4]);
    //System.out.println(line[8]);
    Sum = graphvalue[0]+graphvalue[1]+graphvalue[2]+graphvalue[3];
    Perc[0] = graphvalue[0]/Sum*200;
    Perc[1] = graphvalue[1]/Sum*200;
    Perc[2] = graphvalue[2]/Sum*200;
    Perc[3] = graphvalue[3]/Sum*200;
    System.out.println(Perc[0]);
    DrawGraf[0][0] = 130;
    DrawGraf[0][1] = Y_ax - Perc[0];
    DrawGraf[0][2] = 60;
    DrawGraf[0][3] = Perc[0];
    DrawGraf[1][0] = DrawGraf[0][0]+60;
    DrawGraf[1][1] = Y_ax - Perc[1];
    DrawGraf[1][2] = 60;
    DrawGraf[1][3] = Perc[1];
    DrawGraf[2][0] = DrawGraf[1][0]+60;
    DrawGraf[2][1] = Y_ax - Perc[2];
    DrawGraf[2][2] = 60;
    DrawGraf[2][3] = Perc[2];
    DrawGraf[3][0] = DrawGraf[2][0]+60;
    DrawGraf[3][1] = 310 - Perc[3];
    DrawGraf[3][2] = 60;
    DrawGraf[3][3] = Perc[3];
    for(int d=0;d<4;d++)
    x[d]=d2i(DrawGraf[d][0]);
    y[d]=d2i(DrawGraf[d][1]);
    w[d]=d2i(DrawGraf[d][2]);
    h[d]=d2i(DrawGraf[d][3]);
    repaint();
    static int d2i(double d) {return (int) Math.round(d);}
    public void paint (Graphics g)
    g.setColor(Color.red);
    for(int d=0;d<4;d++)
    g.fill3DRect(x[d],y[d],w[d],h[d],true);
    g.setColor(Color.blue);
    g.drawLine(130,130,130,310);
    g.drawLine(130,310,370,310);
    g.setColor(Color.black);
    g.drawString("WELCOME TO Ali",150,100);
    g.drawString("Region: Lambeth",430,150);
    g.drawString("Manger: ",430,170);
    g.drawString("Location: ",430,190);
    g.drawString("Number of Staff: "+graphvalue[4],430,210);
    g.drawString("Week1",135,345);
    g.drawString("Week2",195,345);
    g.drawString("Week3",255,345);
    g.drawString("Week4",315,345);
    g.drawString(" "+"20 -",100,295);
    g.drawString(" "+"40 -",100,255);
    g.drawString(" "+"60 -",100,215);
    g.drawString(" "+"80 -",100,175);
    g.drawString("100 -",100,135);
    g.setColor(Color.yellow);
    g.drawLine(130,290,370,290);
    g.drawLine(130,250,370,250);
    g.drawLine(130,210,370,210);
    g.drawLine(130,170,370,170);
    g.drawLine(130,130,370,130);
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {
    setVisible(false);
    dispose();
    * @param args the command line arguments
    public static void main(String args[]) {
    JFrame frame = new JFrame();
    sun sn = new sun(frame, true);
    frame.setSize(600,500);
    frame.getContentPane().add(sn);
    frame.setLocation(200,200);
    frame.setVisible(true);
    You were right that I am know to this, but getting there slowly and thanks for your help.
    Cheers

  • Pass a value to a class that extends AbstractTableModel

    Hi
    I have a problem with a table model that I cannot find a way of overcoming.
    I have created a class called MyTableModel that extends AbstractTableModel.
    MyTableModel creates and uses another class that I have defined in order to retrieve records from a database, MyTableModel fills the table with these records.
    However, I wish to alter my class in order to provide an int parameter that will act as a �where� value in the classes sql query.
    The problem is this, I cannot work out how to pass a value into MyTableModel. I have tried creating a simple constructor in order to pass the value but it doesn�t work.
    My code is shown below:
    import BusinessObjects.JobItemClass;
    import DBCommunication.*;
    import java.util.ArrayList;
    import javax.swing.table.AbstractTableModel;
    public class MyJobItemTableModel extends AbstractTableModel
      public MyJobItemTableModel(int j)
          jobNo = j;
      int jobNo;
      JobAllItems jobItems = new JobAllItems(jobNo);
      ArrayList items = jobItems.getItems();
      String columnName[] = { "Item Number", "Item Description", "Cost per item", "Quantity" };
      int c = items.size();
      Class columnType[] = { Integer.class, String.class, Double.class, Integer.class };
      Object table[][] =  new Object[c][4];
      public void fillTable()
          if(c > 0)
            for (int i = 0; i < c; i = i + 1)
              this.setValueAt(((JobItemClass) items.get(i)).getItemNumber(), i, 0);
              this.setValueAt(((JobItemClass) items.get(i)).getDescription(), i, 1);
              this.setValueAt(((JobItemClass) items.get(i)).getCostPerItem(), i, 2);
              this.setValueAt(((JobItemClass) items.get(i)).getQuantity(), i, 3);
      public void setJobNo(int s)
          jobNo = s;
      public int getColumnCount()
          if(c > 0)
            return table[0].length;
          else
              return 0;
      public int getRowCount()
        return table.length;
      public Object getValueAt(int r, int c)
        return table[r][c];
      public String getColumnName(int column)
        return columnName[column];
      public Class getColumnClass(int c)
        return columnType[c];
      public boolean isCellEditable(int r, int c)
        return false;
      public void setValueAt(Object aValue, int r, int c)
          table[r][c] = aValue;
    }Any advice will be appreciated.
    Many Thanks
    GB

    your JobAllItems is created before constructor code is run (since it is initialized in class member declaration)
    use something like
    public MyJobItemTableModel(int j)
          jobNo = j;
          items = (new JobAllItems(jobNo)).getItems();
          c = items.size();
          table =   new Object[c][4];
      int jobNo;
      ArrayList items;
      String columnName[] = { "Item Number", "Item Description", "Cost per item", "Quantity" };
      int c;
      Class columnType[] = { Integer.class, String.class, Double.class, Integer.class };
      Object table[][] ;instead of
    public MyJobItemTableModel(int j)
          jobNo = j;
      int jobNo;
      JobAllItems jobItems = new JobAllItems(jobNo);
      ArrayList items = jobItems.getItems();
      String columnName[] = { "Item Number", "Item Description", "Cost per item", "Quantity" };
      int c = items.size();
      Class columnType[] = { Integer.class, String.class, Double.class, Integer.class };
      Object table[][] =  new Object[c][4];

  • ClassCastexception when casting a Class that extends HttpServletRequestWrap

    I have inherited some code that runs OK in JDK 1.4.2 in a JSP, but give s an exception when the JSP runs unfer 1.5.0. My Class is a as follows:
    public class WrappedRequest extends HttpServletRequestWrapper {
         public WrappedRequest(HttpServletRequest req) {
              super(req);     
         /** Return value string of requested parameter.
         * <ul>
         * <li> If htmlEncode == NO_HTML_ENCODE, return the native request param, un-html encoded
         * <li> If htmlEncode == HTML_ENCODE, return an html encoded copy of the requested parameter
         * <li> If htmlEncode is neither, return the html encoded copy of the requested parameter     
         * </ul>
         * @param     name               name of the request parameter
         * @param     htmlEncode          whether html encoded/un-encoded parameter value should be returned.
         * @return     String of the requested parameter value. If parameter name is null, return null
         public String getParameter(String name, int htmlEncode) {
              if(name != null && (htmlEncode == NO_HTML_ENCODE)) {
                   String str = super.getParameter(name);
                   return str;
              else
                   return getParameter(name);     
         public String getParameter(String name) {
              String str = super.getParameter(name);
              if(str != null)
                   str = Utils.htmlEncode(str); //Another package class
              return str;               
    This class in normally invoked as follows:
         String changeApproval = ((WrappedRequest)request).getParameter("CrApp" , WrappedRequest.NO_HTML_ENCODE);
    I get a ClassCastException exception on this line. Any suggestions?
    Regards,

    Stuart_Millington wrote:
    Further to my original post I have another question. Please bear in mind that I am fairly new to Java and this is code that I have inherited. In the following line of code (which is the line that causes the exception:
    String changeApproval = ((WrappedRequest)request).getParameter("CrApp" , WrappedRequest.NO_HTML_ENCODE);
    Why is the request being cast? The following code SEEMS to run OK:
    WrappedRequest wr = new WrappedRequest(request);
    String CrApproval = wr.getParameter("CrApp" , WrappedRequest.NO_HTML_ENCODE);
    Any ideas?
    Regards,
    Stuart MillingtonOkay, then I understand your problem.
    You can only cast request to WrappedRequest when request IS A WrappedRequest - ie the statement request = new WrappedRequest(request) was called. You are apparently trying to convert a default implementation of HttpServletRequest into a WrappedRequest without first 'Wrapping' the request.
    What does Wrapping a Request mean and do? A request object is generated by the servlet container and it isn't easy to switch in your own implementation. So instead you make a WrappedRequest which takes the original instance of the HttpServletRequest generated from by the container and adds functionality to it. A WrappedRequest would have to extend an HttpServletRequest, and implement all the public API of said parent class. Most of the time the methods would look something like this:
    public String getParameter(String key) { return this.parentRequest.getParameter(key); } That is, it simply delegates most of the work to the HttpServletRequest it is wrapping. But some functions it may want to change behavior for and for those you insert your implementation.
    What you need to do:
    1) Learn how to use Java before you touch Servlets and server side stuff. You are adding too much complication by going straight to the end game. Use a book and the tutorials to get you through.
    2) Take the time to run the JavaEE tutorial.
    3) Start with your own code. Taking code snippets you see around the net and trying to get them to work is tough when you don't understand the concepts. For example, using a WrappedRequest is normally fairly useless if it isn't implemented using a Filter, and they work the best when they don't require a change to the request interface (i.e. when you never actually have to do a cast). Since you don't know Filters, and don't yet understand how the wrapper works I would suggest not using them.
    This is probably a mis-use of the RequestWrapper idea anyway (since, like I said, it requires a change in interface). What you would be better off doing is simply choosing to pass the parameter through a utility function that does the encoding for you. Example like:
    String changeApproval = HTMLEncoder.encode(request.getParameter("CrApp");when you want the parameter encoded and
    String changeApproval = request.getParameter("CrApp");when you don't.
    If you don't want to make your own utility for this purpose (and why would you) you can download a library that does it for you. One example is the [org.apache.commons.lang.StringEscapeUtils#escapeXML|http://commons.apache.org/lang/apidocs/org/apache/commons/lang/StringEscapeUtils.html#escapeXml(java.lang.String)] class#method from the Apache Foundation. The StringEscapeUtils is part of the Apache Commons Lang project, which you can reach [At the Commons/lang website.|http://commons.apache.org/lang/]

  • AS3.0: How to extend a class that extends MovieClip

    When I try to set the base class of a library symbol to a
    class that doesn't DIRECTLY extend MovieClip, but instead extends
    another class that DOES extend MovieClip, it's disallowed, saying,
    "The class 'Whatever' must subclass 'flash.display.MovieClip' since
    it is linked..."
    Is this just a validation bug in the property windows, only
    checking one class deep into the inheritance hierarchy? Because the
    specified class does extend MovieClip, just two levels in instead
    of one. Is there a fix for this? Or must library symbols always
    directly extend MovieClip? If so, why?

    Which classes from flash.display have you imported. Just
    because a class extends another doesn't mean that it inherits all
    of its properties. Saying a class extends sprite doesn't give you
    access to all of it's properties, members and display unless you
    first import flash.display.* or flash.display.Sprite. If you aren't
    already importing flash.display.*, try importing
    flash.display.MovieClip and see what happens...

  • Japplet is not able to call a class that extends JFrame in internet Explore

    Hi
    I am doing an application on Japplet.The Japplet class calls anathor class which extends JFrame.When I am running this appication on Applet Viewer it works fine.but when I am running this aplication in internet Explorer the Frame window doesn't come.What might be the problem.
    Thanks
    Srikants

    There is no error or exceptio comming when i am running that application on Internet Explorer.Convert the html page to use the object tag instead of the applet tag.
    The IE build in jre (called msjvm) cannot display JFrame since the version is
    1.1.2 and it has no javax classes.
    Still problems?
    A Full trace might help us out:
    http://forum.java.sun.com/thread.jspa?threadID=656028

Maybe you are looking for

  • RFC Lookups in SP10`

    Hi all, my requirement is based on PO I need to retrieve the corresponding TAXCodes. For this I wrote an FM to fetch taxcodes based on PO. In Xi part what needs to be done let me know. Thanks Srinivas

  • SAP Script :  Date is Boxes ??

    Dear All, I wanted to print date in boxes. i,e MM DD YY in boxes. I am doing like this. /: SET DATE MASK = 'MM.DD.YY' and then playing with Box Command, to draw vertical lines in between DD, MM and YY... with BOX HEIGHT '0.5' CM FRAME 10 TW BOX XPOS

  • LR 2.2 - Can't open catalog  (AgLibraryRootFolder error)

    I have a catalog that opens and works fine in LR 2.1. When I try to open it in LR 2.2, I get the dialog : Lightroom Database "D:\Children.lrcat": column absolutePath is not unique Statement: INSERT INTO AgLibraryRootFolder( id_local, id_global, absol

  • How to nudge in very small increments

    Hi all. Have recently switched from Quark XPress to inDesign CC2014. How do you nudge/move an object in fine increments? In Quark it was option + arrow keys, and option command + arrow keys to move in even finer increments.

  • MRP:regeneration of pr

    MRP was run in my company and a pr was generated and this pr was converted to po but grn against this po has not been done.But on running the mrp again another pr was generated for the same material for the same quantity and this pr is shown in the m