Vector class, insertElementAt() method and JComboBox

Hi guys,
I am using a vector called vectorSquare. I have an (Square)object in each component. When I run the program, depending on how many squares the user chooses, the combobox size will be vectorSquare.size(). Everything is all right. But if the user reenter data for one of the square, I think the vectorSquare.size() increases 1. Using vSquares.insertElementAt(temp, comboBox.getSelectedIndex()); when the user enters the data works OK, but if the user wants to change and reenter the data of a square, the new solution will be through the getSelectedIndex()) giving by the JComboBox. Instead, the past result will keep displaying, in getSelectedIndex() + 1 index. I don't know why. I thought insertElementAt() inserts new data but delete the past one, but it doesn't seem at all. Thats why I have decided to delete the past entering. But doing that, it compiles but now doesn't run, and gives an error to me here:
--> if (vSquares.elementAt(comboBox.getSelectedIndex()) != null) {
At the beginning I used:
vSquares.insertElementAt(temp, comboBox.getSelectedIndex());
But it overwrites, so I now use this:
if (vSquares.elementAt(comboBox.getSelectedIndex()) != null) {
     vSquares.removeElementAt(comboBox.getSelectedIndex());
     vSquares.insertElementAt(temp, comboBox.getSelectedIndex());
But it doesnt run as I said above.
Anybody knows what I could do to work it out?
Thank you.

Hi, its me again. I am checking and it still doesn't work. I have tried these different ways and I dont know whats going on??????
vSquares.insertElementAt(temp,comboBox.getSelectedIndex());
vSquares.removeElementAt(comboBox.getSelectedIndex()+1);
++++++++++++++++++++++
vSquares.setElementAt(temp,comboBox.getSelectedIndex());
/++++++++++++++++++++
int p = comboBox.getSelectedIndex();
vSquares.removeElementAt(p);
vSquares.insertElementAt(temp,p);
++++++++++++++++++++++++
int p = comboBox.getSelectedIndex();
vSquares.setElementAt(temp,p);

Similar Messages

  • Send Vector class to JSP and print this Vector using JSTL

    Hello All!
    I need your help to solve my question.
    I developed a Servlet + jsp application.
    I tested it in local with Apache Tomcat/6.0.20 and it works correctly.
    I write and use these classes:
    class for execute query, and including data page:
    package MySQL;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.util.*;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    * @author initmax
    public class MySQLQuery {
        private Connection CurrentConnect; //obj for connect to databae
        private Vector VectorPageObj = new Vector(); //save array object page, after execute query
    public MySQLQuery() {}
    //constructor accept current conection database
    public MySQLQuery(Connection CurrentConnectBase)
        CurrentConnect = CurrentConnectBase;
    //method accept name table and return all info on this table
    public void SelectAllField(String NameTable)
           try
             Statement st = CurrentConnect.createStatement();
             String query = ("select * from "+NameTable);
             ResultSet resultQuery = null;
             resultQuery = st.executeQuery(query);
    //step in cycle after execution query, and create Vector object
               while (resultQuery.next())
                  GenPageMySQL PageObj = new GenPageMySQL();
                  PageObj.setId(resultQuery.getInt("id"));
                  PageObj.setTheme(resultQuery.getString("theme"));
                  PageObj.setPage(resultQuery.getString("page"));
                  VectorPageObj.add(PageObj); //add obj in tail vector
           catch (SQLException e) {
             e.printStackTrace();
        *@set the CurrentConnect
        public void setConnection(Connection CurrentConnectBase) {
             CurrentConnect = CurrentConnectBase;
        *@get Vector object "Vector created after execute query"
         public Vector getVectorPageObj(Connection CurrentConnectBase) {
             return VectorPageObj;
    }start Servlet class:
    import java.util.*;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import MySQL.*;
    public class indexServlet extends HttpServlet {
        private  String getpage;
        //Connected MySQL
        private MySQLConnect MySQLConnectObj = new MySQLConnect();
        private MySQLQuery MySQLQueryObj = new MySQLQuery();
        public void init(){
              MySQLConnectObj.DownloadDriver();
              MySQLConnectObj.Connected();
              //Use current connection, for execution query
              MySQLQueryObj.setConnection(MySQLConnectObj.GetConnection());
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException, NullPointerException  {
      //      init();
            PrintWriter out = response.getWriter();
    //GET case useer
          getpage = request.getParameter("page");
          out.print("MySQLConnectObj.GetConnection() = "+MySQLConnectObj.GetConnection()); 
    //Check curent connect to database
          if(MySQLConnectObj.GetConnection() != null)
               MySQLQueryObj.SelectAllField("up_menu");//execution query
               MySQLConnectObj.DisConnected();
                request.setAttribute("up_menu_theme",MySQLQueryObj.getVectorPageObj(null));
                RequestDispatcher Dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp");
                Dispatcher.forward(request, response);
          else if(MySQLConnectObj.GetConnection() == null){
                init() ;
            out.print("MySQLConnectObj.GetConnection() = "+MySQLConnectObj.GetConnection());
    //        MySQLConnectObj.DisConnected();
    }I forward Vector "MySQLQueryObj.getVectorPageObj(null)" to JSP, how I can print data vector using JSTL?

    your right, I learn Java however this very Interesting!
    I change code, change Vector on List
    class MySQLQyery:
    package MySQL;
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    import java.util.*;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    * @author initmax
    public class MySQLQuery {
        private Connection CurrentConnect; //obj for connect to databae
    public MySQLQuery() {}
    //constructor accept current conection database
    public MySQLQuery(Connection CurrentConnectBase) {
        CurrentConnect = CurrentConnectBase;
    //method accept name table and link on List, after work return all info on this table inside List
    public List<GenPageMySQL> selectAllField(String NameTable, List<GenPageMySQL> ListPageObj) {
           try {
             Statement st = CurrentConnect.createStatement();
             String query = ("select * from "+NameTable);
             ResultSet resultQuery = null;
             resultQuery = st.executeQuery(query);
    //step in cycle after execution query, and create Vector object
               while (resultQuery.next()) {
                  GenPageMySQL PageObj = new GenPageMySQL();
                  PageObj.setId(resultQuery.getInt("id"));
                  PageObj.setTheme(resultQuery.getString("theme"));
                  PageObj.setPage(resultQuery.getString("page"));
                  ListPageObj.add(PageObj); //add obj in tail vector
           catch (SQLException e) {
             e.printStackTrace();
           return ListPageObj;
        *@set the CurrentConnect
        public void setConnection(Connection CurrentConnectBase) {
             CurrentConnect = CurrentConnectBase;
      List<GenPageMySQL> ListPageObj;
                //get List<RowObject>
                ListPageObj = MySQLQueryObj.getListPageObj();
      out.print("Size Page objects = "+ListPageObj.size());
                request.setAttribute("upMenu",ListPageObj);
                RequestDispatcher Dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/index.jsp");
                Dispatcher.forward(request, response);string out.print("Size Page objects = "+ListPageObj.size()); == worked, I get count objects correct
    How I can output fields Object GenPageMySQL in JSTL?
    writing so:
             <c:out value="hello, Max" />
             <c:out value="${10+20/2}" />
             <c:forEach items="${upMenu}" var="Object" >     
                   <c:out value="${Object.getId}"> </c:out>
             </c:forEach>
        </body>
    </html>but get error:
    org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/jsp/index.jsp at line 36
    33:          <c:forEach items="${upMenu}" var="Object" >
    34:         
    35:                 
    36:                <c:out value="${Object.getId}"> </c:out>
    37:
    38:    
    39:          </c:forEach>
    Stacktrace:
         org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
         indexServlet.doGet(indexServlet.java:49)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:717)How I can in output print fields my Object?
    Thank you for your help.

  • Calling a class's method from another class

    Hi, i would like to know if it's possible to call a Class's method and get it's return from another Class. This first Class doesn't extend the second. I've got a Choice on this first class and depending on what is selected, i want to draw a image on the second class witch is a Panel extended. I put the control "if" on the paint() method of the second class witch is called from the first by the repaint() (first_class.repaint()) on itemStateChanged(). Thankx 4 your help. I'm stuck with this.This program is for my postgraduation final project and i'm very late....

    import java.awt.*;
    import java.sql.*;
    * This type was generated by a SmartGuide.
    class Test extends Frame {
         private java.awt.Panel ivjComboPane = null;
         private java.awt.Panel ivjContentsPane = null;
         IvjEventHandler ivjEventHandler = new IvjEventHandler();
         private Combobox ivjCombobox1 = null;
    class IvjEventHandler implements java.awt.event.WindowListener {
              public void windowActivated(java.awt.event.WindowEvent e) {};
              public void windowClosed(java.awt.event.WindowEvent e) {};
              public void windowClosing(java.awt.event.WindowEvent e) {
                   if (e.getSource() == Test.this)
                        connEtoC1(e);
              public void windowDeactivated(java.awt.event.WindowEvent e) {};
              public void windowDeiconified(java.awt.event.WindowEvent e) {};
              public void windowIconified(java.awt.event.WindowEvent e) {};
              public void windowOpened(java.awt.event.WindowEvent e) {};
         private Panel ivjPanel1 = null;
    * Combo constructor comment.
    public Test() {
         super();
         initialize();
    * Combo constructor comment.
    * @param title java.lang.String
    public Test(String title) {
         super(title);
    * Insert the method's description here.
    * Creation date: (11/16/2001 7:48:51 PM)
    * @param s java.lang.String
    public void conexao(String s) {
         try {
              Class.forName("oracle.jdbc.driver.OracleDriver");
              String url = "jdbc:oracle:thin:system/[email protected]:1521:puc";
              Connection db = DriverManager.getConnection(url);
              //String sql_str = "SELECT * FROM referencia";
              Statement sq_stmt = db.createStatement();
              ResultSet rs = sq_stmt.executeQuery(s);
              ivjCombobox1.addItem("");
              while (rs.next()) {
                   String dt = rs.getString(1);
                   ivjCombobox1.addItem(dt);
              db.close();
         } catch (SQLException e) {
              System.out.println("Erro sql" + e);
         } catch (ClassNotFoundException cnf) {
    * connEtoC1: (Combo.window.windowClosing(java.awt.event.WindowEvent) --> Combo.dispose()V)
    * @param arg1 java.awt.event.WindowEvent
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void connEtoC1(java.awt.event.WindowEvent arg1) {
         try {
              // user code begin {1}
              // user code end
              this.dispose();
              // user code begin {2}
              // user code end
         } catch (java.lang.Throwable ivjExc) {
              // user code begin {3}
              // user code end
              handleException(ivjExc);
    * Return the Combobox1 property value.
    * @return Combobox
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private Combobox getCombobox1() {
         if (ivjCombobox1 == null) {
              try {
                   ivjCombobox1 = new Combobox();
                   ivjCombobox1.setName("Combobox1");
                   ivjCombobox1.setLocation(30, 30);
                   // user code begin {1}
                   this.conexao("select * from referencia");
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjCombobox1;
    * Return the ComboPane property value.
    * @return java.awt.Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.Panel getComboPane() {
         if (ivjComboPane == null) {
              try {
                   ivjComboPane = new java.awt.Panel();
                   ivjComboPane.setName("ComboPane");
                   ivjComboPane.setLayout(null);
                   getComboPane().add(getCombobox1(), getCombobox1().getName());
                   getComboPane().add(getPanel1(), getPanel1().getName());
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjComboPane;
    * Return the ContentsPane property value.
    * @return java.awt.Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private java.awt.Panel getContentsPane() {
         if (ivjContentsPane == null) {
              try {
                   ivjContentsPane = new java.awt.Panel();
                   ivjContentsPane.setName("ContentsPane");
                   ivjContentsPane.setLayout(new java.awt.BorderLayout());
                   getContentsPane().add(getComboPane(), "Center");
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjContentsPane;
    * Return the Panel1 property value.
    * @return Panel
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private Panel getPanel1() {
         if (ivjPanel1 == null) {
              try {
                   ivjPanel1 = new Panel();
                   ivjPanel1.setName("Panel1");
                   ivjPanel1.setBackground(java.awt.SystemColor.scrollbar);
                   ivjPanel1.setBounds(24, 118, 244, 154);
                   // user code begin {1}
                   // user code end
              } catch (java.lang.Throwable ivjExc) {
                   // user code begin {2}
                   // user code end
                   handleException(ivjExc);
         return ivjPanel1;
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initializes connections
    * @exception java.lang.Exception The exception description.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initConnections() throws java.lang.Exception {
         // user code begin {1}
         // user code end
         this.addWindowListener(ivjEventHandler);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Combo");
              setLayout(new java.awt.BorderLayout());
              setSize(460, 300);
              setTitle("Combo");
              add(getContentsPane(), "Center");
              initConnections();
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * Insert the method's description here.
    * Creation date: (11/17/2001 2:02:58 PM)
    * @return java.lang.String
    public String readCombo() {
         String dado = ivjCombobox1.getSelectedItem();
         return dado;
    * Starts the application.
    * @param args an array of command-line arguments
    public static void main(java.lang.String[] args) {
         try {
              /* Create the frame */
              Test aTest = new Test();
              /* Add a windowListener for the windowClosedEvent */
              aTest.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosed(java.awt.event.WindowEvent e) {
                        System.exit(0);
              aTest.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of Test");
              exception.printStackTrace(System.out);
    * Insert the type's description here.
    * Creation date: (11/17/2001 1:59:15 PM)
    * @author:
    class Combobox extends java.awt.Choice {
         public java.lang.String dado;
    * Combobox constructor comment.
    public Combobox() {
         super();
         initialize();
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Combobox");
              setSize(133, 23);
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * main entrypoint - starts the part when it is run as an application
    * @param args java.lang.String[]
    public static void main(java.lang.String[] args) {
         try {
              java.awt.Frame frame = new java.awt.Frame();
              Combobox aCombobox;
              aCombobox = new Combobox();
              frame.add("Center", aCombobox);
              frame.setSize(aCombobox.getSize());
              frame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
              frame.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of Combobox");
              exception.printStackTrace(System.out);
    * Insert the type's description here.
    * Creation date: (11/17/2001 2:16:11 PM)
    * @author:
    class Panel extends java.awt.Panel {
    * Panel constructor comment.
    public Panel() {
         super();
         initialize();
    * Panel constructor comment.
    * @param layout java.awt.LayoutManager
    public Panel(java.awt.LayoutManager layout) {
         super(layout);
    * Called whenever the part throws an exception.
    * @param exception java.lang.Throwable
    private void handleException(java.lang.Throwable exception) {
         /* Uncomment the following lines to print uncaught exceptions to stdout */
         // System.out.println("--------- UNCAUGHT EXCEPTION ---------");
         // exception.printStackTrace(System.out);
    * Initialize the class.
    /* WARNING: THIS METHOD WILL BE REGENERATED. */
    private void initialize() {
         try {
              // user code begin {1}
              // user code end
              setName("Panel");
              setLayout(null);
              setSize(260, 127);
         } catch (java.lang.Throwable ivjExc) {
              handleException(ivjExc);
         // user code begin {2}
         // user code end
    * main entrypoint - starts the part when it is run as an application
    * @param args java.lang.String[]
    public static void main(java.lang.String[] args) {
         try {
              java.awt.Frame frame = new java.awt.Frame();
              Panel aPanel;
              aPanel = new Panel();
              frame.add("Center", aPanel);
              frame.setSize(aPanel.getSize());
              frame.addWindowListener(new java.awt.event.WindowAdapter() {
                   public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
              frame.setVisible(true);
         } catch (Throwable exception) {
              System.err.println("Exception occurred in main() of java.awt.Panel");
              exception.printStackTrace(System.out);
    * Insert the method's description here.
    * Creation date: (11/17/2001 2:18:36 PM)
    public void paint(Graphics g) {
    /* Here's the error:
    C:\Test.java:389: non-static method readCombo() cannot be referenced from a static context
         System.out.println(Test.lerCombo());*/
         System.out.println(Test.readCombo());

  • Query on Class.forName() method

    What is the difference between instantiating using Class.forName() method and instantiating using the new operator?

    You can do one of them at runtime.
    For example:
    public static void main(String[] args) {
       String className = args[0];
       Object o = Class.forName(className).newInstance();
    }It's essentially a part of the reflection API which is generally used when you don't know exactly what you want to manipulate at compile time.

  • Whats the difference between a class method and a instance method.

    I have a quiz pretty soon and one of the questions will be: "How does an instance method differ from a class method." I've tried looking this up but they gave me really complicated explanations. I know what a instance method is but not really sure what a class one is. Can someone post an example of a class method and try to explain what makes it so special?
    Edited by: tetris on Jan 30, 2008 10:45 PM

    Just have a look:
    http://forum.java.sun.com/thread.jspa?threadID=603042&messageID=3246191

  • Purpose of declaring the method or class or static and as instance

    what is the purpose of declaring a method in a class or the class itself as static.
    Does it mean we cannot create a copy of that class or method if we declare it as static.
    if so then why do they dont want that class to be created as a copy ?
    Why do they want to declare a class as static
    please provide some conceptual undersatnding regarding the static and instance class with one example

    Static methods are often used for the implementation of utility methods. Please have a look at the class CL_ABAP_CHAR_UTILITIES for example.
    You use the methods of this class in the same way as you would use a function in ABAP (like
    LINES( itab )
    ). You use it in a static way because the functionality is always the same no matter in what context you are calling the function.
    The purpose of instance methods is that their logic is in some way related to an attribute of the object instance that you use to call it.
    For example, you create an instance of object PO (a purchase order) called MY_PO. Then the method
    MY_PO->ADD_POSITION
    would add a position to a concrete PO that has a unique number etc. But if the object has a static method DELETE_POSITION then it just deletes the current position of a PO, regardless on which concrete PO you are acting at the moment.
    I hope this clarifies it for you.
    Regards,
    Mark

  • Abstract method and class

    I'm a beginner in Java and just learn about abstract method and class.
    However, i am wondering what is the point of using abstract method/class?
    Because when I delete the abstract method and change the class name to public class XXXX( changed from "abstract class XXXX), my program still runs well, nothing goes different.
    Is it because I haven't encountered any situation that abstract method is necessary or ?
    Thanks!

    Yes - you probably haven't encountered a situation where you need an abstract.
    Abstract classes are not designed to do anything on their own. They are designed to provide a template for other classes to extend by inheritance. What you have build sounds like a concrete class - one which you are creating instances of. Abstract classes are not designed to be ever instantiated in their pure form - they act like a partial building block, which you will complete in a class which extends the abstract.
    An example might be a button class, which provides some core functionality (like rollover, rollout etc) but has an empty action method which has to be overwritten by a relevant subclass like 'StartButton'. In general, abstract classes may not be the right answer, and many people would argue that it is better to use an interface, which can be implemented instead of extended, meaning that you can ADD instead of REPLACING.
    Not sure if that helps.. there are whole chapters in books on this kind of thing, so it's hard to explain in a couple of paragraphs. Do some google searches to find out more about how they work.

  • Classes and methods and Nodes

    hey guys. I have a class called Player, a class called Node, and a class called TurnTaker. The TurnTaker class uses both the Node class and the player class. All the files are in the same directory but i am getting an unresolved symbol for the methods (getName() and printString())
    here is my turnTaker Class
    class Turntaker
         private int totTurns=0;
         private Node first = null;
         private Node turn = first;
         private Node last;
         private Node walk = first;
         public void takeTurn()
              totTurns ++;
              System.out.println(totTurns + ". " + turn + " is taking a turn.");
              turn = turn.getNext();     
         public void addPlayer(Player name)
              Node w = new Node(name, null);
              if(first == null)
                   first = w;
                   last = w;
              else
                   last.setNext(w);
                   last = last.getNext();
                   w.setNext(first);
         public void deletePlayer(Player name)
              while((walk.getItem().getName()).equals(name)!=true)
                   walk = walk.getNext();
              if(turn == walk)
                   turn.getNext();
              walk.setNext(walk.getNext());     
         public void printPlayers()
              walk = first;
              (walk.getItem()).printstring();
              walk = walk.getNext();
              while(walk!=first)
                   (walk.getItem()).printString();
    }here is my Player class
    public class Player
         private String name;
         private int numTurn;
         public Player(String theName)
              name = theName;
              numTurn = 0;
         public int getNumTurn()
              return numTurn;
         public String getName()
              return name;
         public void setNumTurn(int turn)
              numTurn = turn;
         public void printString()
              System.out.println(name + " has taken " + numTurn + " turns.");
    }and here is my Node Class
    public class Node
         Object item;
         Node next;
         public Node(Object newItem, Node nextNode)
              item = newItem;
              next = nextNode;
         public void setItem(Object newItem)
              item = newItem;
         public Object getItem()
              return item;
         public void setNext(Node nextNode)
              next = nextNode;
         public Node getNext()
              return next;
    }can anyone please tell what is wrong with my code?
    thank you

    awesome..my class compiles. ok now i just got a little bit left. I also have a driver program that i made to test out everything. I am getting 12 errors, all pointing to the points where i try to use the methods from my TurnTaker Class. The error is an unresolved symbol error.
    here is my driver
    class TurnTakerDriver
         public static void main(String[] args)
              Player p1 = new Player("Jim");
              addPlayer(p1);
              Player p2 = new Player("Sue");
              addPlayer(p2);
              Player p3 = new Player("Abe");
              addPlayer(p3);
              printPlayers();
              for(int i=0; i<5; i++)
                   takeTurn();
              Player p4 = new Player("Lynn");
              addPlayer(p4);
              printPlayers();
              for(int i=0; i<3; i++)
                   takeTurn();
              deletePlayer(p4);
              printPlayers();
              for(int i=0; i<2; i++)
                   takeTurn();
              printPlayers();
    }any ideas?

  • Final method and final class

    What is final method and final class in abap objects.

    ejp wrote:
    Since that doesn't work--or would overyy complex to implement... would be impossible to implement. Once the method-local copy goes out of existence, ipso facto it can never be changed. This is the whole point.I consider it impossible too, but I'm not a language/compiler/runtime expert, so I allowed for the possibility that there could be some way to do it--e.g. local variables that are references in inner classes live on the heap instead of the stack, or something. My point isn't that it's possible, just that if it were somehow to be done, it would by ugly, so we may as well consider it impossible--it just ain't gonna happen.
    we go with the logic, "Okay, we need to copies, but keeping them in sync is a nightmareNo, it is +meaningless.+No, it's not meaningless. If we have the two copies, and they're not final, then after the inner object is created, the method can continue running, and either the method or the inner object could modify its copy. As far as our code knows, it's the same variable, so there'd have to be some way to keep them in sync. That's either impossible or undesirably complex--like the above, it doesn't matter which--so it's final in order to get past the issue of keeping the copies in sync.

  • Smart forms - Identifying the calling method and class

    Hi Experts,
    Is there a way to identify the method and class names that called a smart form..
    Any inputs or pointers in this regard woul;d be of great help.
    Regards,
    Kris.

    Hi Kartik,
    The procedure you suggested is good to identify the class by manual intervention.
    But I need the class/mehtod name in the program as the logic of the code depends on which class called the smart form.
    Any idea how this can be read?
    Regards,
    Kris.

  • What is Processing Method and Processing Class in Action Profile

    Dear all,
    I have defined an action for case management, to trigger an email after saving the case in Enterprise portal.
    Action is getting initiated in case document after saving, but after a while it is showing message 'Incorrect'.
    In the actions monitor report, error message showing that some problem in Processing Method.
    In my action I have maintained settings as below.
    Form name - SCMG_SMART_FORM_CASE
    Processing class - CL_SCMG_CASE_CONTEXT_PPF
    But I don't know what processing method should I give
    I could not find and values under F4 functionality.
    Please do advice me what method I can use here.
    and why we use processing method and processing class.
    your help will be highly appreciated.
    Thank you
    Raghu ram

    Hi
    DSD means Daily Salary Deduction for more check this table to understand abd DSD and the respective Processing class 77 V_T7INO1

  • What are abstract classes/methods and what are they for?

    Hi,
    I've just heard about abstract classes and methods and I'm just wondering what exactly they're used for, and why are they there for the Graphics class for example?
    Cheers.

    raggy wrote:
    bastones_ wrote:
    Hi,
    I've just heard about abstract classes and methods and I'm just wondering what exactly they're used for, and why are they there for the Graphics class for example?
    Cheers.Hey bro, I'll try to solve your problemYou have to know two important concepts for this part. 1 is Abstract classes and the other is Interface classes. Depends on the nature of the project, you need to set certain level of standards and rules that the other developers must follow. This is where Abstract classes and Interface classes come into picture.
    Abstract classes are usually used on small time projects, where it can have code implementation like general classes and also declare Abstract methods (empty methods that require implementation from the sub-classes).Wrong, they are used equally among big and small projects alike.
    Here are the rules of an Abstract class and method:
    1. Abstract classes cannot be instantiatedRight.
    2. Abstract class can extend an abstract class and implement several interface classesRight, but the same is true for non-abstract classes, so nothing special here.
    3. Abstract class cannot extend a general class or an interfaceWrong. Abstract classes can extend non-abstract ones. Best example: Object is non-abstract. How would you write an abstract class that doesn't extend Object (directly or indirectly)?
    4. If a class contains Abstract method, the class has to be declared Abstract classRight.
    5. An Abstract class may or may not contain an Abstract methodRight, and an important point to realize. A class need not have abstract methods to be an abstract class, although usually it will.
    6. Abstract method should not have any code implementations, the sub-classes must override it (sub-class must give the code implementations). An abstract method must not have any implementation code code. It's more than a suggestion.
    7. If a sub-class of an Abstract class does not override the Abstract methods of its super-class, than the sub-class should be declared Abstract also.This follows from point 4.
    9. Abstract classes can only be declared with public and default access modifiers.That's the same for abstract and non-abstract classes.

  • The get() of Vector class, is it thread safe??

    Hi all:
    the get() of Vector class, is it thread safe?? I looked into the API, but no info is available, so any help is appreciated

    You just have to look out when you perform two or more methods on the Vector in sucession. Then it's better to lock on the vector itself. If you for instance access the vector to query whether the size is greater than zero and immediately remove an item while another thread is removing elements from the same vector, you might get a dirty read and call get() on the vector while there are no elements left.

  • Vectors gone?  When and why?

    I have read in a couple of posts that Vectors are "legacy" and may not be around forever. Can anyone shed light on the when and why of this? I am relatively new to JAVA programming but I do have a bunch of applications out there that use Vectors. I personally found them very easy to work with.
    Thoughts?

    Wow! I can't wait for Java 2.0! (Please read heavy sarcasm.)
    Speaking of rumors, let's not start spreading any rumors that the Java group at Sun has actually started to talk about -- let alone publicly announced -- that a 2.0 version is in the works; 1.5 sounds right to me.
    I know that you can get almost the same functionality out of a List that is returned from the Collections.synchronizedList(List) method as you can out of a Vector, but Vector is by no means a deprecated class. (We should try to be careful about the casual use of meaning-laden words.) pengjuc is right that a lot of Swing (and non-Swing) classes such as JTable rely on Vector; the mere rewrite to replace all the Vectors with ArrayLists would probably require a Java release all on its own (and whose to say that ArrayLists are really all that, anyway?). Moreover, Vector is part of the public API of many classes and to deprecate it would throw a lot of developers into a tizzy because it would potentially break the ability of their applications to upgrade to a new version of Java. There is nothing inherently wrong with Vector -- it performs as advertised -- and pengjuc is right again that the performance differentials are minute over small object collections.
    In response, again, to dubwai, there's a difference between using Vectors as a developer and having them included in the J2SDK. If you don't like them don't use them, and if you don't like them in other classes, rewrite those classes to your taste. Personally, I think you either have to take what you're given, do it yourself, or get involved in the process.
    Good luck, All!
    Shaun

  • Vector class size limitation

    Hi guys,
    Does anyone know how big a Vector class can be?
    I'm planning to have a Vector object of size ~200,000 to 500,000 elements.
    I would really want to use the vector in my design and benefit from its sync feature. The only concern is how reliable it will be..
    Has anyone have an idea?
    Thanks!

    Shouldn't that response be qualified? Somethinglike,
    where your datastructure doesn't need to be thread
    safe, use an ArrayList? I thought that was theonly
    real reason to use ArrayList over Vector. Arethere
    other reasons? Anyhow, his answer to your questionis
    correct, afaik.If you need synchronization... use ArrayList and the
    Collections.synchronizedList() method. Vector has too
    many non-List methods.
    I still say that is wrong, if your data structure needs to be thread safe, then you should use the synchronize on it where ever you use it.
    Is this code thread safe?
    Vector memberVector = new Vector();
    public void addToVector(Object c, Class cType ) {
    memberVector.add( c );
    memberVector.add(cType);
    }This should produce a vector with alternating objects and then a class that is associated with that object. However, will this code always work?
    The answer is no, even though the vector is 'thread safe' this operation is not. If 2 threads call this function on the same instance of the object, then you can get a situation where 2 objects appear in the list one after another. or 2 classes, it really depends on the thread task scheduler. The only difference between this and an ArrayList is that if you had used an ArrayList the internal structure might get messed up and you might get only one of the objects, and 2 classes or some other combination.
    So the answer to this problem is this
    Vector memberVector = new Vector();
    public void addToVector(Object c, Class cType ) {
    synchronized ( memberVector ) {
    memberVector.add( c );
    memberVector.add(cType);
    }You must sync on the member vector, but in this case, syncing on 'this' would work as well assuming that you used data encapsulation.
    I can't 'prove' it, but if you use proper syncing, then Vector, or any 'thread safe' data structure is no better then a non-thread safe version. It may be that it's easier to debug (sometimes) when dealing with vectors, since no elements will accidently be overwritten ,etc. But it's still unsafe.

Maybe you are looking for