Click here to Skip to main content
15,886,773 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here, what i am trying to do is if user marks the checkbox then its entry should be appended to the text area(working) and if uncheck then it should be removed from the text area(not working)...

--> i just want to know how do i remove the entry if user uncheck the entry..?

Java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
import java.awt.geom.Arc2D;
import java.io.*;
public class Hell    {
    static JTextArea a;
    public static void main(String[] args) {
        JFrame frame = new JFrame("WELCOME TO F***LAND");
        frame.setBounds(50, 100, 500, 500);
        frame.setVisible(true);
        Container c = frame.getContentPane();
        c.setLayout(null);
        JCheckBox[] arr = new JCheckBox[5];
        for(int i=0 ; i<5 ; i++)
        {
            arr[i] = new JCheckBox("checkbox "+Integer.toString(i+1));
            arr[i].setBounds(50,50+(i*50),100,30);
            c.add(arr[i]);
        }
        a = new JTextArea();
        c.add(a);
        a.setBounds(200,20,100,200);
        a.setText("");//where do i write this .it is to remove the entry from //the textarea if user uncheck the entry
        for(int i=0 ; i<arr.length ; i++)
        {
            funk_you(i,arr);
        }
    }
    public static void funk_you(int i,JCheckBox[] arr)
    {
        arr[i].addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if(arr[i].isSelected())
                {
                    a.append(arr[i].getText() + "\n");
                }
                
            }
        });
    }
}



--> this is from the video


--> COMPULSORY MAKE USE OF ANONYMOUS CLASS

What I have tried:

--> i have tried viewing the video...

please do see the video for better understanding....
thanks for sparing your immortal time for this question.
Posted
Updated 3-Oct-16 13:04pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900