What exactly are your plans with this local variable from another method?

|
brjavaman 2022-07-22 05:59:44
Have you registered yet?

Let’s celebrate the developer career with Java Champions and JUG Leaders!

https://hopin.com/events/dev-career-day-2022/

International Developer Career Day 2022Hopin
Have direct access to top developers from many areas, and learn their best tips to get YOUR career growing!
phfbonini 2022-07-22 14:14:07
hey guys, going to update on the position corrector, I set up a spreadsheet in excel based on a math spreadsheet, it involves cosine, arc of tangent and other mathematical things. Finally I got the result and converted the excel calculations into code
Viniciusdesousamoraes 2022-07-22 21:40:46
Guys, help please
Viniciusdesousamoraes 2022-07-22 21:42:34
How can i access a variable from a method inside another method?
Viniciusdesousamoraes 2022-07-22 21:43:01
Im working with Jpanels
R_r_F_BR 2022-07-22 21:43:46
A variable declared inside a method is knowing to be a local one. If your code needs its value, call that method and return the variables value.
Viniciusdesousamoraes 2022-07-22 21:43:50
And i want to refresh a label of onde panel by the button on another paner that comes before in script
Viniciusdesousamoraes 2022-07-22 21:44:13
Of one panel*
martin_angelo 2022-07-23 01:50:55
that seems to be something specific regarding JPanels. What exactly are your plans with this local variable from another method?
Can you fill us in about the exact situation you are facing and ideally also a copy of the relevant part of your code?
radenRanggaPratama 2022-07-26 05:23:48
#Ask

I try to learn build the project from tutorial: https://itsourcecode.com/free-projects/java-projects/vehicle-management-system-project-in-java-with-source-code/

When I run, get error: import com.sun.glass.events.KeyEvent;

Try to solve with this solution (import java.awt.event.KeyEvent;) form:
https://stackoverflow.com/questions/43218019/com-sun-glass-does-not-exist

code: https://itsourcecode.com/wp-content/uploads/2021/07/Vehicle-Management-System-Project-In-Java-Source-Code.zip

Try to run: working. This is the best solution?

Vehicle Management System Project In Java With Source CodeItsourcecode.com
This 2022 Vehicle Management System Project In Java was developed in JAVA Programming using NetBeans IDE, It also includes a free source code.
Jaschar 2022-07-26 16:09:36
radenRanggaPratama 2022-07-26 05:23:48
#Ask

I try to learn build the project from tutorial: https://itsourcecode.com/free-projects/java-projects/vehicle-management-system-project-in-java-with-source-code/

When I run, get error: import com.sun.glass.events.KeyEvent;

Try to solve with this solution (import java.awt.event.KeyEvent;) form:
https://stackoverflow.com/questions/43218019/com-sun-glass-does-not-exist

code: https://itsourcecode.com/wp-content/uploads/2021/07/Vehicle-Management-System-Project-In-Java-Source-Code.zip

Try to run: working. This is the best solution?

I hardly recommend to use

import java.awt.event.KeyEvent;

Exactly like it is recommended on stackoverflow: https://stackoverflow.com/a/43218233

If it not work. Then the code needs professional refactoring.

Who ever implemented it by using com.sun.glass.event.KeyEvent did a unprofessional mistake.

com.sun.glass does not existStack Overflow
I have a project that is on github. I have two different computers that use the project. The reason I mention github is because the two computers have the exact same project. But on one of the comp…
Victor_VBA 2022-07-26 19:16:20
Hi, everyone.
I wonder if somebody could enlighten me on how can I prevent a parameter of a Class to accept negative values.

The idea I came up with was as follows in 2nd and 3rd attributes:

public Estoque(String nome, int qtdAtual, int qtdMinima) { //constructor
this.nome = nome;
this.qtdAtual = qtdAtual < 0 ? 0 : qtdAtual;
this.qtdMinima = qtdMinima < 0 ? 0 : qtdMinima;
}

I wonder if that’s the most efficient solution. In case not, I’d be really appreciated to know.

