#BOOLEAN HELP

285 messages · Page 1 of 1 (latest)

neon zinc
#

firstly, always compare using ==.

inland spruce
#

what is e.getSource()?

surreal sparrow
surreal sparrow
inland spruce
#

qnd yes/no are?

surreal sparrow
#

the buttons

quasi robin
#

you also forgot to add punctuation to your question.

surreal sparrow
surreal sparrow
restive adder
#

and just do System.out.println(option);

restive adder
surreal sparrow
restive adder
#

Then don't include the colorMover.option = true since it is asigning and it will never execute

neon zinc
restive adder
#

./run ```java
boolean option = true;
if(option = false == true){System.out.println("True");

spiral bridgeBOT
#

@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
restive adder
#

./run ```java
boolean option = true;
if(option = false == true){System.out.println("True");}

spiral bridgeBOT
#

Your java(15.0.2) code ran without output @restive adder

surreal sparrow
restive adder
#

./run ```java
boolean option = true;
if(option == true){System.out.println("True");}

spiral bridgeBOT
#

Here is your java(15.0.2) output @restive adder

True
restive adder
#

Just to give you an idea

surreal sparrow
#

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

surreal sparrow
restive adder
#

Check if it false and then do what you need to be done, but at the end of the if statements, do option = !option;

surreal sparrow
#

nah if its false i just want the window to dispose

#

If true I want to change something in a different class.

restive adder
#

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

surreal sparrow
#

hmm

#

how do i check if it is true 😭

#

if(option = true?){
do stuff}

#

i hope

restive adder
#

= is asigning a value. == is comparing

surreal sparrow
#

what

#

how do i change the value when clicked

restive adder
#
if (option == true){
//act accordingly
} else {
//act accordingly
}
option = !option;
#

It just removes the code dupes

surreal sparrow
#

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

restive adder
#

What does dispose do?

surreal sparrow
#

not if it is true arleady

#

it closes the window

surreal sparrow
#

ohh

#

but how do i change the boolean value

#

thats my issue

#

when the button gets pressed

restive adder
#

of option right?

surreal sparrow
#

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

restive adder
#

Wait, so you trying to change the option value from another class?

surreal sparrow
#

nonoon

#

its the same class

#

the button is in the same class

#

in the second class im getting the vlaue

#

that was entered

restive adder
restive adder
surreal sparrow
#

this code?

restive adder
#

yes

#

Or the whole thing is what I meant

surreal sparrow
#

but it doesnt change the value bro 😭

restive adder
#

?

#

It should

surreal sparrow
#

does if(option == true) change the value to true?

#

😱

restive adder
#

no

surreal sparrow
#

nbtuhu

restive adder
#

It compares it

surreal sparrow
#

then what changes it

restive adder
surreal sparrow
#

aint no wya

#

leme try

restive adder
#

replace with

if (option == true){
//act accordingly
} else {
//act accordingly
}
option = !option;```
surreal sparrow
#

and for the no button?

restive adder
#

not the while loop

surreal sparrow
#

OH

restive adder
surreal sparrow
#

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

restive adder
#

Replace the if statements and all

surreal sparrow
#

it will change the value to true

restive adder
#

That whole code block

surreal sparrow
#

if (e.getSource() == yes) {
this.dispose();
option = true;
}
if (e.getSource() == no) {
this.dispose();
option = false;

#

like this?

#

all

surreal sparrow
#

ok this is in the maun

#

main

restive adder
surreal sparrow
#

oop

restive adder
#

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

surreal sparrow
#

theis?

restive adder
#

Yes, but do you want the while loop to loop only if it is false?

surreal sparrow
#

no i want it to do nothing when false

#

and do smth when true

inland spruce
restive adder
#

It shouldn't loop right?

surreal sparrow
#

no

restive adder
#

Since it is not even false

surreal sparrow
#

i dont want it to loop

#

its a once of thing

restive adder
#

Right dan?

inland spruce
#

option=true==false

surreal sparrow
#

i learnt that somewhere idk

inland spruce
#

oh right

surreal sparrow
#

i just saw it work

inland spruce
#

it doesn't enter

restive adder
#

./run

boolean option = false;
System.out.println(option = true == false);
spiral bridgeBOT
#

Here is your java(15.0.2) output @restive adder

false
restive adder
#

yea

surreal sparrow
#

./run

System.out.println(option = true == false);```
spiral bridgeBOT
surreal sparrow
#

wtf

inland spruce
#

it always is false

surreal sparrow
#
boolean option = false;
System.out.println(option = true == false);```
surreal sparrow
#

./run

boolean option = true;
System.out.println(option = true == false);```
spiral bridgeBOT
#

Here is your java(15.0.2) output @surreal sparrow

false
surreal sparrow
#

my briann

inland spruce
#

option=true sets option to true

restive adder
#

It is changing option to true, and since option doesn't equal false it the == is false

inland spruce
#

and returns true

restive adder
#

This is the most struggle helping someone I have had in a while lmao (no offense)

surreal sparrow
#

./run

   while(option == true == false)
        if (option == true){

        } else {
        }
        option = !option;

        }```
spiral bridgeBOT
#

@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
inland spruce
#

you forgot the { in the while

restive adder
#

./run

boolean option = 
   while(option == true == false)
        if (option == true){

        } else {
        }
        option = !option;

        }
}
spiral bridgeBOT
#

