Getting user input outside of App Class in IntelliJ IDEA - java

I'm trying to write a program that requires user input of a file path. Using the thread linked below (and setting VM options in Run-> Edit Configurations) I was able to get it to work when I asked for input in my App class. It does not work when I try to ask for input in my object that controls the flow of the rest of the program. I have a feeling it's pretty simple considering I'm already half way there but I couldn't find threads that address my specific issue.
Trying to read from the console in Java

Related

Creating a visual user interface to receive text input using java?

I have worked with Java in the past but have never created a visual user interface, only programs that read from the command line. I would like to create an interface that displays a box with text stating the required input on the left and on the right a blank text field that can be read from by the program. This is for a web app I am working on at my internship, I have very little guidance and would really appreciate any help as I am completely lost at this point. The program currently only reads line by line which is obviously unacceptable for a web app.
Thank you so much for any assistance you can offer.
You can use the browser as your user interface. Create an HTML file to create your form for the user to enter data (which they view in a browser like Google Chrome) and submit back to your app. JSP files are the java equivalent of HTML files with optional java code inside. Download the Eclipse IDE and the Tomcat server and run one of the tutorials for creating a web app. Here's a link to start: https://eclipse.org/webtools/community/tutorials/BuildJ2EEWebApp/BuildJ2EEWebApp.html

How can I target a process without executing it?

I've come across the following code recently:
Process proc1 = Runtime.getRuntime().exec("C:\\Program Files (x86)\\...");
This is working great. However, an intresting problem. This code actually opens a new instance of the specified process and stores it to the object. It doesn't target that process if its already running and store it to the object. I'm guessing thats the .exec() function call which is doing that. How can I target an already active process and store it to my Process object without opening a new instance?
Note: I tried the obvious answers, Process proc1 = new Process("name"); Eclipse says Process cannot be instantiated. I did lookup the Runtime class in the javadoc. As far as I can tell, there is no obvious method that does what I'm trying to achieve. Seems like a simple qustion, I'm sure its been asked before but I couldn't find the answer anywhere which is why I'm asking here. I may be using the wrong terminology which is why.
EDIT:
I'm on Windows 10
My objective is to attatch the process of the game Minecraft to a Process object. Then, I want to move my character forward using robot.keyPress(KeyEvent.VK_W);. I can't just open the process minecraft because all that would do is open the launcher minecraft.exe and then I'd be on a "welcome" screen.
As you can surmise from the Process docs, the process object is created when you create a child process from your code. You can manage the process by using this object, but the other processes out there running are for your OS to manage (or the processes they have affinity to). You'll have to interact with the OS to do anything with them.
An example for finding and killing a process in Windows can be found in this answer.

One-time Java Configuration file on a desktop app

I am doing now a desktop app like a organizer. When the program starts, it has 0 tasks, obviously. I go adding more tasks, but when I close the program and then restart it, all the tasks I have done will be on null.
I think I can use a file that the program will consult. This file will have all the relevant information for load all the tasks.
But, and problem comes here, I want to make a question like "Where do you want to save the configuration file?" It is like Eclipse`s message at start with the workspace. The idea is that the message will only be show until the user specify a valid route.
Can we do this in Java?
Use java.util.prefs.Preferences: https://docs.oracle.com/javase/8/docs/api/java/util/prefs/package-summary.html

Is there a way to replicate an IDE's console like Eclipse, or NetBean's on a website?

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!

Using a Java program I made on a Web Server

I created a small application that, when run, creates or updates some tables in a database by extracting data from some PDF files. Everything works fine in this desktop application, but the next step for me would be to make it possible for an administrator on a website to upload a PDF file and my Java program would then run and update the tables accordingly.
The problem is I have no idea where to start with this (the site isn't done yet, but I'm running some tests and it is going to be coded in PHP). I'd like to know what kind of technologies I need to let the server run the program and update everything as it would in the offline version. Sometimes it takes a while to update everything, so ideally, the user uploading the PDF could continue browsing other pages while the server does its job. (I'll probably implement something that when the server is done processing the file, it says if the program ended successfully or not in a log file)
Can someone tell me what terms to search for on Google or give me some pointers? I haven't chosen where my website is going to be hosted either, so if someone could tell me what to look for to know if they support running applications like this, I'd really appreciate it as well!
This could also apply to other programming languages as I know a bit of Python and C++ as well, so in the future I might have some applications in those languages I'll want to use on the web.
If I'm not approaching this the right way, I'm open to other suggestions, but the best solution would be to keep my Java program intact as I know it works exactly like I want it to and I'd rather not have to start it all over again.
If your host is *NIX based you can use crontab (Automatic Task Scheduler) to run your program at set intervals. Make it check if a "new" PDF exists, and run the program if there is. There may be a way to use Windows Task Scheduler type programs to do it on Windows. This is probably the easiest way.
Alternately you can use You can use shell_exec() in your php to execute a command on your *NIX system directly to run your java program.

Categories