String cmd = "start calc.exe";
Process process = Runtime.getRuntime().exec(codeString);
I can call calculator out, but I wish to specify a accurate position like (200,300).
how can I rewrite my cmd String?
I know that java.awt.window can set a window or frame to the specific position.
Is there any method I can use to fill frame or window with my process?
There is no clean pure java solution because JDK does not provide API that can control non-java windows. So, if you want to can use JNI/JNA.
But I can suggest you a patch that will typically work.
Windows OS allows moving windows using keyboard. Try the following manually:
Win+R
type calc and press enter
press alt+space
press M
press enter
now use arrows to move the window. Press ESC to exit this mode.
All these actions can be implemented using java.awt.Robot.
So, you can run calculator and then immediately move its window where you want.
Well, this is not clear solution, but very simple one.
Expected Problems:
Alt+space is mapped to other, custom application
Other window that started together with calc overlaps it.
User will see that window is created somewhere and then quickly moved.
So, everything depends on how important all this for you. This solution is good as an exercise or demo but bad for real commercial application.
Related
I am writing a Java application that uses both Scanner and Console to get input from the user. I would like to add command history support so that the user can use the ARROW KEYS to search previous inputs (similar to a terminal). Is there a way to do this? Right now, when I use either the Scanner or the Console, I get weird symbols like ^[[A when pressing the arrow keys.
I have read about KeyListener and KeyEvent, but my application does not use a GUI.
Thanks!
Good question - +1'd. On Windows, I would SetConsoleMode to change the console to take raw input, but on *Nix it looks like there is more work involved. Unfortunately I don't have any code that I can show you right now, but have a look at this link and see if it helps.
http://www.darkcoding.net/software/non-blocking-console-io-is-not-possible/
In other words, how can I make it so that the window or screen that they are on is the only screen that they can interact with. For example, if the user wants to exit from the screen but then wants to go to another screen, well then they will have to exit from the exit window first before they can do anything else. A better example is when you open multiple windows in Windows and try to exit from another screen than the one you're on, it will make a beeping noise indicating that you can't do that. Something similar to that is what I'm trying to achieve
It's important to note that my program consists of java code, FXML and a little bit of CSS
If you just want a frame to block all other frames from receiving events, use a modal Dialog.
I want to open an on-screen keyboard (osk or tabtip) when a Text field gets focus. This works but, in my current case, the popup keyboard always hides the Text field.
Is there any way to either influence the position of the window when it is started or to move it once it is opened?
I start the keyboard using ProcessBuilder.
cmd /C pathToExe
For my particular case it would be enough to fix it to the top-left of the screen.
(Using Java 1.6 and eclipse3 RCP, target Windows 8)
This post might help you: Can I move another program's window to the front of focus?
They are adjusting the window's Z-position (whether it is on top of other windows or not) but the Windows API they are accessing allows you to change X and Y position, too.
So I am trying to use a robot (either keypress or mouse) to simulate some tests on an application. However, this program isn't allowing me to do so and I'm pretty sure it is a security feature. The application I am using is TEMS Investigation and I am trying to simulate a record and stop recording for some automated tests I have. The program I am using to automate these tests can not access TEMS so there is no way for me to do this without a Robot. So my questions are:
1) How can I override whatever it is that is preventing me from using my robot.
2) Would this be considered illegal if I did? I don't need to break any laws...I just want to get my testing done! lol
I can't even runs something as simple as:
Robot r = new Robot();
r.keyPress(KeyEvent.VK_F2);
r.keyRelease(KeyEvent.VK_F2);
It will run, as I have downloaded some software to tell me what keys I am pressing....just wont be recognized while the TEMS application has focus.
Update: I found out using Notepad I can't use any keys (like "ALT +
F") to perform any menu options. It doesn't even pull up the "File"
menu. I am able to simulate typing in text, just not the context menu.
What was really weird is that I can't even use mouseMove() while TEMS
has the focus
It sounds like your runtime has no knowledge of the TEMS app. If you start it in your java code it should work. For example the following:
Runtime.getRuntime().exec("notepad");
robot.keyPress(KeyEvent.VK_J);
Will bring up notepad and type in the letter J. Try exec-ing TEMS and then send the key press.
And no, it's not illegal.
UPDATE:
To open the file menu in notepad, you would do the following:
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_F);
The two keys must be pressed together before a robot.keyRelease.
I am developing an application which have the following windows
If the information entered in the windows are correct than only the user will be prompted with the windows in the above sequence. Now the customer has demanded me with this user interface.
Now I have to add all these windows in the last window format, with the specification's as the user will be allowed in the 2nd portion of the last image if the first information entered is correct.And the user when launches this app see the last image and can change the values as any time in the respective portions of the last window.
I have coded it in Swing Java.I am new to Java. I am working in Netbeans 7.1.2 I have three files as
1)Login.java
-containing my LoginDemo class which have main and form object of extended Jframe class
-Login class extending J frame and implementing action listener(this class creates an J frame of next file Enter the information.
2)Algorithm.java
creates new J frame object of next file if information is correct.
3)TravellingSalesmanProblem.java
gives the output as shown in Optimal Travel Route window.
I am accessing the information using REST call to a website.
So can anyone help me in this?
This will depend on how you structured you code. If you simply placed components directly onto the the windows/frames themselves, then you might be in for some work.
Alternatively, if you used panels, which you then placed onto windows, this might save you some time.
Anyway. Assuming you only have windows.
for each window do
myLastWindow.add(window.getContentPane());
This is pretty simple, but you'll also need to know the layout you want. I'd suggest something like GridLayout or VerticalLayout from the SwingX project.