Trying to System.out.print() in a setOnMouseClicked event [Java app] [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm writing a Java application that calls a method letsPlay. I want to see if the code works, and sout'ed to test if it's running or not. When I run the app, nothing is printed. Is it because Java doesn't sout anything, or is it a problem with my code?
private void letsPlay(boolean player1turn) {
if(player1playing && player1turn)
System.out.println("It is " + nameField1.getText() + "'s turn.");
}

One of the two:
(probably) player1playing or/and player1turn are false, causing the expression to be evaluated to false, so the statement won't be executed
output stream is directed to somewhere else and not to the console, to solve this you'll need to do something like:
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
The easiest way to find what's your problem is to debug your code. Use the debugger, it'll save for you time, much of it.

Related

Is there an equivalent of Apex's 'system.debug' in Java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 10 months ago.
Improve this question
I recently started coding with Apex and have been utilizing the 'system.debug()' method. It helps me keep track of variables in my code by printing the variable in the 'debug log'. Now I am studying Java, and I was wondering if an equivalent method exists in Java. I would like to see what my variables are in certain parts of my code.
You can use a PrintStream, like System.out to call print or println in order to display your debug. You can also redirect System.out to file using setOut.
However, if you use an IDE and a debugger, you can create a breakpoint to the line that you wish to debug and let a debugger run until it reaches your line.

Java trying to change the JFrame title when method stops executing [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to change the title of my JFrame when something stops happening how could i achieve this?
I have tried the following:
if(camera.isItDone() == false){
setTitle("Sending...");
}else if(camera.hasFocus() == false){
setTitle("Communication");
}
the 'isItDone' method returns a boolean variable and when false this prints 'sending' on the button click on action listener, however after it being done how can i update this to say communication? because it gets stuck on 'Sending'?
EDIT:
I have also got a Swingworker and then i execute this to run a method in camera, and then check is it done which is a boolean.
Firstly; you don't compare a method that returns a boolean to a boolean. Like Ball.isRed() == false, Ball.isRed() already contains that value.
Secondly; check you if-cases in the debugger. If your are stuck on "Sending..." then:
Either camera.isItDone() is always false, or
camera.hasFocus() is never true.
Your if-else-case is built upon two different booleans that both have to match to fall in the right pigeon hole.

JAVA Swing - Update UI (breaks until I move it around) [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
Im pretty new to SWING and I tried my best but this is what is happening.
I have a interface that looks like this:
https://dl.dropboxusercontent.com/u/17524455/nodelete/1.jpg
From the main thread I call:
FrmMain.settextParticipants(5 + "");
FrmMain.setLaps(5 + "");
FrmMain.setRaceType("standard");
And that goes OK.
I Even manage to update the stoptime and time in the upper part of the GUI.
But as soon as I call (in the next line)
PnlRacers.PnlTransparents[0].setNameAndKartNr("01", "RACER");
My UI breaks like this:
https://dl.dropboxusercontent.com/u/17524455/nodelete/2.jpg
And the only thing that helps to fix the UI is, when I grab the window and move it around (to my second screen for example). That tells me that the "data" or "functions" are working well I guess... But the REDRAWING (or how to call it) is somehow ok for the first arguments and broken for the last class. After moving around it looks like this: https://dl.dropboxusercontent.com/u/17524455/nodelete/3.jpg
I read something about redraw() and validate() and I tried all on all places and on any element I was working with :(.
Maybe someone knows what the problem could be and if the source should be any help, here it is: https://dl.dropboxusercontent.com/u/17524455/nodelete/TEST.rar
Please help :) Im so lost ...
Have you tried calling repaint() to the content pane after the change you implemented?

Printing statements using a method [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Basically I've been set some work where I have to have 4 methods but I don't really understand how methods work. One of these methods basically has to print out two set statements that's it and I have no idea how to do it as most examples across the web deal with methods being used for maths and nothing as simple as printing out two lines for a title. Can anyone please help?
Method is just a way of extracting a piece of code and making it callable on demand. So if you print out two lines...
System.out.println("This is line 1");
System.out.println("This is line 2");
And you want to call it more than once, then you would extract it into a method.
private void myNewMethod()
{
System.out.println("This is line 1");
System.out.println("This is line 2");
}
Then call that method from anywhere in your program like so
myNewMethod();
These types of questions are off topic however as you need to demonstrate an understanding of your problem before we can help fix it.

How can I find a mysterious message being printed? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Okay, so I have a very large project in Java that I have been working on for years (a game, if you must know).
Unfortunately, a mysterious message has started being printed. No matter the lengths of my searching, I cannot pinpoint the location of the message.
I know that you can override the println method, and I was curious if it was possible to have some sort of debugging info attached to the message being printed? Like the line or file it was printed from perhaps? I tried searching Google for this, but it is simply too detailed of a problem that I cannot find an answer.
Even worse, the message is very ambiguous. It is simply "-1".
Atleast I know now to use a proper logger instead of simply println().
In such a case you can use a conditional breakpoint in your ide. This is a really useful feature of ide that's not always well known.
You set a breakpoint and you want it to suspend the application only under some condition, in this case the parameter of the println method being your 'mysterious ufindable string'
In the case of Intelllij IDEA this would look like this:
You can do
new Exception().printStackTrace()
or similar without throwing the created exception to get a full stack trace for a current execution point. And there is no need to throw it. You may event save them into list for later processing.
This looks like a message from ArrayIndexOutOfBoundsException. Add breakpoint on this type of exceptions. Try this:
String[] arr = new String[0];
try{
System.out.println(arr[-1]);
}catch (Exception e){
System.out.println(e.getMessage());
}

Categories

Resources