Accessing values in an array of JComboBoxes

Hello. I am building a program to calculate a user's GPA. This is a class assignment and so has some requirements I'm meeting.
There are two event handlers: One runs a loop to add course input lines; one calculates the GPA based on the inputs.
There are two related problems: When I instantiate JComboBoxes into two arrays (credits[] and grade[]) in the loop, the layout works but the calculate button only returns the values of credits[0] and grade[0] regardless of selection. When I instantiate the arrays outside the loop, the calculate button works but not the layout. I am at a complete loss. I'm posting the full code with comments. Sorry for it being very long.
package macdonnell_COMP228Lab4_Ex1;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GPACalc extends JFrame {
     private String[] letterGrades = {"A+","A","B+","B","C+","C","D+","D","Fail"}; // Values to be used in combGrades
     private double[] gradePoints = {4.5,4.0,3.5,3.0,2.5,2.0,1.5,1.0,0};
     private String[] numberCourses = {"0","1","2","3","4","5","6","7","8"}; // Used to fill cbNumberCourses
     private String[] creditHours = {"1","2","3","4"}; //number of hours per week in the class
     private String[] numberGrades = {"90-100%","80-89%","75-79%","70-74%","65-69%","60-64%","55-59%","50-54%","0-49%"};
     private String[] combGrades = new String[9]; // Used to fill the JComboBox in grade[]
     //Arrays to hold JComboBoxes for Course Inputs
     private JComboBox[] credits = new JComboBox[8];
     private JComboBox[] grade = new JComboBox[8];
     private JLabel lblCreditHoursEarned = new JLabel("Credit Hours Earned: ");
     private JTextField txtCreditHoursEarned = new JTextField(5);
     private JLabel lblCurrentGPA = new JLabel("Current GPA: ");
     private JTextField txtCurrentGPA = new JTextField(5);
     private JLabel lblNumberCourses = new JLabel("Number of Courses: ");
     private JComboBox cbNumberCourses = new JComboBox(numberCourses); //ComboBox for users to select number of course inputs
     private JLabel lblNumber = new JLabel("Number: ");
     private JLabel lblCourseCode = new JLabel("Course Code: ");
     private JLabel lblCreditHours = new JLabel("Credit Hours: ");
     private JLabel lblGrade = new JLabel("Grade: ");
     private JLabel label;
     private JTextField coursCode;
     GridBagLayout gridBag;
     Container c;
     private JButton calculate = new JButton("Calculate");
     CalculateButtonHandler calculateButton = new CalculateButtonHandler();
     private JLabel lblYourGPA;
     public GPACalc(){
          for (int i = 0; i < combGrades.length; i++){
               combGrades[i] = letterGrades[i] + ": " + numberGrades;
          /* This block is used for instantiating the JComboBoxes in credits[] and grade[] outside the loop
          //Assign course input ComboBoxes to arrays
          credits[0] = new JComboBox(creditHours);
          credits[1] = new JComboBox(creditHours);
          credits[2] = new JComboBox(creditHours);
          credits[3] = new JComboBox(creditHours);
          credits[4] = new JComboBox(creditHours);
          credits[5] = new JComboBox(creditHours);
          credits[6] = new JComboBox(creditHours);
          credits[7] = new JComboBox(creditHours);
          grade[0] = new JComboBox(combGrades);
          grade[1] = new JComboBox(combGrades);
          grade[2] = new JComboBox(combGrades);
          grade[3] = new JComboBox(combGrades);
          grade[4] = new JComboBox(combGrades);
          grade[5] = new JComboBox(combGrades);
          grade[6] = new JComboBox(combGrades);
          grade[7] = new JComboBox(combGrades);
          gridBag = new GridBagLayout();
     c = getContentPane();
     c.setLayout(gridBag);
     // ROW 1
     GridBagConstraints Constr1 = new GridBagConstraints();
     Constr1.gridx = 0; //first column
     Constr1.gridy = 0; //first row
     Constr1.gridwidth = 2; //number of cells in the row that will be covered
     Constr1.gridheight = 1; //number of cells in the column
     Constr1.fill = GridBagConstraints.HORIZONTAL; //resize the component horizontally
     // add the text field
     gridBag.setConstraints(lblCreditHoursEarned, Constr1); //apply the constraints to the grid
     c.add(lblCreditHoursEarned);
     GridBagConstraints Constr2 = new GridBagConstraints();
     Constr2.gridx = 3; //second column
     Constr2.gridy = 0; //first row
     Constr2.gridwidth = 1; //number of cells in the row that will be covered
     Constr2.gridheight = 1; //number of cells in the column
     Constr2.fill = GridBagConstraints.HORIZONTAL; //resize the component horizontally
     // add the text field
     gridBag.setConstraints(txtCreditHoursEarned, Constr2); //apply the constraints to the grid
     c.add(txtCreditHoursEarned);
     GridBagConstraints Constr3 = new GridBagConstraints();
     Constr3.gridx = 5; //fourth column
     Constr3.gridy = 0; //first row
     Constr3.gridwidth = 1; //number of cells in the row that will be covered
     Constr3.gridheight = 1; //number of cells in the column
     Constr3.fill = GridBagConstraints.HORIZONTAL; //resize the component horizontally
     // add the text field
     gridBag.setConstraints(lblCurrentGPA, Constr3); //apply the constraints to the grid
     c.add(lblCurrentGPA);
     GridBagConstraints Constr4 = new GridBagConstraints();
     Constr4.gridx = 6; //fifth column
     Constr4.gridy = 0; //first row
     Constr4.gridwidth = 1; //number of cells in the row that will be covered
     Constr4.gridheight = 1; //number of cells in the column
     Constr4.fill = GridBagConstraints.HORIZONTAL; //resize the component horizontally
     // add the text field
     gridBag.setConstraints(txtCurrentGPA, Constr4); //apply the constraints to the grid
     c.add(txtCurrentGPA);
     //ROW 2
     GridBagConstraints Constr5 = new GridBagConstraints();
     Constr5.gridx = 5; //fourth column
     Constr5.gridy = 1; //second row
     Constr5.gridwidth = 1; //number of cells in the row that will be covered
     Constr5.gridheight = 1; //number of cells in the column
     Constr5.fill = GridBagConstraints.HORIZONTAL; //resize the component horizontally
     // add the text field
     gridBag.setConstraints(lblNumberCourses, Constr5); //apply the constraints to the grid
     c.add(lblNumberCourses);
     GridBagConstraints Constr6 = new GridBagConstraints();
     Constr6.gridx = 6; //fourth column
     Constr6.gridy = 1; //second row
     Constr6.gridwidth = 1; //number of cells in the row that will be covered
     Constr6.gridheight = 1; //number of cells in the column
     Constr6.fill = GridBagConstraints.HORIZONTAL; //resize the component horizontally
     // add the text field
     gridBag.setConstraints(cbNumberCourses, Constr6); //apply the constraints to the grid
     c.add(cbNumberCourses);
     //ROW 3
     GridBagConstraints Constr7 = new GridBagConstraints();
     Constr7.gridx = 0;
     Constr7.gridy = 2;
     Constr7.gridwidth = 1;
     Constr7.gridheight = 1;
     Constr7.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(lblNumber, Constr7);
     c.add(lblNumber);
     GridBagConstraints Constr8 = new GridBagConstraints();
     Constr8.gridx = 2;
     Constr8.gridy = 2;
     Constr8.gridwidth = 1;
     Constr8.gridheight = 1;
     Constr8.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(lblCourseCode, Constr8);
     c.add(lblCourseCode);
     GridBagConstraints Constr9 = new GridBagConstraints();
     Constr9.gridx = 4;
     Constr9.gridy = 2;
     Constr9.gridwidth = 1;
     Constr9.gridheight = 1;
     Constr9.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(lblCreditHours, Constr9);
     c.add(lblCreditHours);
     GridBagConstraints Constr10 = new GridBagConstraints();
     Constr10.gridx = 6;
     Constr10.gridy = 2;
     Constr10.gridwidth = 1;
     Constr10.gridheight = 1;
     Constr10.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(lblGrade, Constr10);
     c.add(lblGrade);
     //ROW 4 is built by the event handler cbNumberCourses.addItemListener at line 191; insert panel to hold ROW 4
     //ROW 5
     GridBagConstraints Constr11 = new GridBagConstraints();
     Constr11.gridx = 6;
     Constr11.gridy = 11;
     Constr11.gridwidth = 1;
     Constr11.gridheight = 1;
     Constr11.fill = GridBagConstraints.HORIZONTAL;
     gridBag.setConstraints(calculate, Constr11);
     c.add(calculate);
     //ROW 6 is added in the SubmitButtonHandler at line 242
     calculate.addActionListener(calculateButton);
     cbNumberCourses.addItemListener(
               new ItemListener(){
                    public void itemStateChanged(ItemEvent e){
                         for (int i = 0; i < cbNumberCourses.getSelectedIndex(); i++){
                              label = new JLabel(Integer.toString(i+1));
                              coursCode = new JTextField(10);
                              GridBagConstraints ConstrA = new GridBagConstraints();
                              ConstrA.gridx = 0;
                              ConstrA.gridy = i+4;
                              ConstrA.gridwidth = 1;
                              ConstrA.gridheight = 1;
                              ConstrA.fill = GridBagConstraints.HORIZONTAL;
                              gridBag.setConstraints(label, ConstrA);
                              c.add(label);
                              GridBagConstraints ConstrB = new GridBagConstraints();
                              ConstrB.gridx = 2;
                              ConstrB.gridy = i+4;
                              ConstrB.gridwidth = 1;
                              ConstrB.gridheight = 1;
                              ConstrB.fill = GridBagConstraints.HORIZONTAL;
                              gridBag.setConstraints(coursCode, ConstrB);
                              c.add(coursCode);
                              credits[i] = new JComboBox(creditHours);
                              GridBagConstraints ConstrC = new GridBagConstraints();
                              ConstrC.gridx = 4;
                              ConstrC.gridy = i+4;
                              ConstrC.gridwidth = 1;
                              ConstrC.gridheight = 1;
                              ConstrC.fill = GridBagConstraints.HORIZONTAL;
                              gridBag.setConstraints(credits[i], ConstrC);
                              c.add(credits[i]);
                              grade[i] = new JComboBox(combGrades);
                              GridBagConstraints ConstrD = new GridBagConstraints();
                              ConstrD.gridx = 6;
                              ConstrD.gridy = i+4;
                              ConstrD.gridwidth = 1;
                              ConstrD.gridheight = 1;
                              ConstrD.fill = GridBagConstraints.HORIZONTAL;
                              gridBag.setConstraints(grade[i], ConstrD);
                              c.add(grade[i]);
                         c.validate();
     private class CalculateButtonHandler implements ActionListener{
          public void actionPerformed(ActionEvent event){
               double creds, points, qualityPoints, gpa;
               double totalQualityPoints = 0;
               double totalCredits = 0;
               for (int i = 0; i < cbNumberCourses.getSelectedIndex(); i++){
                    System.out.println(i);
                    System.out.println(credits[i].getSelectedItem());
                    System.out.println(grade[i].getSelectedItem());
                    //creds = Double.parseDouble(creditHours[credits[i].getSelectedIndex()]);
                    creds = Double.parseDouble((String)credits[i].getSelectedItem());
                    points = gradePoints[grade[i].getSelectedIndex()];
                    totalCredits = totalCredits + creds;
                    qualityPoints = creds * points ;
                    totalQualityPoints = totalQualityPoints + qualityPoints;
                    System.out.println(creds);
                    System.out.println(points);
               gpa = totalQualityPoints / totalCredits;
               String yourGPA = "Your GPA is: " + gpa;
               lblYourGPA = new JLabel(yourGPA);
               GridBagConstraints Constr12 = new GridBagConstraints();
          Constr12.gridx = 3;
          Constr12.gridy = 12;
          Constr12.gridwidth = 1;
          Constr12.gridheight = 1;
          Constr12.fill = GridBagConstraints.HORIZONTAL;
          gridBag.setConstraints(lblYourGPA, Constr12);
          c.add(lblYourGPA);
          c.validate();
     public static void main(String[] args) {
          GPACalc mf = new GPACalc();
          mf.setSize(650,700);
          mf.setVisible( true ); // display frame

I changed the cbNumberCourses.addItemListener to an ActionListener. For whatever reason, this has fixed all my problems.

Similar Messages

  • Access values stored in 2D Array in HashMap

    Hi everyone i would like to know how to access values stored in a 2D array inside a HashMap
    Here is a drawing representation of the map.
    So to get the KEYS I just have to execute this code:
    this.allPeople = personInterests.keySet();But how can I get acces to the actual values inside the 2D Array?
    My goal is to create a treeSet and store all the elements of the first array in it, then look at the second array if any new elements are detected add them to the treeset, then third array and so on.
    I tried this code:
    Object[] bands = personInterests.values().toArray();
         for( int i=0; i<bands.length; i++)
              this.allBands.add(bands.toString());
    }But this.allBands.add(bands[i].toString())seems to be the problem, Dealing with a 2D array, this code only return a string representation of the Arrays and not a string representation of their elements.
    Using my logic I tried to execute:
       this.allBands.add(bands[0][i].toString());But i get a ARRAY REQUIRED BUT JAVA.LANG.OBJECT FOUND
    I really don't know the way to go.
    Thanks to anyone that will help.
    Regards, Damien.
    Edited by: Fir3blast on Mar 3, 2010 5:27 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You'll just need to cast the object to the correct type. This is nothing to do with HashMap at all. If you don't know what that means then your google keywords are "java cast tutorial".

  • Accessing values in multi-dimensional arrays

    Hello, I created a 2 dimensioned array, not sure if it is done in the correct way but it works like this:
    var arrLines:Array = new Array(new Array());
    arrLines.pop(); // because it creates an empty value to begin with
    Anyway, I am not sure how to access individual values within this array.
    arrLines.push([100, 200],[300, 400]); // creates 2 compartments each with 2 sub compartments
    trace(arrLines[0]); //displays 100, 200
    How would I make it trace only 100 OR 200?
    Thanks.

    use:
    var arrLines:Array = new Array();
    //arrLines.pop(); // because it creates an empty value to begin with
    arrLines.push([100, 200],[300, 400]); // creates 2d array
    trace(arrLines[0][0]); //displays 100
    trace(arrLines[0][1]); //200
    trace(arrLines[1][0]); //300
    trace(arrlines[1][1]); //400
    Thanks.

  • Putting the values of an array into a combobox

    Hey I'm looking for some advice on an error I'm getting
    First heres the program:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    public class Quizgame implements EventListener {
         JPanel mainPanel;
         JFrame theFrame;
         public static void main(String[] args) { Quizgame b = new Quizgame(); b.buildGUI(); }
         public void buildGUI() {
              Quizbook Q = new Quizbook("C:\\Users\\Boab\\Desktop\\JavaRe-sit\\FileInput.txt");
              String question = Q.getContent(0);
              String Ans1= Q.getContent(1);
              String Ans2= Q.getContent(2);
              String Ans3= Q.getContent(3);
              String Ans4= Q.getContent(4);
              theFrame=new JFrame("QuizGame");
              BorderLayout layout = new BorderLayout();
              JPanel background = new JPanel(layout);
              background.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              Box buttonBox = new Box (BoxLayout.Y_AXIS);
              JButton start = new JButton("Submit");
              start.addActionListener(new MyStartListener());
              buttonBox.add(start);
              JComboBox Answer = new JComboBox(Q);
              start.addActionListener(new MyStartListener());
              buttonBox.add(Answer);
              Box QuestionBox = new Box(BoxLayout.X_AXIS);
              Box nameBox = new Box(BoxLayout.Y_AXIS);
              nameBox.add (new Label(Ans1));
              nameBox.add (new Label(Ans2));
              nameBox.add (new Label(Ans3));
              nameBox.add (new Label(Ans4));
              QuestionBox.add(new Label(question));
              background.add(BorderLayout.EAST, buttonBox);
              background.add(BorderLayout.WEST, nameBox);
              background.add(BorderLayout.NORTH, QuestionBox);
              theFrame.getContentPane().add(background);
              GridLayout grid = new GridLayout(16,16);
              grid.setVgap(1); grid.setHgap(2);
              mainPanel = new JPanel(grid);
              background.add(BorderLayout.CENTER, mainPanel);
              theFrame.setBounds(150,150,1,1); theFrame.pack(); theFrame.setVisible(true);
         public class MyStartListener implements ActionListener {
         public void actionPerformed(ActionEvent a) {
                   //where you put whats to happen
         public class comboListener implements ActionListener {
         public void actionPerformed(ActionEvent a) {
                   //where you put whats to happen
         There is another file which creates an array of strings with the instance Q in this class ^
    I'm trying to fill the combobox with the values of the array but I can't get it too work. With the code as it is now I get:
    C:\Users\Boab\Desktop\Seperate Java files\NewQuiz\Quizgame\Quizgame.java:41: cannot find symbol
    symbol : constructor JComboBox(Quizbook)
    location: class javax.swing.JComboBox
              JComboBox Answer = new JComboBox(Q);
    ^
    1 error
    I don't really understand why it doesn't work, When I look up the error online its about the class but it works fine without the Combobox line. Any ideas why it won't put the array into the combobox?
    Also my next step is to put only certain values into the combobox i.e values 2-4 in the array, Is there any smart piece of code to do this or do I need to put a loop in with an addcontent and hardcode it?
    Thanks for any help

    Yeah sorry, Quizbook is a class with a method to read out the array the method is:
         public String getContent(int element)
              //access arraylist and return
              return (String)Quizbook.get(element);
         so I tried what you said and put :
    JComboBox Answer = new JComboBox(Q.getContent(5));
    Because the Answer is at that location in the array but it gave me the same error message:
    C:\Users\Boab\Desktop\Seperate Java files\NewQuiz\Quizgame\Quizgame.java:41: cannot find symbol
    symbol : constructor JComboBox(java.lang.String)
    location: class javax.swing.JComboBox
              JComboBox Answer = new JComboBox(Q.getContent(3));
    ^
    1 error
    Process completed.
    So I would of thought that meant use the getContent method from Q object with element bieng 3?

  • Get distinct values from plsql array

    Hi,
    I have declared a variable as below in plsql proc.
    type t_itemid is table of varchar2(10);
    inserted set of items in to this using a program
    now i want distinct values from that array how can i get it.

    I am using 9i so i cannot use set operator and more over my problem is that i am declaring the variable inside the plsql block . when i tried i am getting the below errors:
    SQL> r
    1 declare
    2 type t_type is table of varchar2(10);
    3 v_type t_type;
    4 begin
    5 v_type := t_type('toys','story','good','good','toys','story','dupe','dupe');
    6 for i in (select column_value from table(v_type)) loop
    7 dbms_output.put_line(i.column_value);
    8 end loop;
    9* end;
    for i in (select column_value from table(v_type)) loop
    ERROR at line 6:
    ORA-06550: line 6, column 41:
    PLS-00642: local collection types not allowed in SQL statements
    ORA-06550: line 6, column 35:
    PL/SQL: ORA-22905: cannot access rows from a non-nested table item
    ORA-06550: line 6, column 10:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 7, column 22:
    PLS-00364: loop index variable 'I' use is invalid
    ORA-06550: line 7, column 1:
    PL/SQL: Statement ignored

  • Assigning a value to an array cell populated [BULK]

    Hi all,
    I've got a problem in assigning a value to an array populated with BULK COLLECT INTO .
    I can reproduce the problem with this
    CREATE TABLE TEST_TABLE (
    value1 NUMBER,
    value2 NUMBER
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);
    INSERT INTO test_table VALUES(1,1);And this is the PL/SQL anonymous block that gives me problems:
    DECLARE
      SUBTYPE t_rec IS TEST_TABLE%ROWTYPE;
    TYPE records_table IS TABLE OF t_rec;
      elist RECORDS_TABLE;
      CURSOR table_cursor IS SELECT * FROM TEST_TABLE WHERE rownum <= 20;
    BEGIN
      OPEN table_cursor;
      FETCH table_cursor BULK COLLECT INTO elist;
        FOR j IN 1..elist.COUNT
        LOOP
          elist(j)(1) := elist(j)(1) +1;
        END LOOP;
      CLOSE table_cursor;
    END; The error is
    ORA-06550: line 13, column 7:
    PLS-00308: this construct is not allowed as the origin of an assignment
    ORA-06550: line 13, column 7:
    PL/SQL: Statement ignored
    06550. 00000 -  "line %s, column %s:\n%s"
    *Cause:    Usually a PL/SQL compilation error.
    *Action:So it doesn't compile because of this line of code:
    elist(j)(1) := elist(j)(1) +1;
    Why doesn't it work?
    If I try to do this, works perfectly:
    DECLARE
    TYPE v_num_table
    IS
      TABLE OF NUMBER;
    TYPE v_2_num_table
    IS
      TABLE OF v_num_table;
      v_nums V_2_NUM_TABLE := V_2_NUM_TABLE();
    BEGIN
      v_nums.EXTEND;
      v_nums(1) := v_num_table();
      v_nums(1).EXTEND;
      v_nums(1)(1) := 1;
      v_nums(1)(1) := v_nums(1)(1) +1;
      dbms_output.put_line(v_nums(1)(1) );
    END;Edited by: user10396517 on 2-mar-2012 2.35

    Variable "elist" is a collection of record, so you access an individual field of a given collection element by specifying the field name, not its position :
    DECLARE
      SUBTYPE t_rec IS TEST_TABLE%ROWTYPE;
      TYPE records_table IS TABLE OF t_rec;
      elist RECORDS_TABLE;
      CURSOR table_cursor IS SELECT * FROM TEST_TABLE WHERE rownum <= 20;
    BEGIN
      OPEN table_cursor;
      FETCH table_cursor BULK COLLECT INTO elist;
        FOR j IN 1..elist.COUNT
        LOOP
          elist(j).value1 := elist(j).value1 + 1;
        END LOOP;
      CLOSE table_cursor;
    END;Your second example is different as you're dealing with a collection of collections.

  • Unable to access values from database in login page..

    Hey all,
    Friends I have a login.jsp page and I want if i enter username and password then it will be accessed from database and after verifying the details it will open main.jsp.I made a database as "abc" and created DSN as 1st_login having table 1st_login. But the problem is that I am unable to access values from database.
    So Please help me.
    Following is my code:
    <HTML>
    <body background="a.jpg">
    <marquee>
                        <CENTER><font size="5" face="times" color="#993300"><b>Welcome to the"<U><I>XYZ</I></U>" of ABC</font></b></CENTER></marquee>
              <br>
              <br>
              <br>
              <br><br>
              <br>
         <form name="login_form">
              <CENTER><font size="4" face="times new roman">
    Username          
              <input name="username" type="text" class="inputbox" alt="username" size="20"  />
              <br>
         <br>
              Password          
              <input type="password" name="pwd" class="inputbox" size="20" alt="password" />
              <br/>
              <input type="hidden" name="option" value="login" />
              <br>
              <input type="SUBMIT" name="SUBMIT" class="button" value="Submit" onClick="return check();"> </CENTER>
              </td>
         </tr>
         <tr>
              <td>
              </form>
              </table>
    <%
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connection = DriverManager.getConnection("jdbc:odbc:1st_login");
    Statement statement = connection.createStatement();
    String query = "SELECT username, password FROM 1st_login WHERE username='";
    query += request.getParameter("username") + "' AND password='";
    query += request.getParameter("password") + "';";
    ResultSet resSum = statement.executeQuery(query);
    //change: you gotta move the pointer to the first row of the result set.
    resSum.next();
    if (request.getParameter("username").equalsIgnoreCase(resSum.getString("username")) && request.getParameter("password").equalsIgnoreCase(resSum.getString("password")))
    %>
    //now it must connected to next page..
    <%
    else
    %>
    <h2>You better check your username and password!</h2>
    <%
    }catch (SQLException ex ){
    System.err.println( ex);
    }catch (Exception er){
    er.printStackTrace();
    %>
    <input type="hidden" name="op2" value="login" />
         <input type="hidden" name="lang" value="english" />
         <input type="hidden" name="return" value="/" />
         <input type="hidden" name="message" value="0" />
         <br>
              <br><br>
              <br><br>
              <br><br><br><br><br>
              <font size="2" face="arial" color="#993300">
         <p align="center"> <B>ABC &copy; PQR</B>
    </BODY>
    </HTML>
    and in this code i am getting following error
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:93: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:93: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:94: cannot find symbol_
    C:\Project\SRS\build\generated\src\org\apache\jsp\loginjsp.java:95: cannot find symbol_
    4 errors
    C:\Project\SRS\nbproject\build-impl.xml:360: The following error occurred while executing this line:
    C:\Project\SRS\nbproject\build-impl.xml:142: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 6 seconds)

    As long as you're unable to compile Java code, please use the 'New to Java' forum. This is really trival.
    To ease writing, debugging and maintenance, I highly recommend you to write Java code in Java classes rather than JSP files. Start learning Servlets.

  • How to get the values of an Array using JSP Tags

    Hey guys,
    I need some help. I've splited a String using
    fn:split(String, delim) where String = "1,2,3,4" and delim is ,
    This method returns an Array of splited Strings. how do i get the values from this array using jsp tags. I don't wanna put java code to achive that.
    Any help would be highly appreciated
    Thanks

    The JSTL forEach tag.
    In fact if all you want to do is iterate over the comma separated list, the forEach tag supports that without having to use the split function.
    <c:set var="list" value="1,2,3,4"/>
    <c:forEach var="num" items="${list}">
      <c:out value="${num}"/>
    </c:forEach>The c:forTokens method will let you do this with delimiters other than a comma, but the forEach tag works well just with the comma-delimited string.

  • How do I remove NaN values from an array?

    I'm trying to test if the values in an array are less than 0.001. All of them are...BUT the problem is that some of the elements in the array are NaN. I'd like to do one of two things:
    1. Remove the NaN elements from the array and set them to zero to make the test work.
    2. Make the test understand that NaN elements are okay.
    The test results in a boolean array of T/F values. If all of the values of the boolean array are T, it will result in a single boolean value of T. In #2, I am saying that I want it to test if an element of the array is less than 0.001 OR equal to NAN.
    Solved!
    Go to Solution.

    Your statements don't make much sense. It's irrelevant how many NaNs are in the array. A sort will move them all to the bottom. You had said you wanted to find out if all the elements in an array are less than 0.001, and that you've got some NaNs in there. Well, this will do that:
    twolfe13 wrote:
     I did see how to remove NaN once, but couldn't determine a good way to generalize it other than doing a test loop. I thought there might have been a simple function that I overlooked to do this.
    As I noted, there have been several posts in the past about efficient techniques for removing certain elements out of an array. Seek, and ye shall find.
    Joseph Loo wrote:
    Have you look at the coerce function where you can set the lower and upper limit?
    That won't do anything for NaN. Or perhaps I misunderstood what you are suggesting to do?
    Attachments:
    NaN sort.png ‏20 KB
    NaN sort small.png ‏5 KB

  • Using DMA to update values in an array

    Good afternoon, 
    I've been running into a few problems with my vi, and I'd like to give a bit of the background information before I ask my questions. I'm using Labview 8.5 and the NI USB-6009 DAQ. I want to use an encoder to control values that are being written to a file for DMA. I found that I couldn't use the encoder as an external clock since the 6009 DAQ doesn't have this capability. So I've been trying to go a differenet route by using a case structure with a True/false statement to allow me to input values from a simulated signal into a write vi (each time the encoder pulses, a value from the simulated signal should be inputed into the write data storage vi). From there, I want to then read those values and put them into an array. So the plan is to have a 10 element array that reads in values from the storage file (just like in FIFO for FPGA). As I continue reading values, the oldest value of the 10 element array will leave the array and be replaced by a new value. 
     Now here come the questions, I'm using the Write/Read data storage vi's and I keep getting errors. First, if I'm wanting to use DMA to read these values am I using the correct vi's, or is there a different route? Also, once I read these values into the array how would I be able to constantly update the array in a descending order from begining to end of the stored values? 
    I'm posting my most recent vi that I've been editing. Also, in advance, thank you!
    -tjm
    Attachments:
    Using Encoder as an analog input 10_9_13 - Copy - Copy.vi ‏390 KB

    Thank you for your reply.
    First, I'm ultimately trying to use the array as input into a visual display for a meter (to display the mean of the array). I've been successful (in the past) with inputting into an array by not using DMA and using the Sort 1D Array point by point vi. The only problem is the timing mechanism with the encoder, and you are correct with stating that there is uncertainty with the encoder when trying to retrieve values from the input signal (sine wave). I thought about going down the route of using the encoder as a counter (since I am able to see the counter increase by a single digit with each pulse).
    My question would then be how to control the case structure with a counter input? 
    I'm posting both my setup with the Sort 1D Array Point by Point and the simple vi for the encoder as a counter. My idea is to try to merge the two and have the counter control the case structure. 
    Is there a way I can do this? 
    Attachments:
    Sort 1D Array Pt by Pt.vi ‏189 KB
    Using Encoder as a counter input 10_9_13.vi ‏123 KB

  • How to take a field value in an array?

    how to take a field value in an array? its urgent........

    yaa... i know,  but actually we need to  multiply that number with some digit.
    take it this is way, if  i push it into another array, we have an array of digits but what i need is a all digit to be together to be multiplied to a number
    for example -
    if i push the numbers into new array say arr[];
    so i will have something like this. arr[1,2,3,4,5,6.......]  
    but i need  the new varaible should have value as 12345........   all concatenated.
    if i perform operation on array each digit will be multiplied individually.
    hope u got what m trying to sayy....
    Thanks for the prompt response..........

  • Finding a minimum value in an array without using loops

    I can find a minimum value in an array using a loop, but I am unsure of how to do it without any type of of loop
    Here is what I have using a loop:
    // This method searches for the minimum value in an array
    public static int min(int a[]){
    int min = a[0];
    for(int i = 1; i < a.length; i++){
    if(a[i] < min){
    min = a;
    return min;
    How do I covert this to do the same thing, using no loops?
    Thank you for replies
    Edited by: kazmania on Feb 7, 2008 12:26 PM

    public class Test112 {
    public int recurse(int[] x, int i, int n)
    if (i==x.length-1) { return (x[i] < n) ? x[i] : n; }
    n = (n < x[++i]) ? n : x;
    return recurse(x, i, n);
    public static void main(String[] args) {
    int[] nums = {3, 1, 56, 2, 99, 34, 5, 78, -400, 2383, 201, -9, -450};
    Test112 t = new Test112();
    int min = t.recurse(nums, 0, nums[0]);
    System.out.println(min);

  • Store XML node value into an array with node element name

    Hi,
    I have the following code that displays the node element with the
    corresponding node value. I want to store the values in an array in
    reference to the node name.
    i.e.
    XML (my xml is much bigger than this, 300 elements):
    <stock>
    <symbol>SUNW</symbol>
    <price>17.1</price>
    </stock>-----
    would store the following:
    *data[symbol] = SUNW;*
    *data[price] = 17.1;*
    Thanks in advance,
    Tony
    test.jsp
    Here's my source code:
    <html>
    <head>
    <title>dom parser</title>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="dombean.*" %>
    </head>
    <body bgcolor="#ffffcc">
    <center>
    <h3>Pathways Info</h3>
    <table border="2" width="50%">
    <jsp:useBean id="domparser" class="dombean.MyDomParserBean" />
    <%
    Document doc = domparser.getDocument("c:/stocks/stocks.xml");
    traverseTree(doc, out);
    %>
    <%! private void traverseTree(Node node,JspWriter out) throws Exception {
    if(node == null) {
    return;
    int type = node.getNodeType();
    switch (type) {
    // handle document nodes
    case Node.DOCUMENT_NODE: {
    out.println("<tr>");
    traverseTree
    (((Document)node).getDocumentElement(),
    out);
    break;
    // handle element nodes
    case Node.ELEMENT_NODE: {
    String elementName = node.getNodeName();
    //if(elementName.equals("MOTHER-OCC-YRS-PREVIOUS")) {
    //out.println("</tr>");
    out.println("<tr><td>"+elementName+"</td>");
    NodeList childNodes =
    node.getChildNodes();     
    if(childNodes != null) {
    int length = childNodes.getLength();
    for (int loopIndex = 0; loopIndex <
    length ; loopIndex++)
    traverseTree
    (childNodes.item(loopIndex),out);
    break;
    // handle text nodes
    case Node.TEXT_NODE: {
    String data = node.getNodeValue().trim();
    //if((data.indexOf("\n")  <0) &#38;&#38; (data.length() > 0)) {
    out.println("<td>"+data+"</td></tr>");
    %>
    </table>
    </body>
    </html>
    {code}
    *MyDomParserBean.java*
    Code: package dombean;
    {code:java}
    import javax.xml.parsers.*;
    import org.w3c.dom.*;
    import java.io.*;
    public class MyDomParserBean
    implements java.io.Serializable {
    public MyDomParserBean() {
    public static Document
    getDocument(String file) throws Exception {
    // Step 1: create a DocumentBuilderFactory
    DocumentBuilderFactory dbf =
    DocumentBuilderFactory.newInstance();
    // Step 2: create a DocumentBuilder
    DocumentBuilder db = dbf.newDocumentBuilder();
    // Step 3: parse the input file to get a Document object
    Document doc = db.parse(new File(file));
    return doc;
    {code}
    Edited by: ynotlim333 on Sep 24, 2007 8:41 PM
    Edited by: ynotlim333 on Sep 24, 2007 8:44 PM
    Edited by: ynotlim333 on Sep 24, 2007 8:45 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I still need to store it in an array because its 300 elements in the XML stocks.
    I've done the following but its not working, i'm getting error codes. I think its an easy fix. I'd also like to pass a String instead of a .xml document b/c my xml is stored inside a DB. Any suggestions on that?
    <html>
    <head>
    <title>dom parser</title>
    <%@ page import="javax.xml.parsers.*" %>
    <%@ page import="org.w3c.dom.*" %>
    <%@ page import="org.*" %>
    </head>
    <body bgcolor="#ffffcc">
    <center>
    <h3>Pathways Info</h3>
    <table border="2" width="50%">
    <jsp:useBean id="domparser" class="org.MyDomParserBean" />
    <%
    Document doc = domparser.getDocument("c:/stocks/stocks.xml");
    traverseTree(doc, out);
    %>
    <%!
            public String element_store = null;
            public String[] stock_data = new String[400];
            private void traverseTree(Node node,JspWriter out) throws Exception {
            if(node == null) {
               return;
            int type = node.getNodeType();
            switch (type) {
               // handle document nodes
               case Node.DOCUMENT_NODE: {
                 out.println("<tr>");
                 traverseTree
                 (((Document)node).getDocumentElement(),
                 out);
                 break;
              // handle element nodes
              case Node.ELEMENT_NODE: {
                String elementName = node.getNodeName();
                element_store = elementName;
                 //if(elementName.equals("MOTHER-OCC-YRS-PREVIOUS")) {
                   //out.println("</tr>");
                 NodeList childNodes =
                 node.getChildNodes();     
                 if(childNodes != null) {
                    int length = childNodes.getLength();
                    for (int loopIndex = 0; loopIndex <
                    length ; loopIndex++)
                       traverseTree
                       (childNodes.item(loopIndex),out);
                  break;
               // handle text nodes
               case Node.TEXT_NODE: {
                  String data = node.getNodeValue().trim();
                  if((data.indexOf("\n")  <0) && (data.length() > 0)) {
                  out.println("<tr><td>"+element_store+"</td>");
                  out.println("<td>"+data+"</td></tr>");
                  stock_data[element_store]=data;
    %>
    </table>
    </body>
    </html>

  • Problem in assigning value to an array element

    hi all
    in the following prog i am not able to assign the value to the array element
    i am not getting why it is giving me error
    //my program is as follows
    public class ArrayTest
         static int [] intArray = new int[5];
         static int [] intArray1 = new int[1];
         intArray1[0] = 5; // this line gives error
         static char [] charArray = new char[5];
         public static void main(String args[])
              System.out.println(charArray);
              intArray1 = intArray;
    }thanx in advance as usual

    The problem is that you try to execute code outside a method. This can be only done in form of a variable declaration or as a static initilization block which will be executed once when the class is loaded:public class ArrayTest
         static int [] intArray = new int[5];
         static int [] intArray1 = new int[1];
         static char [] charArray = new char[5];
         static {
              intArray[0] = 5;
         public static void main(String args[])
              System.out.println(charArray);
              intArray1 = intArray;
    }

  • Rate and accessable value is not displaying for the tax invoice output

    Hello All,
      Rate and accessable value is not displaying for the tax invoice output. Rest of all outputs for invoices shows Rate and accessable value.
    Scenerio is free of charge sales order (samples) removing the goods from pant so excise invoice has been created and also updated. but for tax invoice out put rate and access value is not displaying.
        Pricing procedure: In pricing procedure account keys have not been maintained because there is not gl account upadation during billing for free of charge delivery.
    Thanks & Regards,
    ramesh

    hi Gurpreet,
    You can add values to that transient column programatically,either by getiing the row from the iterator and then row.setAttribute('Column_name','Value');
    Or providing value to it in the SQL...

Maybe you are looking for

  • Problem with driver initialization and associated application

    I am recertifying a application suite on Solaris 10. This product works well on Solaris 8 & 9. It contains a special psuedo/streams device driver that allows applications to open a port to a daemon that manages clean up of these applications. The dae

  • OfficeJet Pro 8600 plus will not install , msg Call to DriverPackageInstall returns error 5

    I get message "Call to Driver Package Install returned error 5 for package -c\Program Files\HP\HP OfficeJet Pro 8600\Drivers Store\Pipeline\hpup\03.inf-Call to Driver Package Install must be a member of th eadministrator group to install a driver pac

  • Hard drive Replacement for PPC G3 B/W

    My understanding is the H3 B/W will only recognize a maximum size Hard Drive of 128 GB.  Since today's hard drivesizes are much larger, if I install a new hard drive larger than 128 GB, will the computer only allow me to only store 128GB of data or w

  • Apache with OracleXE Apex...

    Hi, I installed OracleXE on my laptop. I would be able to go to Start/All Programs/Oracle Database 10g Express Edition/Go To Database Home Page (which is C:\oraclexe\app\oracle\product\10.2.0\server\Database_homepage.url) I had installed my APEX app

  • ITunes 10 for OSX 10.5 only why?

    I was so bummed to see yet another major component/function of OS X not available for 10.4.11. Is this a "tech-under-the-hood" thing, or a money thing? I just don't need 10.5/6 and am not going to spend $130 for something I don't need - generally spe