I made a client-server chat that uses a postgresql database to store the users. The server uses comunication protocols designed by me to allow the comunication process and everything works fine. The problem is, the user needs to click on a button in order to open the chat window when he gets the message, otherwise he can't read the incoming message. I would like to program a msn-like service where a window opens when you get a message if the window is not already open and if it's open just show the message in that same window. I can't seem to find a way to do it and any help I can get would really be apreciated. Thanks.
A couple of things you may want to take a look at. First is Java integration with Windows System tray.
http://docs.oracle.com/javase/tutorial/uiswing/misc/systemtray.html
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/systemtray/
The other is to run a "listener" in the background perhaps as a Windows service.
This service listens for messages and pops them into a window. The window can be dismissed (hidden) without stopping the service. http://edn.embarcadero.com/article/32068
Related
Presently I have followed some of the codes that had been solved here and I was able to detect network when I press my button to check. It works fine. When I disconnect from network, I click the button to check again. It works fine. However, what I want to achieve now is that once I load the application, without pressing any button, java should detect network if available and if at any time I disconnect the network, the application should detect and send message.When the network is connected again, the application should automatically detect and send message. Please how can I write this code? Thank you
I have created a web application which makes use of JOptionPane to display some dialogs to the users such as 'Record not found etc'. I did this development in Windows and everything was working fine.
I was then asked to deploy the project war on a remote server which is a RHEL machine without any GUI (similar to AWS machines). When i run my we application over there i get the below mentioned exception wherever there is a JOptionPane statement.
Exception in thread "http-bio-8080-exec-6" java.lang.InternalError: Can't connect to X11 window server using 'localhost:1.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:62)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:178)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:142)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:188)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.swing.SwingUtilities2.isLocalDisplay(SwingUtilities2.java:1393)
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1563)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:147)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1599)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:530)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:570)
at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1320)
at javax.swing.UIManager.initialize(UIManager.java:1407)
at javax.swing.UIManager.maybeInitialize(UIManager.java:1395)
at javax.swing.UIManager.getDefaults(UIManager.java:644)
at javax.swing.UIManager.getString(UIManager.java:790)
at javax.swing.UIManager.getString(UIManager.java:807)
at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:610)
I have already tried to use export DISPLAY also tried
System.setProperty("java.awt.headless", "true");
boolean headless = GraphicsEnvironment.isHeadless();
but still my problem is not resolved? Any inputs? Should i not be using JOptionPane in a web application? if not then what is a better option? alternate of JOption?
You absolutely cannot use a JOptionPane in a web application. And don't even think of using any other of the JWhatever classes in Swing.
JOptionPane, and various other Swing components, appear only on the machine they are running on. So, even if you could get past the exception you are encountering, and display the JOptionPane somehow, the JOptionPane would appear on the server1. It would not appear in the user's browser, so the user wouldn't see it.
So, suppose this JOptionPane has appeared on the server. How is a user supposed to read it, or dismiss it? All they have access to is their browser.
The simple answer is that they can't.
Worse still, JOptionPanes are modal, in that the call to create them doesn't return until the dialog is dismissed. If a user entered a model number that did not exist, your web application would appear to hang, as it could not finish serving the page until the JOptionPane was dismissed. With a few more users using your system, the entire application would eventually grind to a halt as more and more of the web application's worker threads get stuck waiting for JOptionPanes to be dismissed.
Instead, you need to send the error message back to the browser somehow.
If the user enters a model number that does not exist, I would recommend redirecting back to the page where the model number is entered, and showing on this page a message that makes it clear to the user that they were redirected back because they entered a nonexistent model number.
Your code may have been working for you on your machine, but that would only have been because you were browsing your web application from the same machine that the web server was running on.
1: Technically you could show this JOptionPane to a client if you had an X server on the client machine and could set it up as Jim Garrison describes, but that is most certainly not something you can assume.
I have a requirement in which if i am shutting down a server then a notification goes to interested user which bring a pop up on user machine so that they can immediately take any action on this.
It may be like if i am shutting down server than I create an event or message and now according to this event a pop up should come on interested users machine.
Do i need to run a client program in each user machine which will listen that message and will bring that message as pop up on user machine.
I need some ideas that how we can implement this thing in java. It should be something like a window service is running on user machine and if it receives any notification it bring a pop up on user machine and block user to work on mahcine untill he respond to that pop up.
Some one said to me that facebook developer have this type of service. Automatic pop-up for priority communications will help users to take appropriate action.
Yes, you'd need some sort of client running on each machine.
For creating Java applications that run as Windows services, How to create a windows service from java app is informative.
JMS would be useful to accomplish this. On your server you can create a JMS Topic (this will use the Publish-Subscribe model) and then have each of the clients register interest in that topic. Each client will then be notified of messages when they are published to that topic and can take whatever action is necessary.
Does anyone know if there's a way to provide remote access from a client to a Swing application running on a server? This question also involves how to redirect the screen output on the remote server to a file or process, as it may be a headless environment.
What I want roughly is this:
the user on the client starts up an application on the server
the application's screen output is routed to 'something' which sends it over to the client
the user on the client can tap on the screen indicating mouse clicks and can optionally bring up a keyboard for keyboard input (obviously keyboard will only work if the user previously focused something on the remote app
(I'm especially interested in doing this using iOS as client platform.)
I'm remote controlling a Java application on a PC through an Android phone, and I needed my application to open a browser at the phones command, chrome in this case. I created a "Process" for chrome, opening a certain address. However, I need to be able to give tools on the Android phone for controlling the web page, such as scrolling. Can I programmatically send a command for chrome to scroll from my PC application containing the Process?
Sorry, it may have been unclear, but the only connection the android phone has to the program is through a socket. It is only used as a remote control for another Java application on a PC, which has its own screen.
I do not think that clean solution exists.
But I can suggest the following directions:
(1) try to investigate the native chrome API. If it has such ability call it with JNI.
(2) Try to use class java.awt.Robot. It allows to simulate user's activity, e.g. mouse clicks. Unfortunately it does not allow you to find any window outside your application, so it is a problem to decide where to perform the click.
(3) You can create proxy server and make browser you open to go to the target URL through the proxy. The proxy server will insert into the page your javascript that will communicate with server. The application that opens browser will send commands to server. The javascript that you inserted will receive these commands using AJAX and perform them. JavaScript can scroll browser window, so theoretically you can implement this.
If you can target the tab you want to control and edit the address bar you could send the command 'javascript:scrollTo(x, y)'. I just tested it on this page and it seems to work fine, replacing what I typed with the original address of the page.
Can I programmatically send a command for chrome to scroll from my PC
application containing the Process?
Not directly. What you could do is make some sort of web service that sits between the Android client and page that the Android client can send commands to and the page can periodically poll via AJAX calls to see what the client wants. That would be a clean DIY way that would work on other browsers besides Chrome.
You can use vnc viewer applications for that.
http://code.google.com/p/android-vnc-viewer/