Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

How to add selected check boxs to arraylist

  • 25-04-2015 05:41PM
    #1
    Registered Users, Registered Users 2 Posts: 6


    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, Registered Users 2 Posts: 774 ✭✭✭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