Vector in Vector help

Hi, I'm trying to make a 2 dimensional vector, and I'm having problems accessing the inside vector. Here's an example of what I'm trying to do:
slist.firstElement().addElement(new Long(current));
err, slist is a vector that holds another vector as its first element. I'm still a little iffy on the reference deals in java, if I set a vector equal to firstElement, change things with that first one, will it affect the one inside slist as well? Also, if I then reuse that name (the one outside the array), will that affect the list inside slist? The latter I don't think will, but better to be safe than sorry.
Thanks!

Hi, I'm trying to make a 2 dimensional vector, and I'm
having problems accessing the inside vector. Here's an
example of what I'm trying to do:
slist.firstElement().addElement(new Long(current));that will work fine.
err, slist is a vector that holds another vector as
its first element. I'm still a little iffy on the
reference deals in java, if I set a vector equal to
firstElement, change things with that first one, will
it affect the one inside slist as well? Also, if I
then reuse that name (the one outside the array), will
that affect the list inside slist? The latter I don't
think will, but better to be safe than sorry.whenever you are dealing with references, and you have two references that are talking about the exact same object the changes you make via one reference will be visible by the other - it is very similar to the following:
Vector v1 = new Vector();
v1.addElement( "Foo" );
Vector v2 = v1;
v2.addElement( "Bar" );
System.out.println( v1 ); // will print [Foo, Bar]v1 and v2 are references to the same object here, so a change via one results in a change to the other.