@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
restive adder
#

Its no worries

#

./run

boolean option = false;
   while(option == true == false)
        if (option == true){

        } else {
        }
        option = !option;

        }
}```
surreal sparrow
#
boolean option = false;
System.out.println(option = true == false);``` how do i make this change when true
spiral bridgeBOT
#

@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
restive adder
#

option == true

surreal sparrow
#

but it wont change when false then>

#

leme try smth

restive adder
#

Why do you even have teh while loop?

#

only use while loops when you need to repeat until an undecided length of time

surreal sparrow
#
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");
        }
    ```
spiral bridgeBOT
#

@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
surreal sparrow
#
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");
        }
    ```
restive adder
#

boolean option = true;
if(option = true) {
System.out.println("true");
}
else
System.out.println("false");
}

spiral bridgeBOT
#

@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
restive adder
#

./run

boolean option = true;
  if(option = true) {
        System.out.println("true");
    }
    else
            System.out.println("false");
        }```
spiral bridgeBOT
#

@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
restive adder
#

bro

surreal sparrow
restive adder
#

./run

boolean option = true;
  if(option = true) {
        System.out.println("true");
    }
    else {
            System.out.println("false");
        }```
spiral bridgeBOT
#

Here is your java(15.0.2) output @restive adder

true
restive adder
#

wait

#

Just do if (option)

#

It is 1 am lmao

#

Sorry if I am a little confusing

surreal sparrow
#

uh i think i understnad

#

./run

boolean option = true;
  if(option) {
        System.out.println("true");
    }
    else {
            System.out.println("false");
        }```
spiral bridgeBOT
#

Here is your java(15.0.2) output @surreal sparrow

true
surreal sparrow
#

./run

boolean option = false;
  if(option) {
        System.out.println("true");
    }
    else {
            System.out.println("false");
        }```
spiral bridgeBOT
#

Here is your java(15.0.2) output @surreal sparrow

false
surreal sparrow
#

ezzz

restive adder
#

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

surreal sparrow
#

leme try this

#

NOO

#

:Sob

#

my brain

#

it just outputs false

#

when ran

restive adder
#

Show me all of your code

surreal sparrow
#

okz

restive adder
#

Code

surreal sparrow
#

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;
    }
}

}

restive adder
# surreal sparrow ```colorhover.java``` package cmd.java.utils; import javax.swing.*; import java...

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;
    }
}
surreal sparrow
#

hmm

#

it still just displays false

#

when ran

#

the buttons do nothing

#

this is what happens

restive adder
#

show the dispose method

surreal sparrow
restive adder
#

the actual method

#

Where you declare it

surreal sparrow
#

its extened by a jframe

restive adder
#

What does dispose do?

surreal sparrow
#

it makes life easier

#

closes the window

#

basically like clicing the "x"

restive adder
#

Ahh ok

surreal sparrow
#

i dont think its that tho

restive adder
#

wait

#

This ^

surreal sparrow
#

its now this

restive adder
#

Do you want to send me your whole entire class file?

#

in a pastebin link

surreal sparrow
#

send htere

#

there

#

i made no changes

#

l

restive adder
#

Imma be honest, I never used swing, but I am trying to figure it out

#

Show the colorhover class

#

nvm

surreal sparrow
#

ye

surreal sparrow
#

then what do u do

restive adder
#

What I do?

surreal sparrow
#

like with java

restive adder
#

Minecraft plugins, creating an api, etc

#

just projects

surreal sparrow
#

noice

#

the only thing i did with mc is create a hacked client

restive adder
#

Lmao

surreal sparrow
#

is there a way to make a if statement only work if a button has been pressed or smth

restive adder
#

Not sure, wrong person to ask

surreal sparrow
#

i think i can fix it

#

even though the code may look cringe

restive adder
#

you also do hoverCol.addActionListener(this); twice

surreal sparrow
#

yeah i was testing smth

restive adder
#

you add 3 action listeners

surreal sparrow
#

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

restive adder
#

What method is the listener that is called hwen a button is cliecked?

surreal sparrow
#

i used lambda

restive adder
#

which one though

#

is it the hover class?

surreal sparrow
#

no

restive adder
#

colorhover

surreal sparrow
#

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

#

I DID IT

#

🧠

#

tysm

restive adder
#

What was it lmao.

#

no problem

surreal sparrow
#

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