So I have a few basic questions that are probably going to be very simple for you guys. Keep in mind, I am not a programmer. I'm just a low-level IT support person who took a few programming courses in high school.
I've got an Announcements program I'm trying to build in Java. The program will launch in a Java applet, and I want it to accept input from an "announcements.txt" file (which will be what we edit with new announcements) and then display it in the applet. I am using the latest version of NetBeans to stumble my way through this.
The program will be added to a group policy in Active Directory to launch at login for all employees.
My questions are:
Can I just use FileOutputStream to write the "announcements.txt" to a TextArea? I've only ever dealt with console applications.
I added a ScrollPane to the applet design, and just placed a TextArea over top of it. Is this how it is meant to be done? Will it automatically insert scroll bars when it goes outside the window or am I supposed to output the text directly to the ScrollPane?
Sorry if this all seems kind of basic. I'm an aspiring programmer, but I've got a LOT of work ahead of me before I become even semi-proficient. ANY INPUT IS APPRECIATED!!!
No.
A JTextArea can accept an input stream to read from.
An applet must access 'application' resources by URL.
With the Swing equivalents, yes. With the AWT equivalents, the ScrollPane is not needed, since a TextArea has inbuilt scrollable ability.
Related
I've created a website portfolio and I want to show some of the projects I've done. But so far the many of the projects I've done have been in java, or C/C++ and the interactive/fun programs take input from the console.
I was wondering if there was a way to simulate those program using JavaServer Faces and taking input from a textbox (possibly) to be used in the java program I've created and posted back to the website.
Just to give you an idea of the kinds of programs I'd like to show. They range from simple things like determining if the entered data from the user is a leap year to a text I/O credit card validation program I've made up.
If my question is clear enough, does anyone have any ideas about how I can show the programs I've created?
I thought of creating a java class that writes the output data from the java file in a String and then posts that to the webpage, but then the user would have to frequently refresh the page. So I thought if I could somehow simulate the console on the website that would take care of that problem.
Extra: Is there any easy way to display javafx programs on a website?
Thank you in advance!
I want to display a HTML file in my java GUI.
Big problem: this java program has to run on Raspbian (Raspberry Pi).
I used the browser from eclipse swt which worked perfectly on my PC, but there is no swt build for the ARM processor on my RPI...
A JEditorPane is too weak, because I need to display some pages with CSS
Is there any other possibility?
The easiest solution is of course to see of JavaFX is supported on Raspbian. If it is, then you can use the WebView component (http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm) and most of your problems will be solved. As pointed out in the comments below by jewelsea, this is not a feasible solution yet. This might change with future builds of JavaFX for Raspbian though, so keep an eye on it.
If, for some reason, JavaFX won't work (due to display drivers etc.) then you might want to reconsider your application approach. If you just need to display the HTML file, then you can write it out to disk and display it in the default system browser. If you need to interact with it, it becomes a bit more complicated - you'd basically write a small web server and then respond to user interaction that way. The user will be using their browser of choice, and you'll send responses back to it.
I'm interested in writing a program that will assist me in marking exam papers online. I would like to use the keyboard to control the mouse eg if I press '1' then the mouse will be sent to a specified location and click there. This will double my work output at least. The problem is marking is done through Internet Explorer so the Java program will be out of focus. From searching this site I found that someone has written a library that can receive keyboard input out of focus but I couldn't find any such thing for mice (I don't think Java Robot works out of focus).
Does anyone know whether such a program is possible in Java using standard libraries?
The problem of course is capturing key presses when Java is not in focus. You have three main options as far as I can tell:
Write your own JNA or JNI code to register your hot keys, or
Find a library that does this and call its methods, or
Use a scripting program like AutoIt (if this is Windows) that is linked to your Java program, such as with sockets linking the standard inputs and outputs of both programs.
I have used the 3rd option successfully, but in fact for me, it was usually easier just to do everything in AutoIt.
Note that this statement is not true:
(I don't think Java Robot works out of focus).
The Java Robot doesn't require that a GUI has focus, and in fact does not require that a GUI be running at all.
I did a project for university (it is a personal implementation of Zork the Game). As asked I did it with a text interface, using system.out.print. Is there a way to "put the text interface in a GUI" ? I mean for example a simple window with 2 fields, one that displays text output and one for the text input by keyboard.
I downloaded windowsBuilder for eclipse but.. I dont know what to do! :(
Thanks!
Sure there is, just change the output stream for System class. Create a PrintStream that will write out your data to your swing components and then replace it in the System class to use it.
System.setOut(printStream);
If you're doing this for a text game, I'd recommend using a Glk library. Glk is a cross-platform windowing I/O system designed for text games. You may have to write a JNI interface since the libraries tend to be written in C: an existing project called GlkJNI is meant to work the other way around, so a C program can use a Java UI, but it might be helpful anyway.
For an example of how to create a GUI that does what you are asking, take a look at this article: http://www.comweb.nl/java/Console/Console.html
This does not use best practices for building a GUI, but for quick and dirty, it'll get you started. You really should read up on how to properly write a Swing application, though, if this is going to be something you are serious about.
I created a program with a Swing GUI in NetBeans a while back using the Graphical Editor. I now needed a web version but since I use eclipse now I copied + pasted the code into a new Web Applet project. I found some problems I didn't spot before and updated the code in the web applet.
I want to add some buttons to the GUI, but one problem is its an annoyance to find the part of the code where NetBeans put all the variable declarations, then find another part of the code where all the fields are initialised, then find the other part of the code where the layout needs to be defined, then find the other part of the code where all the action listeners are added, etc... Another problem is that the Swing layouts are complex and also an annoyance to hard code... it is difficult to judge what the exact outcome will look like when you have to edit GroupLayouts with other swing components already layed out in them.
Also, I can't edit this in NetBeans because the Generator is very fussy and if I copy+paste code in there it wont read it as a Java Form nor generate an XML file which I think it uses to manage your layout.
Are there any free GUI designers out there that take a bunch of java swing code and allow you to graphically edit it? How do professionals manage their graphical layouts?
So I should have implemented the Model-View approach from the start.
Here is a nice tutorial on the subject:
http://people.csail.mit.edu/phw/OnToJava/ONTOJAVA755.HTML