martin_angelo 2022-07-26 19:21:35
Hi Victor,
in this case it is better, to throw an exception. The user of the class will have no feedback, that his value was set to 0 and might assume, that it still is his negative value.
Therefore, you could use the guava library (https://guava.dev/releases/19.0/api/docs/com/google/common/base/Preconditions.html), which already has many cases covered, like Preconditions.checkNotNull(…)
JFCostta 2022-07-26 19:22:52
martin_angelo 2022-07-26 19:21:35
Hi Victor,
in this case it is better, to throw an exception. The user of the class will have no feedback, that his value was set to 0 and might assume, that it still is his negative value.
Therefore, you could use the guava library (https://guava.dev/releases/19.0/api/docs/com/google/common/base/Preconditions.html), which already has many cases covered, like Preconditions.checkNotNull(…)

I’d suggest the same thing, throwing an exception gives you more feedback and you can act directly on the undesired condition.

Jaschar 2022-07-26 19:24:06
martin_angelo 2022-07-26 19:21:35
Hi Victor,
in this case it is better, to throw an exception. The user of the class will have no feedback, that his value was set to 0 and might assume, that it still is his negative value.
Therefore, you could use the guava library (https://guava.dev/releases/19.0/api/docs/com/google/common/base/Preconditions.html), which already has many cases covered, like Preconditions.checkNotNull(…)

Here the most recent api doc of Preconditions: https://guava.dev/releases/31.1-jre/api/docs/com/google/common/base/Preconditions.html

martin_angelo 2022-07-26 19:25:22
in Jaschars link there is a good example code:

public static double sqrt(double value) {
checkArgument(value >= 0, “input is negative: %s”, value);
// calculate square root
}

Victor_VBA 2022-07-26 19:27:15
I appreciate all the help and will work on it
martin_angelo 2022-07-26 19:41:06
radenRanggaPratama 2022-07-26 05:23:48
#Ask

I try to learn build the project from tutorial: https://itsourcecode.com/free-projects/java-projects/vehicle-management-system-project-in-java-with-source-code/

When I run, get error: import com.sun.glass.events.KeyEvent;

Try to solve with this solution (import java.awt.event.KeyEvent;) form:
https://stackoverflow.com/questions/43218019/com-sun-glass-does-not-exist

code: https://itsourcecode.com/wp-content/uploads/2021/07/Vehicle-Management-System-Project-In-Java-Source-Code.zip

Try to run: working. This is the best solution?

‼️
I just downloaded the source code because I was suspicious about the quality after having a glance over the article. I am shocked how unprofessional the source code is…. Please don’t take it as an example of what good quality source code looks like.

There are multiple aspects which are designed badly. I would rather consider this source code as a good starting point, for practicing refactoring.

link to source code: https://itsourcecode.com/wp-content/uploads/2021/07/Vehicle-Management-System-Project-In-Java-Source-Code.zip

Jaschar 2022-07-26 19:45:16
martin_angelo 2022-07-26 19:41:06
‼️
I just downloaded the source code because I was suspicious about the quality after having a glance over the article. I am shocked how unprofessional the source code is…. Please don’t take it as an example of what good quality source code looks like.

There are multiple aspects which are designed badly. I would rather consider this source code as a good starting point, for practicing refactoring.

link to source code: https://itsourcecode.com/wp-content/uploads/2021/07/Vehicle-Management-System-Project-In-Java-Source-Code.zip

I’d rather not look at it.

radenRanggaPratama 2022-07-27 08:09:13
martin_angelo 2022-07-26 19:41:06
‼️
I just downloaded the source code because I was suspicious about the quality after having a glance over the article. I am shocked how unprofessional the source code is…. Please don’t take it as an example of what good quality source code looks like.

There are multiple aspects which are designed badly. I would rather consider this source code as a good starting point, for practicing refactoring.

link to source code: https://itsourcecode.com/wp-content/uploads/2021/07/Vehicle-Management-System-Project-In-Java-Source-Code.zip

thanks for your recommendation 👍

|