#BOOLEAN HELP
285 messages · Page 1 of 1 (latest)
what is e.getSource()?
the button
it gets the source of the button
qnd yes/no are?
the buttons
you also forgot to add punctuation to your question.
SORRY IM NOT AN DICTONARY
should i use || instead
just remove the if statement and only have
this.dispose();
option = !option;
and just do System.out.println(option);
It is not "an" it is "a"
That would work if i wanted to print out the value but i want it to do something when its true and something else when false it should print out something
Then don't include the colorMover.option = true since it is asigning and it will never execute
Come on, we aint gotta be that picky 
./run ```java
boolean option = true;
if(option = false == true){System.out.println("True");
@restive adder I only received java(15.0.2) error output
file0.code.java:5: error: reached end of file while parsing
}}
^
1 error
error: compilation failed
./run ```java
boolean option = true;
if(option = false == true){System.out.println("True");}
Your java(15.0.2) code ran without output @restive adder
hmm okay that sounds right i think
I'm just being a smart ass
./run ```java
boolean option = true;
if(option == true){System.out.println("True");}
Here is your java(15.0.2) output @restive adder
True
Just to give you an idea
thanks ill try
@restive adder HI sorry but the way to set the variables true or false is in a different class
when button "yes" gets pressed i expected it to change the option variables to true and vice versa when false
and thats why i did that there
Check if it false and then do what you need to be done, but at the end of the if statements, do option = !option;
so like !option option = false; ?
nah if its false i just want the window to dispose
If true I want to change something in a different class.
No. Check if it is true/false and act accordinly, but after the if and else, switch it by reversing the option
I think I understand
= is asigning a value. == is comparing
if (option == true){
//act accordingly
} else {
//act accordingly
}
option = !option;
It just removes the code dupes
so i replace that with an if statement basically?
BUT
if it is true u basically making the same thing
i want it to change the value
when the button gets pressed
What does dispose do?
This is for the bottom pic
ohh
but how do i change the boolean value
thats my issue
when the button gets pressed
of option right?
how do i change it
yeahhhh
like when it gets pressed on yes
it changes to true
and on no
the value changes to false
Wait, so you trying to change the option value from another class?
nonoon
its the same class
the button is in the same class
in the second class im getting the vlaue
that was entered
Replace the code in the bottom pic with this
Replace the top code pic with this
this code?
but it doesnt change the value bro ðŸ˜
no
It compares it
then what changes it
replace all this code with
this.dispose();
option = !option;```
replace with
if (option == true){
//act accordingly
} else {
//act accordingly
}
option = !option;```
and for the no button?
not the while loop
OH
you talking about this code?
bro i dont think u understand what im saying
i want this to change the value
if its true or false
like if option button yes is clicked
Replace the if statements and all
it will change the value to true
That whole code block
if (e.getSource() == yes) {
this.dispose();
option = true;
}
if (e.getSource() == no) {
this.dispose();
option = false;
like this?
all
No, just this
Replace everything in the while loop with the code provided
oop
the while loop won't even loop since it is setting option to true and then since option isn't false, it won't even loop
Yes, but do you want the while loop to loop only if it is false?
interesting way of writing an endless loop
It shouldn't loop right?
no
Since it is not even false
Right dan?
option=true==false
i learnt that somewhere idk
oh right
i just saw it work
it doesn't enter
./run
boolean option = false;
System.out.println(option = true == false);
Here is your java(15.0.2) output @restive adder
false
yea
./run
System.out.println(option = true == false);```
@surreal sparrow
Unsupported language: None
Request a new language
wtf
it always is false
boolean option = false;
System.out.println(option = true == false);```
./run
boolean option = true;
System.out.println(option = true == false);```
Here is your java(15.0.2) output @surreal sparrow
false
option=true sets option to true
It is changing option to true, and since option doesn't equal false it the == is false
and returns true
This is the most struggle helping someone I have had in a while lmao (no offense)
./run
while(option == true == false)
if (option == true){
} else {
}
option = !option;
}```
@surreal sparrow I only received java(15.0.2) error output
file0.code.java:10: error: class, interface, or enum expected
}}
^
1 error
error: compilation failed
ðŸ˜
im so sory
you forgot the { in the while
./run
boolean option =
while(option == true == false)
if (option == true){
} else {
}
option = !option;
}
}
@restive adder I only received java(15.0.2) error output
file0.code.java:3: error: illegal start of expression
while(option == true == false)
^
file0.code.java:13: error: class, interface, or enum expected
}}
^
2 errors
error: compilation failed
Its no worries
./run
boolean option = false;
while(option == true == false)
if (option == true){
} else {
}
option = !option;
}
}```
boolean option = false;
System.out.println(option = true == false);``` how do i make this change when true
@restive adder I only received java(15.0.2) error output
file0.code.java:12: error: class, interface, or enum expected
}}
^
1 error
error: compilation failed
option == true
Why do you even have teh while loop?
only use while loops when you need to repeat until an undecided length of time
boolean = true
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}
```
./run
boolean = true
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}
```
@surreal sparrow I only received java(15.0.2) error output
file0.code.java:2: error: not a statement
boolean = true
^
file0.code.java:2: error: ';' expected
boolean = true
^
file0.code.java:10: error: class, interface, or enum expected
}}
^
3 errors
error: compilation failed
boolean = true;
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}
```
oop
./run
boolean = true;
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}
```
boolean option = true;
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}
@surreal sparrow I only received java(15.0.2) error output
file0.code.java:2: error: not a statement
boolean = true;
^
file0.code.java:2: error: ';' expected
boolean = true;
^
file0.code.java:10: error: class, interface, or enum expected
}}
^
3 errors
error: compilation failed
./run
boolean option = true;
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}```
@restive adder I only received java(15.0.2) error output
file0.code.java:9: error: class, interface, or enum expected
}}
^
1 error
error: compilation failed
bro

