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
Hi all! We have been experiencing an issue on site where threads have been missing the latest postings. The platform host Vanilla are working on this issue. A workaround that has been used by some is to navigate back from 1 to 10+ pages to re-sync the thread and this will then show the latest posts. Thanks, Mike.
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

How to add selected check boxs to arraylist

  • 25-04-2015 6:41pm
    #1
    Registered Users 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: 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