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?

Similar Messages

  • How can I put the contents of an array into a set of write local variable clusters?

    I have a set of controls that a user fills in. The controls are clustered by rows, then combined into a 1D array, then written to a file. When I read the file, I want to feed the array back into the clusters with write local variables. Is there a simple way to handle the numerous local variable clusters so I can stuff the array back into them?
    Is there a better way to handle the whole issue of storing and recovering the information?
    The rows are steps in a procedure, and each row (cluster) contains numerical as well as string controls.

    There are many ways of doing this
    You may convert all your data to strings and save as an ascii file (you have to pay attention to the file format, so you can read it properly.
    Or you can use the configuration vi's, it may work in your case.
    or you may use an invoke node to get all controls of the vi's, save it, then read it, without worrying about any format. I have attached a vi that uses this method.
    Attachments:
    Temp.vi ‏52 KB

  • How can i put the values of the position of a pixel in an array ?

    Hello. I wanted to know if someone can help me with my problem. In fact i have to make an image treatment. For this i put my immage in an array and i work in this array thanks to two For loops. I wanted to know which pixel is white and which one is grey so i made a software and this works very well but know i would like to put the value of X and Y of each white pixel. unfortunately i don t know how to use Labview very well. So i tought about a system based on a conditional loop who put the value of X and Y in two 1D arrays. But i am not able to achieve it. This is what i tried but i don t know how to achieve it. If you guy or girls have solutions to my problem or an other way to do it go on ^^.
    Thanks every one.
    Attachments:
    Untitled.png ‏15 KB

    I am sure you can adapt one of the two solutions shown here.
    LabVIEW Champion . Do more with less code and in less time .

  • 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.

  • I-photo:  I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?

    I-photo:  I used 2 cameras to take pictures on a trip --- i have put the pictures from both cameras into an album --- when i click on view and then sort by date, the pictures do not sort by date --- any ideas on how to get the pics sorted by date?

    Select all the photos that you need to change, then click the "Photos" menu and choose "Adjust Date and Time".
    If you add a year, it will adjust all the photos that you selected by adding a year (so if you accidentally select one of the photos that already has "2012", that will change to "2013"). 

  • SUBMIT and return the value of that report into internal table

    Dear all,
    I have a requirement. I want to submit a report and return the value of that report into my internal table.
    How to do this.
    Pl. guide.

    Hi Vidhya,
    Below links from SAP help will resolve your issue.
    http://help.sap.com/saphelp_nw04/Helpdata/EN/fc/eb3bde358411d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3bd1358411d1829f0000e829fbfe/content.htm
    Edited by: Harsh Bhalla on Jan 2, 2010 11:54 AM

  • How can I reset the value of an array?

    How can I reset the value of an array at the beginning of my program?

    There is a option in LV,
    "Edit --> Make current value defult"
    Every time you reopen your VI, it will set to your custom default value.
    There are many ways of doing this.
    Another way of doing this is, You can use "sequence structure and property node". Make the property node of your array and choose "value". Then mark it to write. See attach.
    When you feel sad, laugh
    Attachments:
    x.GIF ‏4 KB

  • Is there any way to put the values inthe system matrix which is non editabl

    is there any way to put the values inthe system matrix which is non editable...
    this Q is not that much priority since i had achieved the requirement other way round by having user defined matrix ... but if i get the way for this it will help my add on performance much better...

    Hi Raj, I didnt get all the details but here some ideas how you can solve your issue:
    Depending in the system form you are working you can always use a DBDataSource in order to manipulate the rows in a matrix. It's much better as using the objects of the matrix itself. In this case you can use:
    oMatrix.FlushToDataSource()
    oDBDsource.SetValue("U_Quan", pVal.Row, "101")
    oMatrix.Clear()
    oMatrix.LoadFromDataSource()
    As you can see in SetValue i'm obtaining the Column, then the row number and then setting a NEW value for this cell.
    Please consider if you can use DBDataSource instead of UserDataSource.
    If the answer is yes then you can use the following:
    oMatrix.FlushToDataSource()
    '//Get the line you want
    matrix.GetLineData(pval.row)
    '//Call the Userdatasource assigned to that column
    UserDataSource = UserDataSources.Item("ItmCode")
    '//Set the new value
    m_UserDS.ValueEx = "A02520"
    oMatrix.LoadFromDataSource()
    You can also use:
    oMatrix.Columns.Item("ItemName").Cells.Item(l_rownum).Specific.String = "A02520"
    In case you are not assigning the string in a combobox of course.
    Good luck!
    Felipe

  • Can you tell me how I can put the data of sql server into SAP to auto gener

    Dear all,
             Can you tell me how I can put the data of sql server into SAP to auto generate PR?
    Best regards,
    Merry zhang

    Many thanks ,it is ok now.

  • I got  a new computer, how do i put the content of my ipad into itunes on the new computer

    i got  a new computer, how do i put the content of my ipad into itunes on the new computer?

    You should copy everything from your old computer, or your backup copy of your old computer, to your new one.

  • Putting the values into HashMap

    Hi Techies,
    I am having two string arrays as stringArray and stringArray1. I need to put the
    stringArray in keys and stringArray1 as values.
    import java.util.HashMap;
    import java.util.Map;
    public class DifferentStringArraysAndPuttingTheValuesIntoHashMap {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
          String[] stringArray = {"age","sex"};
          String[] stringArray1 = {"27","Male"};
          Map hm = new HashMap();
             How can I place age = 27 and sex = 'male' in hash map.
    regards,
    Krishna

    import java.util.HashMap;
    import java.util.Map;
    public class DifferentStringArraysAndPuttingTheValuesIntoHashMap {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
          String[] stringArray = {"age","sex"};
          String[] stringArray1 = {"27","Male"};
          Map<Integer, String> hm = new HashMap<Integer, String>();
    for (int i = 0; i < stringArray.length; i++) {
      hm.put(stringArray, stringArray1[i]);
    Use generics :) And this assumes that both arrays have equal length. For robustness you should check for this as well.

  • How to set the value of an array element (not the complete array) by using a reference?

    My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.
    In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).
    The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
    tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.
    If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.
    Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.
    I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.
    My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done ;-) but I'd still like to know ho
    w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.

    > My situation is that I have an array of clusters on the front panel.
    > Each element is used for a particular test setup, so if the array size
    > is three, it means we have three identical test setups that can be
    > used. The cluster contains two string controls and a button: 'device
    > ID' string, 'start' button and 'status' string.
    >
    > In order to keep the diagrams simple, I would like to use a reference
    > to the array as input into a subvi. This subvi will then modify a
    > particular element in the array (i.e. set the 'status' string).
    >
    It isn't possible to get a reference to a particular element within an
    array. There is only one reference to the one control that represents
    all elements in the array.
    While it may seem better to use references to update
    an element within
    an array, it shouldn't really be necessary, and it can also lead to
    race conditions. If you write to an element that has the
    possibility of the user changing, whether you write with a local, a
    reference, or any other means, there is a race condition between the
    diagram and the user. LV will help with this to a certain extent,
    especially for controls that take awhile to edit like ones that use
    the keyboard. In these cases, if the user has already started entering
    text, it will not be overwritten by the new value unless the key focus
    is taken away from the control first. It is similar when moving a slider
    or other value changes using the mouse. LV will write to the other values,
    but will not rip the slider out of the user's hand.
    To completely avoid race conditions, you can split the array into user
    fields and indicators that are located underneath them. Or, if some
    controls act as both, you can do like Excel. You don't directly type
    into the cell. You choose w
    hich cell to edit, but you modify another
    location. When the edit is completed, it is incorporated into the
    display so that it is never lost.
    Greg McKaskle

  • Putting attribute value from java level into sessionScope variable?

    Hallo,
    is it possible to put an attribute value from java level into a sessionScope variable?
    For example when i'am in prepareSession is it possible to fill a sessionScope variable which i can use in a jspx-Site? And when how i must do it?
    Any help is appreciated.

    At the java level i make this
    private void setUserIdIntoUserDataHashtable() {
    Integer userid = getUserIdForLoggedInUser();
    Integer groupid = getGroupIdForLoggedInUser();
    Hashtable userdata = getDBTransaction().getSession().getUserData();
    if (userdata == null){
    userdata = new Hashtable();
    userdata.put(PBConstants.CURRENT_USER_ID, userid);
    userdata.put(PBConstants.CURRENT_GROUP_ID, groupid);
    And when i at the java level i can use the constants. But i don't have an interaction at this point. Thats why i don't now how to bring the values to a sessionScope variable i need later in a / some sites?

  • Copy the value from one item into another

    Hi,
    I have a page with 2 items on it: Field1 and Field2. When the user enters a value in Field1 and tabs out, I want to copy the value to Field2.
    I have changed the setField1 method in the VORowImpl to call setField2 passing in the same value.
    In the JHeadstart definition file I have set the Depends On Item property of Field2 to be Field1.
    When I run the page and put a value in Field1 the page autosubmits as expected and the setField1 method runs. Unfortunately, the value does not appear in Field2.
    Any ideas?
    Thanks,
    Gavin

    Hi Steven,
    Checking the box does indeed get the value from Field1 into Field2.
    What I want to do, though, is to populate Field2 from Field1 only if Field2 is empty. Unfortunately, Field2 is now cleared before the setter of Field1 executes and so it always overwrites Field2.
    Any ideas?
    Thanks,
    Gavin

  • MIGO- Goods Issue- Order, the value is not written into Table COSP

    Hi,
      We make a substitution of wbs element of line item( BSEG-PROJK ). The wbs filed will be filled automatically when the user input a cost center or a order number.
    But we found some inconsistency in standard report S_ALR_87013558 OR CJI3.
    The following is what we have done:
    In Tcode F-02, we enter a order(e.g. A), then the WBS Element is filled automatically. when we post the document, and go to Standard report: S_ALR_87013558,
    we can see the amount in the report.
    In MIGO, we make a goods issue by order(e.g. A. Movement type is 261) , when we post, Material Document and Accounting document and Controlling document , but in report S_ALR_87013558 or CJI3. the amount is wrong, we can not see the amount we have done in MIGO.
    The movement type 201 is also wrong, the value is also not written into tabl cosp.
    But GI for project-movement type 221, the value is written into table cosp.
    Can you tell me this is wrong or right? if right, why? if wrong, how can i correct it, i need some customizing or others? or my substitution affect the result?
    Best Regards
    qingda

    Sorry, not reply these days.
    And very thanks for all your replies.
    I am a abaper, not familiar with the business.
    The business consultant want to control budget, control cost. 
    At first, he let me do a substibution in FI line item of besg-projk(WBS Element), when we he test the substitution in TCode F-02, the WBS field is filled automatically as per G/L account and Cost Center or as per G/L Account and Order, and then in Standard Report 'S_ALR_87013558', we can see the changes of the cost.
    But when biz consultant do a MIGO->Goods Issue by order, we can not see the changes of the cost,but the value of WBS in FI Accounting Document is substituted correctly.
    And if we enter the WBS manually when we do a MIGO->Goods Issue by order, we can see the changes of the report 'S_ALR_87013558'.
    In the original post, i was wrong, when we do a goods issue with movement type 201, the result is the same as 261, also we cant see the changes. but if we enter the wbs manually(movement type 201),the changes is write to COSP table.
    The solution about the original requirement is right or wrong?
    Thank You All.
    Best Regards
    qingda

Maybe you are looking for

  • Using Apple TV bought in the U.S. in England

    Any issues using Apple TV bought in the U.S. in England ?

  • 9800 pro & 9.2.2

    My G4/QS/733 has lots of upgrades including the Radeon 9800 pro.Is it compatible with 9.2.2? I boot up into 9.2.2 ok but when I change the colors to 256(to play an old Atari game) and then i want to switch back to millions of colors all i get is a gr

  • Multiple SSL Certs in one SSL Proxy/VIP

    Guys I have a requirement to be able to provide SSL for two different sites that will resolve to the same VIP.  Ive created alot of SSL sites before and these work a treat with HTTP to HTTPS redirection. However Im not sure how are take two different

  • Drivers for hpdiskjet 995c for wimdows 8

    I just bought a new hp pc with windows 8.  I have an HPdeskjet 995c printer and can not find the printer drivers to make it   work with windows 8.  Can anyone help?

  • Import Signatures into Mail.app

    I'm trying to find out if there is a way to import signatures from a web based account such as yahoo or something similar. I have the POP setup already and the email is working fine but it would nice to be able to import signatures b/c the content of