Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How to add selected check boxs to arraylist

Options
  • 25-04-2015 6:41pm
    #1
    Registered Users Posts: 4


    Hey, I'm pretty new/bad at Java and completely new to GUI.
    How do I add selected checkboxs to an arraylist? I've tried looking around but can't really find anything that helps.
    Any help would be appreicated! :)





    public class testProcedures extends JPanel
    {
    private static JLabel procedureLabel;
    private static JButton orderButton, resetButton, quitButton;
    private static JTextArea orderDetails;
    private static JCheckBox[] procedure;
    private static int NUM_PROCEDURES= 5;
    static JTextField patientIDField;


    public testProcedures()
    {
    super();
    patientIDField = new JTextField("Enter Patient ID Number", 25);
    add(patientIDField);

    setPreferredSize(new Dimension(350,300));
    setLayout(new GridLayout(1,1));
    add(pane, new Dimension(1,1));
    setVisible(true);

    JFrame frame = new JFrame("Procedures");
    frame.setContentPane(split);
    frame.pack();
    frame.setVisible(true);*/
    }

    public void selectProcedures()
    {
    procedureLabel = new JLabel("Select Procedures");
    procedure= new JCheckBox[NUM_PROCEDURES];
    procedure[0] = new JCheckBox("Extraction",false);
    procedure[1] = new JCheckBox("Filling",false);
    procedure[2] = new JCheckBox("Cleaning",false);
    procedure[3] = new JCheckBox("Crown",false);
    procedure[4] = new JCheckBox("X-Ray",false);


    orderButton = new JButton("Set Procedures");
    orderButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event){



    processOrder();
    }
    });

    resetButton = new JButton("Reset Patient Procedures Form");
    resetButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event){
    resetForm();
    } });

    quitButton = new JButton("Quit Program");
    quitButton.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event){

    System.exit(0);
    } });

    orderDetails = new JTextArea("Awaiting Procedures....",5,40);
    add(procedureLabel);
    for (int index=0; index < NUM_PROCEDURES;++index)
    add(procedure[index]);
    add(orderButton);
    add(resetButton);
    add(quitButton);
    add(orderDetails);
    }

    static void processOrder()
    {
    String order = "Procedures Selected:";
    boolean proceduresSelected= false;

    String patientID = patientIDField.getText();
    int patientNumb = Integer.parseInt(patientID);
    ArrayList<Patient> PatientList = DentistTabbed.getPatientList();
    ArrayList <Procedure> procList = new ArrayList<Procedure>();
    for (int index=0; index < NUM_PROCEDURES;++index)
    if (procedure[index].isSelected())
    {
    //here
    for(Patient pat: PatientList)
    {
    if(pat.getPatientNumber()==patientNumb)
    {

    //pat.addProcedure(procedure);
    //procList.add(procedure);

    }
    }
    //here
    proceduresSelected = true;
    order += "\n"+ procedure[index].getLabel();
    }
    if (!proceduresSelected)
    order += "No procedure Selected.";
    order += ".";
    orderDetails.setText(order);
    }


Comments

  • Registered Users Posts: 772 ✭✭✭maki


    You're trying to add an array of JCheckBoxes to an ArrayList of type <Procedure>. Assuming you only want the current procedure being iterated on, you need to grab that only, and also change the ArrayList type.

    I can't see why you need the actual JCheckBox object though. I can't see your Patient class to verify, but wouldn't it be simpler to call procedure[index].getName() and just store the String of the procedure?


Advertisement