So I'm making a module that has three JTextField windows corresponding for 24 bit RGB color values "R", "G" and "B" with buttons for decrement/increment. The module is supposed to take these values and display the color. I did that and it works, but I need to ensure some details about the inputs and I don't know how to. These details are:
- if you enter a value outside of 0 and 255 it will be treated as 0
- if you click a decrement button when the value is 0 it won't drop it to -1
- if you click an increment button when the value is 255 it won't rise to 256. I have no idea how to do it. I tried to google it but I can't find what I need. I'd appreciate some guidance
EDIT: I tried to add some if statements to the ActionPerformed method but all it does is returns a whole bunch of errors when I run the module and try the value out of range
EDIT2: for example, I had this but it doesn't work :
@Override
public void actionPerformed(ActionEvent e) {
String r,g,b;
if (e.getSource() == tf1) {
r = tf1.getText();
this.r =Integer.parseInt(r);
if (this.r < 0 && this.r > 255)
this.r =0;
color(); }
I have nothing for my buttons because I have completely no idea how to