Similar Messages

  • Vector help

    hi
    im making a level editor for my breakout game now
    and I use a vector to store the game objects..
    However when painting I want to go through the vector and call
    each objects draw method..but that doesnt work. Im just used to use arrays but they cant hold objects of different types so thats a problem.
    What should I do? I just want to reference an object in the vector and call the method to draw it.

    If you look at the JavaDocs, you'll note that everything extends java.lang.Object. So what does this mean? It means, we can mix types in an array. :-)
    Object[] stuff = new Object[10];
    populateArray(stuff);
    for(int i=0; i<stuff.length; i++)
        if(stuff[i] instanceof String) System.out.println("First three characters of "+ stuff[i] +" are "+((String)stuff).subString(0, 3));
    if(stuff[i] instanceof Integer) System.out.println(stuff[i]+" + 1 = "+(((Integer)stuff[i]).intValue()+1));
    Of course, that's rather inefficient. That's why we have interfaces. Let's say you had the following interface:
    public interface Drawable
        public void draw(int x, int y, Graphics g);
    }We'll assume that you have two classes, Block1 and Block2. That means you can do this:
    public void paint(Graphics g)
        Drawable[] items = new Drawable[2];
        items[0] = new Block1();
        items[1] = new Block2();
        for(int i=0; i<items.length; i++) items.draw(i*10, 0, g);
    Does that help?
    P.S. The forums converts brackets like stuff[ i ] into stuff<i>

  • JTrees Vectors Help

    Can anyone give some advice on how to implement a JTree using a vector and adding tree listner's or a good site to reference. I have scourge many sites trying to find what I am looking for but I can never find an example containing both actions. What I am looking for is a way to nodes such as Titles, Genre,Rating,Cast, Directors, Year..etc. To note this is being used to house movies. However, I want to set it up so a movie may be in multiple nodes. For example, Star Wars II would be in the node Titles, Genre node containing an Action node, Rating node containing a PG-13 node, ...etc. I want to press the leafs (being movies of a particular node) to display in another panel with the Movies details. My biggest hang up seems to stem from the .getUserObject(). How does the Jtree and the information I need in the vector establish the desired connection. Any help would be appreciated.

    did you read
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html?
    hth

  • "digesting" protein strings - need vector help!

    Alright, here's my problem. I've got a GUI up and running to accept a long protein string, which will look like this (no breaks):
    G D V E K G K K I F V Q K C A Q C H T V E K G G K H K T G P N L H G L F G R K T G Q A P G F S Y T D A N K N K G I T W G E E T L M E Y L E N P K K Y I P G T K M I F A G I K K K G E R E D L I A Y L K K A T N E
    The gui offers a number of different proteases which are just things that cut the protein in certain places.
    For example, the protease Trypsin will cut the string after every K.
    What I need to do is write a method to cut the string after every K, save that sring to a vector, and continue with the remainder of the original protein string until there's no letters left.
    My problem is that I really don't know how to use vectors, and I don't know what this method should look like! Can anyone help? Thanks!

    if you want to keep the 'K' you will want to do this
    import java.util.*;
    public class Prot {
      public static void main(String[] args) {
        String str = "G D V E K G K K I F V Q K C A Q C H T V E K G G K H K T G P N L H G L F G R K T G Q A P G F S Y T D A N K N K G I T W G E E T L M E Y L E N P K K Y I P G T K M I F A G I K K K G E R E D L I A Y L K K A T N E";
        StringTokenizer stoken = new StringTokenizer (str, "K");
        List prots = new ArrayList();
        while (stoken.hasMoreTokens()) {
          String thisProt = stoken.nextToken();
          if (stoken.hasMoreTokens()) thisProt += "K";
          prots.add (thisProt);
          System.out.println("str = " + thisProt);
    // iterate the list
        Iterator it = prots.iterator();
        while (it.hasNext()){
          String dd = (String) it.next();
          System.out.println(dd);

  • Throws infinite-loop error after cycline through Vector - HELP!!!

    public void paint(Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    xpos = (getSize().width - fm.stringWidth(((String[])parseVector.elementAt(kount))[1])) / 2;
    if (ypos >= getSize().height || ypos <= 0) {
    g.drawString("", 0, 0); // CLEAR THE APPLET
    ypos = getSize().height;
    if (kount <= parseVector.size()) {
    kount++;
    } else {
    kount = 0;
    g.drawString(((String[])parseVector.elementAt(kount))[1], xpos, ypos);
    class ScrollNews implements Runnable {
    public void run() {
    while (true) {
    ypos = ypos - 1;
    ParseNews.this.repaint();
    try {
    Thread.sleep(50);
    } catch (InterruptedException e) {}
    I don't know why this breaks after working one time through the Vector parseVector, what am I missing????
    Phil

    public void paint(Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    xpos = (getSize().width -
    fm.stringWidth(((String[])parseVector.elementAt(kount))
    1])) / 2;
    if (ypos >= getSize().height || ypos <= 0) {
    g.drawString("", 0, 0); // CLEAR THE APPLET
    ypos = getSize().height;
    if (kount <= parseVector.size()) {
    kount++;
    } else {
    kount = 0;
    g.drawString(((String[])parseVector.elementAt(kount))[
    ], xpos, ypos);
    class ScrollNews implements Runnable {
    public void run() {
    while (true) {
    ypos = ypos - 1;
    ParseNews.this.repaint();
    try {
    Thread.sleep(50);
    } catch (InterruptedException e) {}
    I don't know why this breaks after working one time
    through the Vector parseVector, what am I missing????
    PhilI think your problem is here:
    while (true) {You have an infinite loop - how will the while loop ever be false?

  • Raster to Vector help with Live Trace

    Hello All,
    When I convert a raster to vector with Live Trace the result is great but I want to reduce the number of points so I get less layers when I import it into Painter. Can anyone advise on how to do this?
    Rayne

    Jacob Bugge wrote:
    I know nothing about Painter. Is it from the same company as is Worst?
    Jacob...
    Shame! I would have thought that, at the very least,  you knew that Painter existed! Oh! Woe is the world, woe is the world!!

  • Read data from Vector object serialized in a file issue!!

    Hi all,
    I have two classes :CBase and CHelper class in a package and serializing some information in a file and then reading it. I am facing some problem while reading the data
    which was stored using vector of objects. Below is the detailed problem:::::
    ////////////CHELPER
    public class CHelper implements Externalizable, Cloneable {
    public string szname;
    //..other functions writeexternal read external
    ////////////CBASE
    public class CBase
    implements Externalizable, Cloneable {
    protected boolean bRead;
    protected boolean bWrite;
    protected Vector vData;
    public void addInstance(CHelper obj) {
    vData.addElement(obj);
    //..other functions writeexternal read external
    I am Serializing all the CBase information in a file and trying to read the contents from this serialized file::::
    CBase base = new CBase();
    CHelper obj = new CHelper();
    obj.setName("HELPER");
    base.addInstance(obj); // ADDING THE OBJECT DATA INTO THE VECTOR
    base.bRead = true;
    base.bWrite = true;
    // Writing to the file
    FileOutputStream fs = new FileOutputStream("d:\\temp\\Base.txt");
    ObjectOutputStream os = new ObjectOutputStream(fs);
    os.writeObject(base);
    os.close();
    //reading from the file
    FileInputStream fi = new FileInputStream("d:\\temp\\Base.txt");
    ObjectInputStream oi = new ObjectInputStream(fi);
    CBase read = (CBase) oi.readObject();
    PRINTING THE OUTPUT
    System.out.println("Vector = " + read.vData.firstElement().toString());
    System.out.println("Write = " + read.bRead);
    System.out.println("Read = " + read.bWrite);
    The output is something like:
    Vector = com.sp.CHelper@14b7453 // WHAT IS THIS ?? GARBAGE ?? NOT ABLE TO ANALYSE :(
    Write = true;
    Read = true;************
    MY PROBLEM:
    i.e How to get the information stored in the Vector ? I am getting something "com.sp.CHelper@14b7453 " whereas the expected output should be Vector = HELPER. I am
    writing and reading the vector as follows:
    // CHELPER
    public void writeExternal(ObjectOutput out) throws IOException {
    out.writeUTF(szName.toString());
    public void readExternal(ObjectInput in) throws IOException,
    ClassNotFoundException {
    setName(in.readUTF());
    Externalize in CBase Classs
    out.writeInt(getInstanceCount()); // getting number of objects in the vector
    for (int index = 0; index < getInstanceCount(); index++) {
    out.writeObject((CHelper)vData.get(index));
    out.writeBoolean(bWrite);
    out.writeBoolean(bRead);
    And reading like this::
    int iNumberofInstances; // number of instances
    iNumberofInstances = in.readInt();
    vData.clear();
    // Get the CHelper object and add it into the CFeatureBase vector
    for (int i = 0; i < iNumberofInstances; i++) {
    CHelper objbase = (CHelper)in.readObject();
    vData.add(objbase);
    this.bWrite = in.readBoolean();
    this.bRead = in.readBoolean();
    I suppose that i am correctly WRITING AND READING the data. B/w what can be the problem. All suggestions are welcome/
    Thanks,
    Rohit

    Vector = com.sp.CHelper@14b7453 // WHAT IS THIS ??
    GARBAGE ?? NOT ABLE TO ANALYSE :(
    Write = true;
    Read = true;************
    MY PROBLEM:
    i.e How to get the information stored in the Vector
    ? I am getting something "com.sp.CHelper@14b7453 "
    whereas the expected output should be Vector =
    HELPER.This is perfectly normal behaviour if your CHelper class doesn't override the toString() method. The default toString() method in Object just prints the name of the class and a hex representation of the object's hash code.
    Add a toString() method to CHelper that returns szname and you should see what you are expecting.

  • HELP!!Need to import and print vector drawings

    I am trying this topic again in the hope of help. I need to
    import drawings in a vector format for printing. These drawings
    will be cast members not sprites. I have tried printing a swf
    version via Printomatic but it cannot print Flash members. My
    questions are:
    1. Is therre any way to print a swf cast member (not a
    sprite)
    2. How can I import an EPS file? - I have heard that it can
    be done but every version I have tried seems to fail

    Darrel Plant has written an importer for .ai and .eps files.
    You can get
    it at:
    http://www.moshplant.com/direct-or/ps2vs/
    Haven't used it for a while but it works pretty good.
    Downside is that it creates multiple members because Director
    can't
    (couldn't?) handle multiple-line vector members.
    Dsotm wrote:
    > I am trying this topic again in the hope of help. I need
    to import drawings in
    > a vector format for printing. These drawings will be
    cast members not sprites.
    > I have tried printing a swf version via Printomatic but
    it cannot print Flash
    > members. My questions are:
    > 1. Is therre any way to print a swf cast member (not a
    sprite)
    > 2. How can I import an EPS file? - I have heard that it
    can be done but every
    > version I have tried seems to fail
    >
    Manno Bult
    [email protected]

  • Please help with retrieving values from object stored in a vector

    hi..
    i have a class Magazine with 2 varibles name and price like this
    class magazine
    String name;
    int price;
    i have created a vector called selectedmag which stores objects of Magazine class... now each object will contain the name and price rite...
    i want to print the values stored in vector ie i want to print the vector elements...like
    Name: Mag1
    Price: 10
    which wil be present in object1...
    and then
    Name: Mag2
    Price:15
    which wil be present in object2...
    and so on...
    plz help...
    if i give selectedmag.elementAt(position) i am not able to get the above output...plz help me.....
    thanks,
    Akshatha

    hi,
    Yes i have used a for loop to print the values... it goes like this
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    class Magazine
         String title;
         int price;
    public class sessiontrack1 extends HttpServlet
         public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
              res.setContentType("text/html");
              PrintWriter out=res.getWriter();
              HttpSession session=req.getSession(true);
    // This is my vector          
    Vector myshoppingcart=(Vector)session.getAttribute("ShoppingCart");
              if(myshoppingcart==null)
                   myshoppingcart=new Vector();
              Magazine selectedMag=new Magazine();
              selectedMag.title=req.getParameter("Title");
              selectedMag.price=Integer.parseInt(req.getParameter("Price"));
    //Putting Magazine object into the vector myshoppingcart
              myshoppingcart.addElement(selectedMag);
              session.setAttribute("ShoppingCart",myshoppingcart);
              out.println("<html><body>U have selected these magazines");
              out.println("<br>");
         //Enumeration vEnum=myshoppincart.elements();
    //here a am trying to print output the values
              for(int i=0;i<myshoppingcart.size();i++)
    out.println("Name:" + (Magazine)myshoppingcart.elementAt(i));
                   out.println("<br>");
    out.println("Price:" + (Magazine)myshoppingcart.elementAt(i));
                   out.println("<br>");
              out.println("</body></html>");
    this is a servlet program.... plz suggest me how to print the values... in the following format
    Name: Book1
    price: Rs 10
    Name:Book2
    price:Rs 15
    Akshatha

  • How do I  print out the attributes of objects from a  Vector?  Help !

    Dear Java People,
    I have created a video store with a video class.I created a vector to hold the videos and put 3 objects in the vector.
    How do I print out the attributes of each object in the vector ?
    Below is the driver and Video class
    Thank you in advance
    Norman
    import java.util.*;
    public class TryVideo
    public static void main(String[] args)
    Vector videoVector = new Vector();
    Video storeVideo1 = new Video(1,"Soap Opera", 20);
    Video storeVideo2 = new Video(2,"Action Packed Movie",25);
    Video storeVideo3 = new Video(3,"Good Drama", 10);
    videoVector.add(storeVideo1);
    videoVector.add(storeVideo2);
    videoVector.add(storeVideo3);
    Iterator i = videoVector.interator();
    while(i.hasNext())
    System.out.println(getVideoName() + getVideoID() + getVideoQuantity());
    import java.util.*;
    public class Video
    public final static int RENT_PRICE = 3;
    public final static int PURCHASE_PRICE = 20;
    private int videoID;
    private String videoName;
    private int videoQuantity;
    public Video(int videoID, String videoName, int videoQuantity)
    this.videoID = videoID;
    this.videoName = videoName;
    this.videoQuantity = videoQuantity;
    public int getVideoID()
    return videoID;
    public String getVideoName()
    return videoName;
    public int getVideoQuantity()
    return videoQuantity;
    }

    Dear Bri81,
    Thank you for your reply.
    I tried the coding as you suggested
    while(i.hasNext())
    System.out.println( i.next() );
    but the error message reads:
    "CD.java": Error #: 354 : incompatible types; found: void, required: java.lang.String at line 35
    Your help is appreciated
    Norman
    import java.util.*;
    public class TryCD
       public static void main(String[] args)
         Vector cdVector = new Vector();
         CD cd_1 = new CD("Heavy Rapper", "Joe", true);
         CD cd_2 = new CD("Country Music", "Sam", true);
         CD cd_3 = new CD("Punk Music", "Mary", true);
         cdVector.add(cd_1);
         cdVector.add(cd_2);
         cdVector.add(cd_3);
         Iterator i = cdVector.iterator();
         while(i.hasNext())
           System.out.println( i.next() );
    public class CD
       private String item;
       private boolean borrowed = false;
       private String borrower = "";
       private int totalNumberOfItems;
       private int totalNumberOfItemsBorrowed;
       public CD(String item,String borrower, boolean borrowed)
         this.item = item;
         this.borrower = borrower;
         this.borrowed = borrowed;
       public String getItem()
         return item;
       public String getBorrower()
         return borrower;
       public boolean getBorrowed()
         return borrowed;
       public String toString()
          return System.out.println( getItem() + getBorrower());

  • Need to sort two vectors at the same time! please help!

    I have
    vectorA: 2 4 9 1 7 6 8
    vectorB: two four nine one seven six eight
    i want to sort these two vectors in parallel
    what is the best way?
    i could just do Collection.sort(vectorA) and get
    1 2 4 6 7 8 9
    but i want the vectorB to have a corresponding order
    please help!!
    thanks

    public class Pair implements Comparable {
    private int value;
    private String name;
    public int getValue() {
    return this.value;
    public void setValue(int value) {
    this.value = value;
    public String getName() {
    return this.name;
    public void setName(String name) {
    this.name = name;
    public int compareTo(Object o) {
    Pair that = (Pair) o;
    return this.value - that.value;
    place both in a Collection (vector is a bad choice if you are going to do sorting LinkedList is better) the Collections.sort method will sort
    according to the compareTo method.

  • Need help in storing data from JList into a vector

    need help in doing the following.-
    alright i click a skill on industryskills Jlist and press the add button and it'll be added to the applicantskills Jlist. how do i further store this data that i added onto the applicantskills JList into a vector.
    here are the codes:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.text.*;
    import java.util.*;
    import java.util.Vector;
    import javax.swing.JScrollPane.*;
    //import javax.swing.event.ListSelectionListener;
    public class Employment extends JFrame
            //declare class variables
            private JPanel jpApplicant, jpEverything,jpWEST, jpCENTRE, jpEAST, jpAddEditDelete,
                                       jpCentreTOP, jpCentreBOT, jpEastTOP, jpEastCENTRE, jpEastBOT,
                                       jpBlank1, panel1, panel2, panel3, panel4,jpBottomArea,
                                       jpEmptyPanelForDisplayPurposes;
            private JLabel jlblApplicantForm, jlblAppList, jlblName, jlblPhone,
                                       jlblCurrentSalary, jlblPassword, jlblDesiredSalary,
                                       jlblNotes, jlblApplicantSkills, jlblIndustrySkills,
                                       jlblBlank1, jlblBlank2, ApplicantListLabel,
                                       NotesListLabel, ApplicantSkillsLabel,
                                       IndustrySkillsLabel,jlblEmptyLabelForDisplayPurposes;  
            private JButton jbtnAdd1, jbtnEdit, jbtnDelete, jbtnSave, jbtnCancel,
                                            jbtnAdd2, jbtnRemove;
            private JTextField jtfName, jtfPhone, jtfCurrentSalary, jtfPassword,
                                               jtfDesiredSalary;
              private JTabbedPane tabbedPane;
            private DefaultListModel /*listModel,*/listModel2;
              String name,password,phone,currentsalary,desiredsalary,textareastuff,NotesText;
              String selectedname;
            final JTextArea Noteslist= new JTextArea();;
            DefaultListModel listModel = new DefaultListModel();
            JList ApplicantSkillsList = new JList(listModel);
           private ListSelectionModel listSelectionModel;
            JList ApplicantList, /*ApplicantSkillsList,*/ IndustrySkillsList;
            //protected JTextArea NotesList;    
                    //Vector details = new Vector();
                  Vector<StoringData> details = new Vector<StoringData>();             
                public static void main(String []args)
                    Employment f = new Employment();
                    f.setVisible(true);
                    f.setDefaultCloseOperation(EXIT_ON_CLOSE);
                    f.setResizable(false);
                }//end of main
                    public Employment()
                            setSize(800,470);
                            setTitle("E-commerce Placement Agency");
                                  Font listfonts = new Font("TimesRoman", Font.BOLD, 12);
                            JPanel topPanel = new JPanel();
                            topPanel.setLayout( new BorderLayout() );
                            getContentPane().add( topPanel );
                            createPage1();
                            createPage2();
                            createPage3();
                            createPage4();
                            tabbedPane = new JTabbedPane();
                            tabbedPane.addTab( "Applicant", panel1 );
                            tabbedPane.addTab( "Job Order", panel2 );
                            tabbedPane.addTab( "Skill", panel3 );
                            tabbedPane.addTab( "Company", panel4 );
                            topPanel.add( tabbedPane, BorderLayout.CENTER );
            public void createPage1()//PAGE 1
                 /*******************TOP PART********************/
                            panel1 = new JPanel();
                            panel1.setLayout( new BorderLayout());
                                  jpBottomArea = new JPanel();
                                  jpBottomArea.setLayout(new BorderLayout());
                            jpApplicant= new JPanel();
                            jpApplicant.setLayout(new BorderLayout());
                            Font bigFont = new Font("TimesRoman", Font.BOLD,24);
                            jpApplicant.setBackground(Color.lightGray);
                            jlblApplicantForm = new JLabel("\t\t\t\tAPPLICANT FORM  ");
                            jlblApplicantForm.setFont(bigFont);
                            jpApplicant.add(jlblApplicantForm,BorderLayout.EAST);
                            panel1.add(jpApplicant,BorderLayout.NORTH);
                            panel1.add(jpBottomArea,BorderLayout.CENTER);
           /********************************EMPTY PANEL FOR DISPLAY PURPOSES*************************/
                               jpEmptyPanelForDisplayPurposes = new JPanel();
                               jlblEmptyLabelForDisplayPurposes = new JLabel(" ");
                               jpEmptyPanelForDisplayPurposes.add(jlblEmptyLabelForDisplayPurposes);
                               jpBottomArea.add(jpEmptyPanelForDisplayPurposes,BorderLayout.NORTH);
           /*****************************************WEST*********************************/             
                            jpWEST = new JPanel();                 
                            jpWEST.setLayout( new BorderLayout());
                            //Applicant List
                                  listModel2=new DefaultListModel();
                                  ApplicantList = new JList(listModel2);
                                listSelectionModel = ApplicantList.getSelectionModel();
                                listSelectionModel.addListSelectionListener(new SharedListSelectionHandler());
                                JScrollPane scrollPane3 = new JScrollPane(ApplicantList);
                                  ApplicantList.setPreferredSize(new Dimension(20,40));
                                 scrollPane3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);                                             
                                scrollPane3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                            ApplicantListLabel = new JLabel( "Applicant List:");
                            jpWEST.add(ApplicantListLabel,"North"); 
                            jpWEST.add(scrollPane3,"Center");
                            jpBottomArea.add(jpWEST,BorderLayout.WEST);
                            /*********CENTRE*********/
                            jpCENTRE = new JPanel();
                            jpCENTRE.setLayout(new GridLayout(2,1));
                            jpCentreTOP = new JPanel();
                            jpBottomArea.add(jpCENTRE,BorderLayout.CENTER);
                            jpCENTRE.add(jpCentreTOP);
                            jpCentreTOP.setLayout(new GridLayout(6,2));
                              //Creating labels and textfields
                            jlblName = new JLabel( "Name:");
                            jlblBlank1 = new JLabel ("");
                            jtfName = new JTextField(18);
                            jlblBlank2 = new JLabel("");
                            jlblPhone = new JLabel("Phone:");
                            jlblCurrentSalary = new JLabel("Current Salary:");
                            jtfPhone = new JTextField(13);
                            jtfCurrentSalary = new JTextField(7);
                            jlblPassword = new JLabel("Password:");
                            jlblDesiredSalary = new JLabel("Desired Salary:");
                            jtfPassword = new JTextField(13);
                            jtfDesiredSalary = new JTextField(6);
                              //Add labels and textfields to panel
                            jpCentreTOP.add(jlblName);
                            jpCentreTOP.add(jlblBlank1);
                            jpCentreTOP.add(jtfName);
                            jpCentreTOP.add(jlblBlank2);
                            jpCentreTOP.add(jlblPhone);
                            jpCentreTOP.add(jlblCurrentSalary);
                            jpCentreTOP.add(jtfPhone);
                            jpCentreTOP.add(jtfCurrentSalary);
                            jpCentreTOP.add(jlblPassword);
                            jpCentreTOP.add(jlblDesiredSalary);
                            jpCentreTOP.add(jtfPassword);
                            jpCentreTOP.add(jtfDesiredSalary);
                            //Noteslist
                            jpCentreBOT = new JPanel();
                            jpCentreBOT.setLayout( new BorderLayout());
                            jpCENTRE.add(jpCentreBOT);
                            jpBlank1 = new JPanel();
                             //     Noteslist = new JTextArea(/*Document doc*/);
                            JScrollPane scroll3=new JScrollPane(Noteslist);
                                scroll3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);                                             
                                scroll3.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                            NotesListLabel = new JLabel( "Notes:");
                            jpCentreBOT.add(NotesListLabel,"North"); 
                            jpCentreBOT.add(scroll3,"Center");
                            jpCentreBOT.add(jpBlank1,"South");
                            jpBottomArea.add(jpCENTRE,BorderLayout.CENTER);
                            /**********EAST**********/
                            //Applicant Skills Panel
                            //EAST ==> TOP
                            jpEAST = new JPanel();
                            jpEAST.setLayout( new BorderLayout());
                            jpEastTOP = new JPanel();
                            jpEastTOP.setLayout( new BorderLayout());
                            ApplicantSkillsLabel = new JLabel( "Applicant Skills");
                            JScrollPane scrollPane1 = new JScrollPane(ApplicantSkillsList);
                               scrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);                                             
                              scrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);                                             
                            ApplicantSkillsList.setVisibleRowCount(6);
                            jpEastTOP.add(ApplicantSkillsLabel,"North"); 
                            jpEastTOP.add(scrollPane1,"Center");
                            jpEAST.add(jpEastTOP,BorderLayout.NORTH);
                            jpBottomArea.add(jpEAST,BorderLayout.EAST);
                            //Add & Remove Buttons
                            //EAST ==> CENTRE
                            jpEastCENTRE = new JPanel();
                            jpEAST.add(jpEastCENTRE,BorderLayout.CENTER);
                            jbtnAdd2 = new JButton("Add");
                            jbtnRemove = new JButton("Remove");
                            //add buttons to panel
                            jpEastCENTRE.add(jbtnAdd2);
                            jpEastCENTRE.add(jbtnRemove);
                            //add listener to button
                           jbtnAdd2.addActionListener(new Add2Listener());
                           jbtnRemove.addActionListener(new RemoveListener());
                            //Industry Skills Panel
                            //EAST ==> BOTTOM
                            jpEastBOT = new JPanel();
                            jpEastBOT.setLayout( new BorderLayout());
                           String[] data = {"Access97", "Basic Programming",
                           "C++ Programming", "COBOL Programming",
                           "DB Design", "Fortran programming"};
                           IndustrySkillsList = new JList(data);
                           JScrollPane scrollPane = new JScrollPane(IndustrySkillsList);
                           scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);                                             
                           scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                           IndustrySkillsLabel = new JLabel( "Industry Skills:");
                           jpEastBOT.add(IndustrySkillsLabel,"North"); 
                           jpEastBOT.add(scrollPane,"Center");
                           jpEAST.add(jpEastBOT,BorderLayout.SOUTH);
                            //BOTTOM
                            jpAddEditDelete= new JPanel();
                            jbtnAdd1=       new JButton("Add");
                            jbtnEdit=       new JButton("Edit");
                            jbtnDelete=     new JButton("Delete");
                            jbtnSave=       new JButton("Save");
                            jbtnCancel=     new JButton("Cancel");
                            jpAddEditDelete.add(jbtnAdd1);
                            jpAddEditDelete.add(jbtnEdit);
                            jpAddEditDelete.add(jbtnDelete);
                            jpAddEditDelete.add(jbtnSave);
                            jpAddEditDelete.add(jbtnCancel);
                               jbtnEdit.addActionListener(new EditListener());
                               jbtnDelete.addActionListener(new DeleteListener());
                                jbtnEdit.addActionListener(new EditListener());
                            jbtnAdd1.addActionListener(new Add1Listener());
                            jbtnCancel.addActionListener(new CancelListener());
                            jpBottomArea.add(jpAddEditDelete,BorderLayout.SOUTH);
            public void createPage2()//PAGE 2
                    panel2 = new JPanel();
                    panel2.setLayout( new GridLayout(1,1) );
                    panel2.add( new JLabel( "Sorry,under construction" ) );
            public void createPage3()//PAGE 3
                    panel3 = new JPanel();
                    panel3.setLayout( new GridLayout( 1, 1 ) );
                    panel3.add( new JLabel( "Sorry,under construction" ) );
            public void createPage4()//PAGE 4
                    panel4 = new JPanel();
                    panel4.setLayout( new GridLayout( 1, 1 ) );
                    panel4.add( new JLabel( "Sorry,under construction" ) );
            public class Add1Listener implements ActionListener
            public void actionPerformed(ActionEvent e)
                    name = jtfName.getText();
                    password = jtfPassword.getText();
                    phone = jtfPhone.getText();
                    currentsalary = jtfCurrentSalary.getText();
                    int i= Integer.parseInt(currentsalary);
                    desiredsalary = jtfDesiredSalary.getText();
                    int j= Integer.parseInt(desiredsalary);
                       StoringData person = new StoringData(name,password,phone,i,j);
                   //     StoringData AppSkillsList = new StoringData(listModel);
                    details.add(person);
                 //     details.add(AppSkillsList);
                  listModel2.addElement(name);
                    jtfName.setText("");
                    jtfPassword.setText("");
                    jtfPhone.setText("");
                    jtfCurrentSalary.setText("");
                    jtfDesiredSalary.setText("");
    //                NotesList.setText("");
            public class Add2Listener implements ActionListener
                    public void actionPerformed(ActionEvent e)
                           String temp1;
                           temp1 = (String)IndustrySkillsList.getSelectedValue();
                           listModel.addElement(temp1);
            public class RemoveListener implements ActionListener
                    public void actionPerformed(ActionEvent e)
                            int index = ApplicantSkillsList.getSelectedIndex();
                                listModel.remove(index);
            public class EditListener implements ActionListener
                    public void actionPerformed(ActionEvent e)
                            jtfName.setEditable(true);
                            jtfPassword.setEditable(true);
                            jtfPhone.setEditable(true);
                            jtfCurrentSalary.setEditable(true);
                            jtfDesiredSalary.setEditable(true);
                            Noteslist.setEditable(true);
                            jbtnAdd2.setEnabled(true);               
                            jbtnRemove.setEnabled(true);
                            jbtnSave.setEnabled(true);
                            jbtnCancel.setEnabled(true);                     
            public class DeleteListener implements ActionListener
                    public void actionPerformed(ActionEvent e)
                        int index1 = ApplicantList.getSelectedIndex();
                            listModel2.remove(index1);
            public class SaveListener implements ActionListener
                    public void actionPerformed(ActionEvent e)
            public class CancelListener implements ActionListener
                    public void actionPerformed(ActionEvent e)
                    jtfName.setText("");
                    jtfPassword.setText("");
                    jtfPhone.setText("");
                    jtfCurrentSalary.setText("");
                    jtfDesiredSalary.setText("");                         
            public class SharedListSelectionHandler implements ListSelectionListener
            public void valueChanged(ListSelectionEvent e)
             selectedname =ApplicantList.getSelectedValue().toString();
             StoringData selectedPerson = null;
             jtfName.setEditable(false);
             jtfPassword.setEditable(false);
             jtfPhone.setEditable(false);
             jtfCurrentSalary.setEditable(false);
             jtfDesiredSalary.setEditable(false);                                 
             Noteslist.setEditable(false);
             jbtnAdd2.setEnabled(false);               
             jbtnRemove.setEnabled(false);
             jbtnSave.setEnabled(false);
             jbtnCancel.setEnabled(false);
                   for (StoringData person : details)
                          if (person.getName1().equals(selectedname))
                                 selectedPerson = person;
                                 jtfName.setText(person.getName1());
                                 jtfPassword.setText(person.getPassword1());
                              jtfPhone.setText(person.getPhone1());
                              //String sal1 = Integer.parseString(currentsalary);
                             // String sal2 = Integer.parseString(desiredsalary);
                             // jtfCurrentSalary.setText(sal1);
                             // jtfDesiredSalary.setText(sal2);
                                 break;
                   //     if (selectedPerson != null)
    }

    Quit posting 300 line programs to ask a question. We don't care about your entire application. We only care about code that demonstrates your current problem. We don't want to read through 300 lines to try and find the line of code that is causing the problem.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.
    Here is a simple SSCCE. Now make your changes and if you still have problems you have something simple to post. If it works then you add it to your real application.
    Learn to simplify your problem by simplifying the code.
    import java.awt.*;
    import javax.swing.*;
    public class ListTest2 extends JFrame
         JList list;
         public ListTest2()
              String[] numbers = { "one", "two", "three", "four", "five", "six", "seven" };
              list = new JList( numbers );
              JScrollPane scrollPane = new JScrollPane( list );
              getContentPane().add( scrollPane );
         public static void main(String[] args)
              ListTest2 frame = new ListTest2();
              frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
              frame.setSize(200, 200);
              frame.setLocationRelativeTo( null );
              frame.setVisible( true );
    }

  • Please Help With A Loop Using Vectors?

    I am developing a swing application and this loop has me completly stumped I have not worked with vectors alot, nut I have never seen this happen in a loop before:
    I am just going to post the loop because that is where this problem is happening.
    What I want to do is loop through CAT X amount of times and
    have an inner loop for SUBCAT X amount of times.
    fs is a formattedString class I have and eventually this text is appended to a JTextArea.
    Here is the Loop:
    Vector CAT = new Vector();
    Vector SUBCAT = new Vector();
    CAT = getCategories(Department);
    for (int i=0; i<CAT.size(); i++){
    String Category = CAT.elementAt(i).toString();
    fs.append("\nCategory: ",11);
    fs.append(Category,65);
    SUBCAT = getSubCategories(Category);
    }//End CATEGORY
    The part where I am completely stumped is, if I comment out the SUBCAT= part then the Text displays fine. If I dont it will just display the first string in the CAT Vector I have done a try and catch to see if there is an exception being thrown but there is none. The getSubCategories() method works fine b/c it is working at other parts of my program. (It Returns a Vector BTW). So commenting it out should really make no difference.
    Can anyone help me with this????
    Thanks in advance

    I will post what my output is in each scenario and maybe you can better understand what I am explaining:
    SCENARIO 1::::::::::::::::::::::::::::
    for (int i=0; i<CAT.size(); i++){
    fs.append("\nCategory: ",11);
    fs.append(CAT.elementAt(i).toString(),65);
    }//End CATEGORY
    Category: A Collars
    Category: Access Door
    Category: Aluminum
    Category: Anchors Drop In
    Category: Bits
    Category: Blades
    Category: Bolts, Nuts, Pins and Rivets
    Category: Bolts, Nuts, Pins, and Rivets
    Category: Canvas Connection
    Category: Caps
    Category: Caulking
    Category: Copper
    Category: Duct Mate
    Category: Ells
    Category: Flat Bar
    Category: Flex Duct
    Category: Galvanized
    Category: Grills
    Category: Insulation
    Category: Iron
    Category: Miscellaneous
    Category: Pipe
    Category: Reducers
    Category: Return Air Panels
    Category: Rings
    Category: Rod
    Category: Slide Gates
    Category: Spin Ins
    Category: Stainless Steel
    Category: Stick On With Damper
    Category: Tape
    Category: TDC
    Category: Tees
    Scenario 2:::::::::::::::::::::::::::::::::
    Category: A Collars
    for (int i=0; i<CAT.size(); i++){
    fs.append("\nCategory: ",11);
    fs.append(CAT.elementAt(i).toString(),65);
    SUBCAT = getSubCategories(CAT.elementAt(i).toString());
    }//End CATEGORY
    Now do you see:
    The SUBCAT = getSubCategories(CAT.elementAt(i).toString()); should not be affecting the loop. It should just be assigning a new Vector to SUBCAT. I know that it is missing the inner loop in this example, but this is how I found out the loops where not working right.

  • Help needed to solve "java.io.NotSerializableException: java.util.Vector$1"

    hi to all,
    i am using a session less bean A to querry a Entity Bean B , which inturns calls another EntityBean C ,
    finally a ' find' method is invoked on the EntityBean C, In this a vector is created which holds 3 different vectors at different indexes, now the problem i am facing is that when Enity Bean B is returning the final vector to the A , it's firing out a errors that :-
    TRANSACTION COULD NOT BE COMPLETED: RemoteException occurred in server thread;
    ested exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.rmi.ServerException: RemoteException occurred in server thread; ne
    ted exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.ServerException: RemoteException occurred in server thread; nested exc
    ption is:
    java.rmi.RemoteException: null; nested exception is:
    java.rmi.ServerException: RemoteException occurred in server thread; ne
    ted exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.RemoteException: null; nested exception is:
    java.rmi.ServerException: RemoteException occurred in server thread; ne
    ted exception is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.ServerException: RemoteException occurred in server thread; nested exc
    ption is:
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.rmi.RemoteException: null; nested exception is:
    java.io.NotSerializableException: java.util.Vector$1
    java.io.NotSerializableException: java.util.Vector$1
    <<no stack trace available>>
    ur any help would be highly appricated to solve out this prob.
    If i try to iterate through this vector it's gives IOR:0232003x343242344asdsd................................................blabla....................
    thanxs in adavance
    Deepak

    Hi I think you are using the method elements() in a remote method.
    This method can't be Serializable!! Because it returns an Interface. Interfaces are never Serializable.
    Regards,
    Peter

  • When I try to open Help in Vector Works 12.5.5, nothing happens. It works fine when I switch to Safari as my browser. I'm running on a 10.5.8 Mac. It worked fine last week. Any ideas?

    When I try to open Help in Vector Works 12.5.5, nothing happens. It works fine when I switch to Safari as my browser. I'm running on a 10.5.8 Mac using Firefox 3.6.3. It worked fine last week. Any ideas?
    == This happened ==
    Every time Firefox opened
    == today

    Wow! You're amazing! It's now ok! Thanks so much!
    I just thought that Rapport will help me to be more secured but I didn't know that it has a side effect. haha!

Maybe you are looking for