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..?
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("");
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.