./run
boolean option = true;
if(option = true) {
System.out.println("true");
}
else {
System.out.println("false");
}```
Here is your java(15.0.2) output @restive adder
true
uh i think i understnad
./run
boolean option = true;
if(option) {
System.out.println("true");
}
else {
System.out.println("false");
}```
Here is your java(15.0.2) output @surreal sparrow
true
./run
boolean option = false;
if(option) {
System.out.println("true");
}
else {
System.out.println("false");
}```
Here is your java(15.0.2) output @surreal sparrow
false
ezzz
Remember, to compare 2 things such as if an integer equals an integer of a boolean equals a boolean use == and not =
if (1 == 1)
wil execute since 1 equals 1
Just as a reminder
And in an if statement, you don't need to check if a boolean equals true since the if statement already takes a boolean, which is why this works
Show me all of your code
Code
this is MainCmd.java
colorhover.java
package cmd.java.utils;
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class colorHover extends JFrame implements ActionListener {
JRadioButton yes;
JRadioButton no;
public static boolean option;
public colorHover() {
yes = new JRadioButton("Yes");
yes.addActionListener(this);
no = new JRadioButton("No");
no.addActionListener(this);
ButtonGroup grp = new ButtonGroup();
grp.add(yes);
grp.add(no);
JLabel text = new JLabel();
text.setText("Change border-color on hover: ");
this.add(text);
this.add(yes);
this.add(no);
this.setSize(30, 30);
this.setLayout(new FlowLayout());
this.setVisible(true);
this.pack();
this.setTitle("Options");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == yes) {
this.dispose();
option = true;
}
if (e.getSource() == no) {
this.dispose();
option = false;
}
}
}
replace this with
package cmd.java.utils;
import javax.swing.;
import java.awt.;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class colorHover extends JFrame implements ActionListener {
JRadioButton yes;
JRadioButton no;
public static boolean option;
public colorHover() {
yes = new JRadioButton("Yes");
yes.addActionListener(this);
no = new JRadioButton("No");
no.addActionListener(this);
ButtonGroup grp = new ButtonGroup();
grp.add(yes);
grp.add(no);
JLabel text = new JLabel();
text.setText("Change border-color on hover: ");
this.add(text);
this.add(yes);
this.add(no);
this.setSize(30, 30);
this.setLayout(new FlowLayout());
this.setVisible(true);
this.pack();
this.setTitle("Options");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
this.dispose();
option = !option;
}
}
hmm
it still just displays false
when ran
the buttons do nothing
this is what happens
show the dispose method
its extened by a jframe
What does dispose do?
Ahh ok
i dont think its that tho
What happened to this code? Is that the overriden method?
wait
This ^
.
send htere
there
i made no changes
l
Imma be honest, I never used swing, but I am trying to figure it out
Show the colorhover class
nvm
ye
wtf
then what do u do
What I do?
like with java
Lmao
is there a way to make a if statement only work if a button has been pressed or smth
Not sure, wrong person to ask
in colorHover class, put a print statement in the constructor and the actionPerformed method printing option's value
you also do hoverCol.addActionListener(this); twice
yeah i was testing smth
you add 3 action listeners
uh bro
I GOT 1 QUESTION PLZ
i asked this
i just wanna know
how do i change a boolean value
when a button is clicked
What method is the listener that is called hwen a button is cliecked?
i used lambda
no
colorhover
i used javas actionListener
since it can take more than 1 line
of code
even though i could make a public void and add that method in there
i find javas easier
idk
MY BRAIN
@restive adder
I DID IT
ðŸ§
tysm
i just created a button that gets the value
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == yes) {
if(!option){
option = true;
}
}
else{
option = false;
}
if(e.getSource()==button){
System.out.println(option);
}
}
and this is how u get the value
i had to add !option and then set it
im so dumb
ðŸ˜
but aitleast ill remember in the future
the only flaw is that it for somereason when pressed sets the value to true on default
but in the box they forced to chose anyways
