-1

Can any one please tell to how to make a desktop client.

I mean i have a frame in which it has a text field and a button.

when i clicked the button i want my text which i have placed in the text field to get placed in the text field of a website and should get processed in a website by a button in the website just like we place our id and password and click sign and the dynamic text produced by the website based on our input should be displayed on my frame.

That means i am operating a website indirectly from the desktop through a java frame. so i want to know what kind of things i should do in the action listener code of the button.

I know jsps and servlets even but unable link the things to make this application.

Any please do help i m new to development.

user2341870
  • 11
  • 1
  • 4
  • 1
    Can you tell what all you have already tried? – rahul maindargi May 02 '13 at 06:24
  • 1
    I don't think you want the desktop client to populate fields on an HTML page. Instead, separate your webapp to presentation and controller layers, and the make the desktop application to communicate with the controllers directly. – kaskelotti May 02 '13 at 06:24

2 Answers2

0

I think all you want to do is to make a HTTP request from your application, by passing the value as parameters.

May be a possible duplicate of How to send HTTP request in java?

Go through the link, it may be useful.

Get value from the textField, make HTTP request along with the parameters(obtained from the textField), and you are done.

If you want to open the web browser while requesting, you can make use of Desktop.browse()

Community
  • 1
  • 1
Maximin
  • 1,540
  • 1
  • 11
  • 30
0

You are going to have to use ProcessBuilder (or alternatively Runtime.exec() to execute explorer.exe explicitly with the options you want.

Process p = new ProcessBuilder("explorer.exe", "http://yourpage.com/Myjsp.jsp").start();

You can send the value you want to autopopulate as a pat pf URL parameter like

Process p = new ProcessBuilder("explorer.exe", "http://yourpage.com/Myjsp.jsp?myvar="+my value).start();//where myvalue is String variable where you have the value from Frame.

I think you can use below code...

if(java.awt.Desktop.isDesktopSupported()){ // Desktop Not supported on all Platforms.
   Desktop desktop=Desktop. getDesktop();
   desktop.browse(new java.net.URI("http://yourpage.com/Myjsp.jsp?myvar="+myvalue));
}else{
  Process p = new ProcessBuilder("explorer.exe", "http://yourpage.com/Myjsp.jsp?myvar="+my value).start();
}
rahul maindargi
  • 4,826
  • 2
  • 14
  • 23
  • No need to make it complicated. [Desktop.open()](http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html#open(java.io.File)) is enough. – Maximin May 02 '13 at 06:38
  • OP wants to `open the web browser with some URL`. `desktop.open` takes `File` as a parameter So `it won't` suffise the perpose. – rahul maindargi May 02 '13 at 06:46
  • 2
    Oh sorry, it is `Desktop.browse()`, not `Desktop.open()`. My mistake. – Maximin May 02 '13 at 06:49
  • `Desktop` is `not supported` on `all the platforms`. SO I think `combination of both Process and Desktop` will be right way to go about it. – rahul maindargi May 02 '13 at 06:57
  • From documentation: "The methods look for the associated application registered on the current platform, and launch it to handle a URI or file. If there is no associated application or the associated application fails to be launched, an exception is thrown." It is supported in all platforms, as far as I know. – Maximin May 02 '13 at 07:01
  • @Maximin see `documentation` for `isDesktopSupported()` at http://docs.oracle.com/javase/6/docs/api/java/awt/Desktop.html#isDesktopSupported(). Also see this line on documentation `public static Desktop getDesktop() Returns the Desktop instance of the current browser context. On some platforms the Desktop API may not be supported; use the isDesktopSupported() method to determine if the current desktop is supported.` – rahul maindargi May 02 '13 at 07:04
  • also see this. `See this `http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6486393`` – rahul maindargi May 02 '13 at 07:10
  • Requirement is to open a web-page. In almost every platform there is a web-browser. So in this case, no need to bother about that. From the documentation of java6(that you provided now) "But for a specific file, there may not be an application registered to open it." If there is no application registered with the file type, then only it will a exception. The documentation is not saying that `Desktop` is not supported in all platforms. – Maximin May 02 '13 at 07:11
  • You are providing reference based on java6. I haven't faced the issue so far, in java7. Usually bugs get fixed in updates. – Maximin May 02 '13 at 07:21