I have developed a map applet that has JLabels on it. The JLabels get their X/Y coordinate values from an applet parameter file in order to be shown on the map in an exact position.
The problem is:
The map applet normally runs on a big LCD screen but some clients want to view the map in their browsers too. The issue with this is that the applet is being loaded from a server to the client's browser and it should always connect to the server so they can't run the applet locally. In this case, X/Y coordinates shift a little bit on map.
One solution may be to create two versions of the applet -- one for the LCD and one for client computers. But is there any option to use local parameter file for clients?
As far as I understand, you can determine the type of display programatically. So you can just pass 4 parameters to the applet instead of 2 - x, y, xLcd, yLcd, and use the appropriate ones (with a simple if-statement in the applet).
But better try to analyze what causes that shift, because it should not happen in the first place. Or ask a question (giving more details) - why is the shift happening.
Related
I'm trying to manipulate an external window on Java, with JNA. I want to find a specific window and then minimize it. Every window that I've tried worked well but one (obviously the one that I need). That one can be found and set to the foreground, but can not be minimized programmatically. I've also tried to move it with User32.INSTANCE.MoveWindow, but that command failed too.
I was wondering if there are applications that do not allow JNA window manipulations. If so, what can I do? My code is shown below.
HWND test = User32.INSTANCE.FindWindow(null,"windowname");
User32.INSTANCE.SetForegroundWindow(test);
User32.INSTANCE.ShowWindow(test, WinUser.SW_MINIMIZE);
From the API for ShowWindow:
nCmdShow
Type: int
Controls how the window is to be shown. This parameter is ignored the first time an application calls ShowWindow, if the program that launched the application provides a STARTUPINFO structure. Otherwise, the first time ShowWindow is called, the value should be the value obtained by the WinMain function in its nCmdShow parameter. In subsequent calls, this parameter can be one of the following values.
It would seem to be that your minimize command may work if you call it a second time.
I'm currently working on a client-server project where the client sends a request to the server and the server runs a database statement based on the information from the client. As there's no static length for the output I add all the data to a ArrayList<String> and send it back to the client.
The data that the client requests has a certain hierarchy so that one could also display it using an XML file (however the output to a GUI is wanted here instead of file creation). There's several ways of displaying I came up with. One would be using a simple text area, however using this, I need to do applying the layout myself and the option of folding where I can expand and collapse certain items is not possible.
Another possibility of course would be using a simple JList, however I read on Stackoverflow that using a JList to display hierarchical things is way easier done using a JTree.
When I decided trying to implement JTree I also found the Genealogy.java file provided by Oracle in their documentation of JTree. As to be seen in the first examples of this documentation there is always a filestructure being displayed and hence also a filestructure kind of representation (using folder- and file-symbols) is shown. In contrast to this Genealogy.java only shows the names of the persons so I tried to adapt the implementation from Genealogy.java to my case however I'm completely clueless of how to do this as I don't even know where these symbols come from and where I could possibly disable them and also don't really get what some of the methods I need to implement do.
As I'm currently really clueless of how to possibly accomplish that I really need some detailed help (only telling me to come up with my own implementation of JTree or TreeNode doesn't really help me at this point). Is there any simpler way or is the need to implement any of the before mentioned interfaces inevitable and if so, how would it be done?
EDIT:
This is how it currently would be displayed (example taken from the Oracle documentation, showing folder- and file-symbols in front of the string):
And this is how I want it to be displayed (also from the documentation, this time only displaying a string as node):
The answer almost certainly will be found via the (icon of the) TreeCellRenderer used for the tree nodes. See the File Browser GUI for tips. It shows how to set the icons in the FileTreeCellRenderer. Admittedly the point here is almost exactly opposite what it was there, but it still comes down to the same thing - the icons.
The section of the tutorial that covers it is How to Use Trees: Customizing a Tree's Display.
Here (http://www.desktop-macros.com/) is a program which records sequences of mouse clicks and key strokes on a PC and then plays it back to perform some user-defined actions.
Now, what I'd like to achieve is a bit more demanding: I'd like for example to launch a browser with mouse clicks, wait until it's started (i.e. its application screen is visible) and then again perform some mouse&keyboard actions.
Of course it would also be useful to obtain also other information, like position and dimensions of the window.
Is it possible to make such fancy OS-related operations (like checking whether an application is fully-loaded) with Java? Maybe there are some non-standard libraries with useful API?
If not, could you recommend some way/language of solving such an issue?
I use Autohotkey that has the command WinWait that waits for windows having the good title. But I rely on Send {Enter}, not on mouse, to do things.
We have a desktop client with several hundreds of users in our company. Sometimes it throws exceptions and crashes, but it's been hard to get the users to report their issues. To track these exceptions we are catching them and e-mailing the stacktrace and user specific data relating to the crash to a server wherefrom we then can view a log of all the crashes.
What would be really nice, is if we could log, not only the exception details, but also a screen recording video clip, of say the last 2 minutes up until the exception.
It shouldn't be very hard, all we need is some software that continuously records the screen and saves the video on drive, but erases everything older than a certain number of minutes. When the crash occurs we have can simply pick the current videoclip and attach it along with the exception details.
Anyone know of such a software, or anything similar that would solve our issue?
----------Solved:
I used both AndrewThompson´s and pjvds answers below. Andrews strategy outline, but with C# instead of Java, simply because our application is written in C#. The Code Project article pjvds linked helped me on how to do it in C#.
Here is one strategy:
Define a ScreenGrab object that encapsulates a BufferedImage and other relevant information (e.g. the time in millis or the mouse location).
Gain a screenshot using either the Robot or by establishing a BufferedImage the size of the content pane, and painting the content pane to the Graphics instance obtained from the image.
Create a ScreenGrab object and add it to an ArrayList
If the array list has exceeded a certain size, delete the first ScreenGrab in the list.
Rinse & repeat, perhaps at 2FPS, until an error occurs.
Either:
Use an adapted version of JpegImagesToMovie (uses the JMF) to transform the images (with pseudo mouse drawn in) to a MOV.
Zip all the ScreenGrab objects and send the archive instead.
Tweaks on this technique. The advantage of sending the ScreenGrab archive are multiple.
It can record the GUI perfectly, without the 'lossy' effect typical of JPEG compression.
If the user leaves the computer, neither the screen nor mouse position will change. So compare each one to the last and if the details are the same, skip storing it. The MOV would have to be at constant frame rate, but the Zip of custom objects could record at whatever rate best suits the user activity.
I remember I tried some code from a Code Project article years ago to accomplish the same. Capture Activities on Screen in a Movie.
We removed it from our software a release later due a lot of complains. People don't like it when their boss records their screen ;-)
I am developing an Java swing based application which will 3 distinct main JFrames and each one of these will have to be displayed on one of the three display-monitors present in the system. Moreover application is going to have capability to alertif a particular display-monitor gone disconnected or reconnecetd.
Each main-JFrame must be displayed on a specific display-screen. This is due to the place where these monitors are going to be located. More like a point of sale scenario where one monitor can show things for sale-person and other for client and other for a security person.
Now the main issue is how to know which monitor is which. I solved this issue by getting serial-no of each monitor by calling a VBScript from within Java.
But still another problem is how map serial-no information of the monitor in Java. In Java what I can get corresponding to each monitor is a java.awt.GraphicsDevice instance and I have no idea how I can map serial-no information to this as the only way to have these instances of java.awt.GraphicsDevice is GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices() and this function does not ensure that it will return the devices in a sepecific sequence, each time the function is called.
Thanking in anticipation
Java supports multiple monitors via a GraphicsEnvironment and GraphicsDevice objects. Check the GraphicsDevice javadoc for more info.
Does the GraphicsDevice.getIDString() method give you a stable value that you can compare against the serial numbers? If so, you can write all identified serial numbers to a property file, and do a comparison each time your program starts (if the ID isn't already the serial num). This property file could also store the position of each display (left, center, right or top, middle, bottom, etc)
If you cannot determine the correspondance between the id and the serial number, you could trigger a 'display setup routine' whenever you see an display id that is not in your properties file.
This routine would prompt the user to confirm the display model number and enter the position of each display (consider the display orientation settings in Win,OS X, Linux etc). If you can draw widgets to a specific display, you should be able to collect this information. Also, if the user rearranges the physical position of their displays (perhaps swapping the position of two displays), then they could manually execute this routine.