that might be some kind of a silly question for you guys, but anyways: Is it possible to start the Java-console (as it is shown in Eclipse) parallel to the actual SWT-GUI?
The console contains an awful lot of debugging-information and I want my testers to be able to see what's currently going on. Obviously, they're not gonna use Eclipse...
Start your program using java instead of javaw.
Another way is that you abstract your logging mechanism so that it uses console if one is attached to the process (when started with java or within Eclipse) or puts the messages in a separate window the user can open if they want.
Run the application with the parameters:
-console -consoleLog
Related
I am creating a complex game, because of this I use System.out.println(); a lot to test to see if something works or to see if something went wrong. To see these messages I have been going to the CMD or terminal and running it from there but I was wondering if there was an easier way. I thought of a couple ways and came up with running with a batch, but I have no idea how to make one, and another way was to put a button in game that opens the console that the game is running in. I don't even know if the second one is possible but I was wondering if there was a way! Thanks in advanced!
This is what logging frameworks are for.
Use sfl4j - http://www.slf4j.org/ - in your code to generate the log events, and choose a suitable backend for your purpose. I would suggest using slf4j-simple which is easy to get started with and which easily can be sent to a file you can view in your favorite file viewer.
http://www.slf4j.org/api/org/slf4j/impl/SimpleLogger.html
I'm currently writing a pretty large program that calls the same methods from different places.
Now I would really like to see how the program goes from one method to another as it is running. Like a live view that shows when what method is opened (and why?). Call Hierarchy doesn't suit my needs at this point. Is there a way?
One way to follow the logic of your application is by placing breakpoints at the line of code you want your application to stop at but, to do this you'll have to setup it up in debug mode.
Every major IDE will let you do this, including Eclipse.
Have a look at this tutorial:
Java Debugging with Eclipse
Once you setup your program in debug mode you can add a breakpoint in the gutter next to the line numbers.
I want to clear the console output of the NetBeans console. We can clear it manually by using Ctrl+L.
Is it possible to do this programmatically, in Java?
Thank you very much
I think that it's not so simple.
The Netbeans console is not really a full system console.
I'd see a proper option - like getting the console reference using the Netbeans RPC binding, but your application would need to run as a Netbeans plugin or bundle. (so - don't do that, keep it simple)
For a shortcut (workaround) - you may try to use java.awt.Robot class to send a keyRelease event (Ctrl+L) while being focused in the console (effectively sending the Ctrl+L event to the focused component)
This is a poor solution because it doesn't actually clear anything, but it does push it out of the way to hopefully make it more readable.
System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
add or subtract "\n" to lengthen or shorten it depending on the size of the console window.
I am creating a program using Java Sockets in which I capture the client desktop and send messaging to client. Its working properly but now I want to block Client applications like Notepad, MS-Word, etc.
How can I do this?
Thanks.
It is hard to do using pure java API.
I do not know what do you mean when you say "block". The easiest way is to check from time to time running processes and kill one named "notepad" by executing taskkill from java.
If you wish to achieve effect of inactivity of application, i.e. user sees the notepad but cannot type you can do the following.
You have to check which application is on front. There is no clean pure java solution for this but you can probably write VBScript or JScript that does this task and run it from java. Once you detected that notepad is on top create transparent window (or even probably half-transparent window) that occupies full screen. Bring it on top. User will not be able to type into notepad because your window is on top but will see it.
Here is reference how to create transparent windows: http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/
Good luck.
When running a JNLP application (for example), "Java console" is opened, containing the output of the program and a bunch of debug functionality.
Whether the console is opened or not, is determined in the settings in Java Control Panel.
Is there a way to enable & show this Java console programmatically during the program execution?
Or alternatively, is there any way to to enable this Java console during the program execution if it wasn't enabled at the program startup?
(I'm thinking that probably not but if there's a way that could be nice to know)
br, Touko
Andrew Thompson's answer is the right way to do this. My answer is the fast way, if you don't have time to implement a logging framework now:
If you have written your program without logging and you just want to see all those System.out.println messages, you can redirect them all to a text file.
Inside your main method, try this:
System.setOut(new PrintStream(new File("C:/logs/log.txt"));
You might want to include a complete path instead of a local file reference.