Jump to content

Hey guys I'm a freshman IT student and our professor tasked us to make a POS System

 

I want to make a temporary name for my JLabel so that I can just change the value when I call the method of the formula but its not working because it treats the name of the temporary variable as a String (I declared it as a String cus idk what else to declare it xd)

 

Main method code:

 

image.png.8075388acbd266983cdaa5c636fc4c72.png

 

Method code with the formula that I want to call:

 

method.png.e14ae8686145cb83918517f2cd421657.png

 

What I'm trying to achieve: I placed a JLabel with the square thingy as the text ("⬛") and I want to change its color depending on the value of the stock...

It would basically act as a status indicator for the stock

 

window.thumb.png.e434ea52b72323a3e57a6d8c7b075f1e.png

Link to post
Share on other sites

20 hours ago, Loli Pits said:

when I call the method of the formula but its not working because it treats the name of the temporary variable as a String (I declared it as a String cus idk what else to declare it xd)

In java, variables cannot change types, declare it as a JLabel.

 

Can you show us the rest of the code? It's not obvious what's happening here. Are those variables object properties?

ಠ_ಠ

Link to post
Share on other sites

Please post your code. And please, don't post screenshots of code, post the actual code (i.e. text) using code tags.

// like this
JLabel temp = null;

This way people can copy it and play around with it to try things out before posting an answer, instead of having to rewrite your code by looking at a jpeg.

 

If you want to define a variable, you need to use the type of value you want to assign to it. If you don't have a value yet, you can assign null to it.

Remember to either quote or @mention others, so they are notified of your reply

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×