Java Swing, application or applet? - java

If I want to write a GUI program using Swing, my understanding is that I can either write a Swing desktop application, or write a Swing-based applet (which I can run using appletviewer or a browser). But it's not clear to me which one to use.
I don't have a particular program in mind; I'm trying to understand generally which is better under what circumstances. Any clarification on this would be appreciated.

Applets are meant to be executed inside a browser and have a few more restrictions to ensure that users can run any applet without major risk. While the concept of applets was revolutionary when it was introduced, it has never had as much success as it deserved. These days, applets are quite an exception.
Desktop apps have less restrictions than applets and in most cases it is probably what you want.
If you want easy distribution of your app, you should also have a look at Java Web Start though again, it does not have the traction it deserves.

There is no better or worse in this regard because an applet is run with Java Web Start using JNLP which is a way to deploy Java technology based applications.
It entirely depends on the intended architecture, distribution, security considerations, use cases, etc. of an application which way is optimal.
Web Start requires software on top of JRE but it is included in the default Java Runtime package since version 1.4.2.

Related

Is a Java applet usable online anymore?

I have a BlueJ applet that I want to run in a web browser. I've realized that the tutorial I was trying to learn from was outdated, and applets are really obsolete. What I'm trying to figure out (I'm searching but finding a lot more outdated info, hence my confusion) is what replaced applets, and if there is still a viable way to use my .jar file in a web app.
what replaced applets
The browser, as a runtime, has become powerful enough to make Java Applets unnecessary. Modern webapps with some amount of JavaScript on the frontend replaced Java Applets.
and if there is still a viable way to use my .jar file in a web app.
No, there isn't. Java Applets are dead and there is no viable way to run them for the vast majority of users on the public Internet.
If you are a software developer, you should abandon applets and start learning a modern full-stack framework. There are many to choose from.
May I suggest you taking a look at CheerpJ?
It allows for both old java applet to run and for java applications in general to be executed in the browser.
There is an extension for Chromium/Google Chrome that can be used for free to test the applet and our product.
Disclaimer: I work for Leaning Technologies, the company behind the CheerpJ project.

Is there a modern way to run java applications in browser?

Is there a modern way to run java application on the web? As far as I know, java applets and java web start both are deprecated.
I have an android app, written in java, which I want to run on server (of course, altered in some way). While java is cross-platform there is no problem to transfer it to desktop (no matter, javafx, swing or etc.).
Apparently, it would be great not to re-write it in some other language.
Nowadays, we're using GWT at work. Well.. It's efficient, it's fast and compatible with all browsers. And it's so easy to build a web page with GWT. You can check tutorials from this link.
And you can look up for Spring MVC. Not the most flexible choice for UI, I know. But give it a shot. link
But.. If you're open to new things, I'll totally recommend React Js. It's flexible,it's super fast with perfect UI. If you ever think of using Java just for back end, React js is a great deal for UI. link
There is an HelloWorld Example Java-Program which is running in a browser:
https://github.com/neo-expert/jsjvm_helloworld
After compiling you can just run the jar file which starts a webserver where the program will be served. (port 8080)

Java Web Start (JNLP) advantages over Java Applet

What do you think are the advantages/disadvantages of a Java Web Start project against an Java Applet? We're trying to figure out what type we should use for our new application. We've already developed an Desktop App (JAR) and we're trying to make is useable from every machine, which has Java installed, without the need of installing it.
Any thoughts?
Applet/browser/JRE interaction problems. If you don't know what I mean, don't even have an inkling (from lost hair) then deploying applets will be a steep learning curve.
What does the browser bring to the deal? If the answer is JS interactivity, integration with an existing HTML based web app., or a few other related things, plenty. If not, then ask yourself what the advantage of deploying the app. wrapped in a browser window really is?
JWS Jar caching and update is more reliable (and can be taken under programmatic control, if needed).
The AppletContext provides some ability for an applet to interact with the environment, but the JNLP API goes beyond what the AC can achieve (mostly).
General usability. These may or may not be a problem for your use-case.
A free floating JWS deployed app. does not get closed when the browser gets closed, and does not suffer focus loss on tab change.
If 3 applets each with controls are embedded in 1 page with links, what gets focus? Since Sun never bothered to specify what should happen (according to them) it has been different across JREs over time. Now it is common for the JRE to grab focus for the applets. If it does, it it generally impossible to use the keyboard (alone) to get to the links and other focusable elements in the web page.
It is far easier to resize a desktop app.
A desktop app. (with splash screen, desktop shortcut with icon etc.) can look much more professional.
Of course, it should be mentioned that the lines become blurred:
Since JWS was introduced, it could launch applets
Since the Plug-In 2 architecture JRE, JWS could launch applets that remained embedded in a web page.
..we're trying to make is useable from every machine, which has Java installed, without the need of installing it.
I would sweep aside the 'without the need of installing it' requirement of that since there is always the passage of time and the need for updating plug-ins. On that note, use deployJava.js to handle JRE minimum version checking. The script will either embed an applet or write a link to a JNLP launch file after checking minimum Java is available.
See also
The Stack Overflow info. pages for tags:
Java Web Start
JNLP
Applet
Since 6u10 the significant difference is down to an applet appearing in (and being able to interact with) a web page (possibly opening windows that don't necessarily interact very well with the browser window) and WebStart applications being separate from the web browser. WebStart applications will automatically get their own process, which may be significant from a memory usage point of view, at the cost of a slower warm start. Applets have access to javax.jnlp.* since 6u10.
I think web start is what you should use. As far as I know it allows you to start full blown java applications.
JNLP can (and in some cases should) be used with applet.
Just finished integration of applet that read-write to user's file system.
Advantages of applet are obvious -- no installation on client machine.
Disadvantages:
not working in Chrome anymore;
additional configuration required -- each jar's manifest file must contain
Permission: all-permissions
line.

Java Web Start vs Embedded Java Applet

I'm going to deploy my Java game to show it to my friends and whatnot, but I'm having trouble deciding between Java Web Start and applets.
Under what conditions is one preferable over another and what advantages/disadvantages are there?
If your game is going to consume a lot of cpu and memory resources I recommend deploying it as Java Web Start since applets run slower.
If you have some java-javascript interaction you'd better use applets
Here you can find a table with advantages/disadvantages
Java applets have the advantage that they run instantly without the user having to click on anything. In addition, applets will automatically prompt the browser to download the Java plug-in if it's not already installed. This is important if your end users aren't very tech-savvy.
However, applets are extremely limited in terms of memory (60 - 90 MB), so if your game uses a lot of graphics you will notice a performance slowdown.
If performance is an issue, you will probably have to use Java Web Start. It suffers no performance penalty, but is a lot trickier to deploy and more difficult for end users to run.
I'd make it run as either, and then choose which to use. An applet will sit in a web page nicely. A WebStart application will look like a normal application (only with a little triangle to indicate it's from the web). From 6u10, applets can use JNLP services, and can be dragged out on to the desktop.
You can actually have both applets and web start with the same Java applet code. Web start supports launching unmodified applet .jar in a separate frame, all you need is to write JNLP file properly. You can specify the applet parameters in JNLP file, if required. The only difference is that the applet will pop out in a separate frame and not as part of the web page which may or may not be a problem. Why not to provide both applet and web start link? JNLP is not much more difficult to write than the applet tag.
I think it should not be much difference between Web start and applet performance unless applet runs in some old JRE that is part of the browser. I would not recommend this anyway - as any other software, Java evolves and gets better over time. This may explain posts talking about that Web start application is much faster, this otherwise would be very difficult to understand. If you applet supports also old JREs, I think you can simply specify the low version number in JNLP, adding + so it can also run with future versions.
Since Oracle is not making any progress in delivering a non-NPAPI java plugin, I would say that applets is an obsolete technology.
Otherwise, we would dive into a good old IE-only web. Banks are already requiring IE browsers so they would not spend tons of money to modernize their software. I feel sorry for them.
Web Start requires the client to install the Java application (and possibly the JRE) on their computers. If they don't have administrative rights to install software this is going to be a problem.

UI for a Desktop App

I have a desktop application . The functionality is complete, but user interface requires a lot of work. I am looking for UI tools.My current operating system is Windows and application is required to run on both Windows and Linux.
Can you guys recommend any?
The software is customized file management application for a specific client, with future plans of web integration.
Thanks in advance :)
Application Environment
Lang : java,
IDE : Eclipse 3.4,
Target Platforms : Windows Vista-OpenSuse 11
SWT is another option. The advantages are a look-and-feel closer to the native platform, and generally faster execution times. The main disadvantage is that you will have to have different distributions for different target platforms, as SWT depends on platform specific libraries.
With an eye toward the web integration, look at GWT. You write your interface in Java but it gets generated into Javascript and can thus be run in a browser. This may make your deployments easier. On the downside, you lose a bit of the rich client UI, but maybe you don't even need that. It all depends on how complex your UI is.
A word of advice: you mentioned future plans of web integration. Take special care to isolate what logic you can from the UI. Keep the UI as clean as possible, and then you may be able to use the same logic in the web UI either on the client or the server.
If you are just looking for a GUI designer you could check out Netbeans IDE which has a built-in Swing user-interface builder.
Alternatively you could build a front-end in JavaFX. There's not much tooling for FX yet but a new tool was recently previewed at JavaOne 09. Not sure when it's being released.
I've used Qt a few times and find it very good at this sort of thing -
Qt Home Page I'm not sure if it's exactly what you're looking for as your application is complete, however, but it may be worth a look.
Found an excellent fix,
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(myform);
looks so cool in my vista and suse , its enough for now.
Thanks for everybody for helping out

Categories

Resources