Two Laptop Bag*
The moose likes Beginning Java and the fly likes Using swing in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using swing in Java " Watch "Using swing in Java " New topic
Author

Using swing in Java

Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
I know Swing provides good GUI capability. Now, with web applications we use JSP or Servlets(again like JSP). How do we use swing here when we going to run web application using http. Most examples in books i have seen are using applet or stand alone application. That is not a normal case. What kind of set up we need in architecture to use swing.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
You can't use Swing in a standard web app. Embedding applets are the only way to get Swing in a web browser. You can distribute stand-alone apps over the web with jnlp.

The end result of a web application is an HTML page displayed in a browser. Java is one way to provide dynamic content in the form of generated HTML documents delivered through a servlet container (like Tomcat).

You may want to look at some web frameworks such as Tapestry (My personal favorite), Spring MVC, Struts, JSF (not sure if JSF really qualifies as a framework though).

In the end it's all HTML and/or some script (usually javascript).

Although I would reject the idea that a stand-alone Java app is not the 'normal case'.
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Hi Steven,
So what would you suggest best for making colorful webpages.So,should we use just JSP,Servlets,HTML,Applets and Java Script.Would that serve the purpose??Can we make a full-functional website without using swing.I am thinking to make a website,but i am not quite sure where to start with.I need the drop-down boxes,dynamic images,login etc functionalities.Can i avoid swing and get all these funtionalities into my website.Please tell me the simplest way..thanks.


SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Just to be clear: no websites use Swing. Swing-based applets on the Web are exceedingly rare, and those few that exist are tech demos or toys of some kind. No websites use applets as their primary mode of interaction.

Swing is for desktop apps; JSP (i.e., HTML) is for web apps.


[Jess in Action][AskingGoodQuestions]
Jas Oberai
Ranch Hand

Joined: Jan 16, 2005
Posts: 231
Thanks Ernest,
But just a small element of doubt still exists......if for instance,I use JSP to generate web-pages,I won't have lay-out manager sort of functionalities,so dont you think that it would be a little difficult to handle with simple HTML tables.And where from would we get the drop-down menus,checkboxes....do you think html should be used to generate all of them in combination with java script.
Thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You'd be surprised what you can do with HTML (for expressing the content) and CSS (for doing the formatting and layout.) Remember that every web site you visit is working with these same basic tools.

JavaScript adds some behavior, but it can't do anything to the appearance of a site that you can't do without it just as easily.
Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
Well, coming from client/server systems where we could do two very powerful things in Powerbuilder/Oracle forms world - create Tab pages and create tree navigators. These two give a very clean look to application and let some one look application more matching business needs. Seems from this thread there is no way I can do this with JSP as these are really not supported by HTML - may be tons of code of Javascript etc will do. We have applications that has a number of menu/sub-menus and tab pages for each submenu. Really, only way is to go for ASP.NET and forget Java - but I have concers with some special outerHTML that Microsoft uses that will fail on Mac, Firefox etc.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Ernest Friedman-Hill:
No websites use applets as their primary mode of interaction.
Are you sure about that? I support a web site built around applets. Also, I am fairly certain that at least one on-line brokerage uses Swing to enable all sorts of functionality to traders. In fact, my brother in laws firm writes support applications for traders and brokers using Swing over the web. So, swing and applets may be rare but I wouldn't say that there are no websites using them.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Raj Puri:
We have applications that has a number of menu/sub-menus and tab pages for each submenu.
You mean like this: http://www.symbol.com/
Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
No, not like that. I am talking of two controls. Navigator conrol - it has like file explorer and tab pages(there could be nested tab pages). These can not be implemented using JSP/HTML etc, I believe tab page can be done with swing. But doing w/o applet constraints design. Applets are not allowed because of security concerns at most classified govt projects.
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Originally posted by Raj Puri:
I know Swing provides good GUI capability. Now, with web applications we use JSP or Servlets(again like JSP). How do we use swing here when we going to run web application using http.


If you wrote a good API to handle all the business logic, which was generic enough to "port" over to any context, then moving it from say, a web application to a command-line interface or GUI should not be a problem. If you find that you need to change a lot of code (not the presentation-layer), then its probably a bad design.

Are you trying to port a web application to a GUI or vice-versa? HTTP browsers are very basic, they are HTML viewers with some addon's. If you want more control over what the user sees, with rich widgets, than using a GUI library such as Swing or SWT/JFace would be the way to go. If you use the MVC pattern, then changing the "View" should not be a problem at all.

Originally posted by Raj Puri:
Applets are not allowed because of security concerns at most classified govt projects.


If you sign the applet, you can bypass the security and the applet can do I/O on the local machine. I don't know what you mean by "classified govt projects".
[ May 14, 2005: Message edited by: Kashif Riaz ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Thomas Paul:
So, swing and applets may be rare but I wouldn't say that there are no websites using them.


I stand corrected, I guess. Maybe I should qualify what I said to "no general-purpose consumer Internet sites." Intranets use them, certainly, as would sites that deliver rich functionality to motivated customers. But what I was saying in general was that any consumer website that wants to capture Joe Sixpack's attention commits customer-service suicide by requiring the Java plug-in.
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Originally posted by Raj Puri:
No, not like that. I am talking of two controls. Navigator conrol - it has like file explorer and tab pages(there could be nested tab pages). These can not be implemented using JSP/HTML etc,

I would be careful saying that. The project I'm working on has tabbed 'panes' and expandable/collapsable trees all done in html and javascript (java servlets on the backend).

I believe tab page can be done with swing. But doing w/o applet constraints design. Applets are not allowed because of security concerns at most classified govt projects.


It sounds to me that you don't know just how much cool stuff can be done with just html and javascript.

Things like JSP, Tapestry, Struts, SpringMVC, ect... are frameworks that provide easier development than trying to do all that with straight servlets (which in the end generate html and javascript).

Tapestry is my personal favorite framework and here are some links that show a few cool things being done with it. Remeber by the time it gets to the browser it's all just html and javascript.



menus

workbench. An example of many of the standard Tapestry 'widgets'.

Tree component.

Again all this is done in the end with just html and javascript. It's much more capable than what you seem to think.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using swing in Java
 
Similar Threads
Regarding Usage of Web Services In desktop Swing application
swing
How can a Swing-based framework be done for various users without jdk installed?
Pattern for routing web client's (Servlet) request to Controller(POJO) of Swingclient
JNLP and web application