Best Java GUI performance on Raspberry PI - java

I hope somebody can help me and you fiund this question useful and interesting.
I'm making a Java application for my degree project using a Raspberry Pi. I'm programming all in Java and Linux, but now that I'm starting some developing tests,I found an important issue.
I built all the user interfaces of the application using Java Swing, and although on Linux it runs quite well, I'm detecting bad perdormance on the Raspi, because the GUIs behave wuite slow on the Rapi and the CPU has a huge load.
I've been searching on the net for performance tests and comparisons between main GUIs in Java, but I didn't found relevant results for my problem. Some programmers talk about is better to use AWT or SWT over Swing. I also found that maybe the best approach is to use the LWUIT, but this framework is for Java ME apps and I'm developing my application using Java SE.
Does anybody know which is the best performance Java GUI for the Raspi? The main elements I'm using are: Jlist of Elements (designed as an ArrayList), a few JButtons, pop-ups, key and mouse listners and custom images (for the backgrounds and for the image preview icon of the elements). I want to keep it simple, fast, with the minimum CPU charge and best performance on the raspi. Any ideas for the best GUI in this scenario?
Thank you so much!
Best regards.

Related

Is Processing (2d graphics) appropriate for larger projects?

I'm going to be working on a decent-sized game in clojure and for now it will have 2d graphics. Is Processing (or rather, Quil, which is just a clojure wrapper for Processing) an appropriate tool to use for this.
Processing presents itself as a way to quickly experiment with different ways of generating and manipulating graphics rather than a scalable 2d graphics library, but I don't see any obvious reasons why it couldn't be used as such, so long as you take care to properly separate logic code from rendering code.
If there are better options, let me know.
Processing is certainly cool, but is somewhat specialised towards visualisation / interactive animations. It also has it's own mini-language designed for visualization applications. While it is possible you could make a decent game using it, you might start running into performance issues as this is going outside its usual usage.
For a decent-sized game I expect you will ultimately want to use OpenGL directly, in which case LWJGL might be a better option.
Ultimately, you probably need to prototype using both and figure out what works best. As a rough benchmark, you will want to render a full screen of tiles plus 1,000 sprites at 100+ FPS with less than 20% CPU. If you can demonstrate that processing can handle that then you may be fine.
Other options that you can consider:
Swing - good for simple 2D games. Has the advantage that it is built-in to the standard Java distribution and has lots of good tutorials. Wasn't really designed for games but works fine providing you aren't too demanding.
JavaFX 2.0 - roughly intended to plat in the same space as Flash (rich internet applications). Looks pretty cool, but is still fairly new. Again, probably fine for simple Flash-style games.
I would be careful of using processing for this. I'm not sure about PC, but on the Mac Processing can have pretty hi CPU usage, depending what you are doing. So if your game is cross platform there might be a better option. If it's an online game why not use Flash? The scripting languages are not too far apart and in the book 'Processing: A programming handbook for visual Designers and Artists' (Casey Reas & Ben Fry) there's a handy little section at the back (pages 686 - 691) showing the comparative syntax of Processing, Java, Actionscript & Lingo that would be a useful way of getting you started.

Converting an existing web app to desktop application

I saw some other similar questions on this topic here but they were not very helpful so I a posing this question.
What is the fastest way to convert a reasonably sized, simple web app to a Java desk top based client targeted for pc and mac? Unfortunately I can not share a whole lot of details about the app here due to various reasons. The most complicated UI in the app though is a page that contains a multi level threaded discussions (please see here for an illustrative example of what I am talking about.) The current web app is based on python so I can not re use anything from the server side code (dont think this is an issue)
I have never done any swing or awt or any other Java based thick client GUI work. My thinking is more or less defined by web based applications. I am capable of doing end to end web app development (including backend and decent UI using HTML, CSS and JS) using Java or python. For your answers please focus on Java solutions only.
So here are my questions
What is the best framework or tool I should use? I found some of the following tools on the web as part of my research.
Awt - does not look like this is a good choice.
Swing which I believe is bundled with regular Java SDK/JRE. - This may be my best
bet.
SWT which seems to compliment Swing in some fashion.
Griffon based on an article here. This framework uses Groovy ( I
have no clue about Groovy, btw) Adobe Air flex. Any open source
frameworks?
What are some of the other issues that I need to keep in mind? Some that I would like your comments on are:
How does the fact that it needs to be deployed on the client complicates things? Since we are using Java, I believe this to be a non issue. I am aware of the usual trade offs between a web based app and a desktop app (e.g. ease of deployment and upgrades etc etc.)
How easy is it to create a one click installer and bundle the app and the environment needed - eg. JRE etc?
The product needs to work on Mac and Windows. Does that complicate things in any way (Again, since it is Java I am assuming there are no gotchas but would like to be forewarned if there are any)
What is the framework or technology that may be good to have on the resume as a skill set?
My deadline is a max of 2 months - would that be enough for a reasonably simple web app given that I need to learn all of these technologies? I am just trying to get a sense here - I know it is most likely impossible to give an accurate answer - just assume I am smart enough and can pick up any unfamiliar tech stack fast enough.
Thank you!
GUI toolkit
Given "Mac and Windows", I'd say that settles my recommendation as "Swing" (perhaps with SwingX1).
I agree with your assessment of AWT. It does not support formatted text in any component out-of-the-box. It also lacks trees, tables (and other components) & people with recent experience using it. Note though, that it is also "bundled with regular Java SDK/JRE" just like Swing, it is just that it is older and less enabled than Swing generally.
If anything complements Swing it would be SwingX. SwingX is built on Swing and provides advanced controls that are not available 'out of the box' in the J2SE.
Swing and SWT are mutually incompatible - use one or the other.
I have no experience with Griffon.
Swing is the most used of the options outlined, so for getting help (ignoring other potentially important factors in the decision), it would be a good choice.
Note 1) Add SwingX if they have any groovy components that present threaded conversations easily, but I suspect a JTextPane would suffice.
Deployment
As far as deployment goes, that is a little more tricky than it seems. Many desktop computers do not come with Java as standard. Those that already have it, might have an old version.
To ensure a JRE of the right minimum version to run the app. is available, use the deployJava.js (mentioned, with links, in the JWS page below).
To provide a 'one click' launch experience for the user, look to Java Web Start.
Cross-platform gotcha's
Unfortunately, though Java is x-plat, there are plenty of things that programmers can do that stuff that up. E.G.
Not accounting for the platform default:
File encoding (file.encoding2)
Line break (line.separator2)
File separator (file.separator2)
Coding fixed size ('absolute layout') apps. that will be shown as different sized apps. on other OS.
...
Note 2. That is showing the property to use for each.
Timetable
Obviously I cannot speak for you, but I can tell you that I would have had no chance of going from 'which technology' to a 'deployable app' within two months.
Hope you're more capable than me! ;)
You said that you wanted a Java solution, but be aware that there are plenty of Gui options in Python, and you already have your web application written in Python.
Groovy is a different programming language than Java, but Groovy runs on the JVM. Do you want a Java solution or a JVM solution? I ask because you mention Griffon.
Assuming you want Java, I think your main options are Swing, SWT, JavaFX 2, and Apache Pivot. Oracle has said that they intend for JavaFX to replace Swing as the GUI platform of choice. That said, JavaFX 2 is in its infancy, and only a preview release is available for Mac right now. The upshot of JavaFX and Apache Pivot is that you could use the same code for your web application as your desktop application.
You can try doing so in small steps:
* As a first step you can create an applications with SWT and embed your application in a browser control.
* Then you should move pages and some controls from the web app to the desktop one by one.
In this way you can get a minimal application in hours :)
P.S. If you want an iOS app with this approach it's worth looking at this open source project: http://en.wikipedia.org/wiki/PhoneGap

Tool to create 3d programs

As we know that we can use NetBeans for creating Swing programs (with drag and drop the code for each part of Swing will be written automatically)
Is there any software that help us write Java 3d code without writing code manually?
I don't think there's anything out there like that for almost any languages. The problem is... what exactly are you creating? With swing you know you are making a GUI for a certain set of applications but with 3D, the applications are endless. The only thing out there are APIs to help with your job. If you are an animator or game maker there are plenty of game engines to help you out.
Widening your question slightly if what you're looking for is a more productive 3D java environment (rather than Java 3D itself) then Demicron's WireFusion is worth a look. It's Java based and the higher-end versions allow pretty comprehensive access to the underlying engine so you can effectively extend it to do nearly anything.
I've used it for a project or two and I highly recommend it, the only issue is it's ridiculously expensive - in fact jaw-drop'ingly so.

Why are (almost) all the on-line games written in ActionScript (Flash) not Java?

I absolutely love good defender games (e.g. Gemcraft, Protector: reclaiming the throne) as they can be intellectually quite challenging; it's like playing chess but a little less thinking and a bit more action. Sadly, there are not that many good ones out there and I thought I would create one myself and share it with the rest of the world by making it available on-line.
I have never worked with ActionScript but when it comes to on-line games, this is the main choice. I have tried to find a decent 2D game in the form of a Java applet but to no avail. Why is this so? I could write the game, most comfortably, in Delphi for Win32 but then people would need to download the executable, which could deter some form downloading it, and also it would only work on Windows. I am also familiar with Java, having worked with Java for the last four years or so; although, I don't have much experience with games programming.
Should I not be deterred by the fact that all on-line games are written for in Flash and create my defender game as a Java applet, or should I consider learning ActionScript and games development for the ActionScript Virtual Machine (AS3 looks very much like Java... but still, it's an entirely new technology to me and I might never use it professionally.)
Could you, please, just answer the the question in the title? Why Flash, not Java applets? Is it only 'politics'?
Flash is more popular since its penetration rate is huge.
Flash is also more powerful when it comes to create and integrate graphics assets (since Flash CS* is also a vector animation editor).
It's also very easy to embed sounds and fonts assets, to play with bitmap effects, without using any aditional library.
And last but not least, there's a lot of sites who offers ActionScript APIs in order to earn money with your games by adding various ads in it (such as MochiMedia, Kongregate...)
Flash provides a fully-built graphics and sound engine that will handle separate objects ("sprites") on paths and animation.
In Java those features would need to be provided by third-party library. Java does provides the necessary building stones to build such an engine, however.
JavaFX might change this, however.
I can provide a little insight on the Java side: Early in the history of Java, Sun tried to push Java applets as the new way to display dynamic content in a browser. This attempt was doomed to failure by the combination of the following factors:
Java had (and still has) a lengthy load time for the (JRE) runtime;
Java originally had only AWT as a GUI toolkit, and AWT is limited and really ugly;
Java used to be a lot slower before the advent of faster CPUs and JIT compiling;
Java was (many think intentionally) supported very half-heartedly by Microsoft in IE, so it wasn't well integrated and ran poorly.
All this gave Java (deservedly) a horrible reputation, from which desktop and browser Java have still not recovered. To most people, Java stands for ugly, slow and often not working applications. It still suffers from this stigma today.
While both Java and Flash are Turing complete programmng environments, Java is more universal, with a bigger set of libraries for all kinds of different purposes. Sun strove to have the Java environment be universal among platforms, so browser-side Java includes a lot of libraries that are usually not needed. Again, more load time.
Simple answer: the flash player is installed in almost all of PCs, but JRE isn't.
Flash has a much wider install base, that can be the only reason. I personally don't install Java on my machines....flash, of course.
Why write something for a far smaller audience? I'm not saying it's wrong to, but that's usually the reason when you're making games for a profit.
Think of this equivalent with consoles, with the second generation playstation there were hardware add-ons available...but they were useless unless the games used them. You had 3 options as a game developer, package it with your product - driving the price up, assume they have it - smaller audience, or assume they don't - maximum audience, maximum profit. The result is the hardware never really sold much because as a game developer you had to assume they didn't have it.
For me, that equates that to Java vs Flash, if I have to install it, the price for me accessing it goes up...assuming they have the most common thing and you're safe, minimum cost of entry, maximum audience.
However, if you have a great game, I could be convinced to install :)
Flash typically performs better at the kind of drawing, animation and video features that games require, since that's what it was originally designed for. In addition, the strict-OO nature of the Java language does not lend itself well to the kind of ad-hoc rapid development environment that is common for games.
More importantly from an author's point of views, Flash is by far the more commonly-deployed browser plugin. Java just doesn't have the penetration on the desktop. Applets were historically despised for their instability and poor performance (particularly slow startup); whilst that has improved somewhat, Sun are continuing to undermine what user acceptance they have left with their obnoxious bundling updater. It is a brave company that develops anything much for desktop Java these days.
should I consider learning ActionScript and games development for the ActionScript Virtual Machine
It's definitely worth learning JavaScript/ActionScript. (They're almost the same language, sharing a standardised common core.) Then you can apply your Flash scripting knowledge to browser scripting. You can even consider implementing games in JavaScript/HTML itself!
AS3 looks very much like Java...
In as much as it's a C-like-language, yes. However the concepts and practice are very different; you'll have difficulty if you try to write JS/AS like Java.
A lot of flash developers are designers who have crossed over into making games. They used flash as a design tool before a programming tool.
Plus it seems to be something of a precedent now for online games to be written in flash so I guess people do not want to deviate from "the norm"
Future Flash CS5 could creates iPhone applications directly, so you'll be creating games for 2 platform at the same time.

Why do we need JavaFX though we have Swing?

Swing is good in many ways, then why do we need JavaFX?
There is both a technology part of JavaFX that will help design UIs, and a language part that will make writing UIs easier.
The JavaFX technology brings a 2d scenegraph and video capabilities. Afaik these will also be made available generally to java. They are good advancements for creating client side application with fancy and interactive graphical UIs. The 2d scenegraph should make it possible to create more graphic heavy applications that are still responsive.
The JavaFX language is a much better way off creating UIs programatically. Java Swing code can get very verbose, while the same JavaFX code will be smaller and easier to maintain. Closure support makes creating event handlers easier. Declerative assignment of settings makes configuration of elements easier. Native list syntax makes adding components easier.
Please note that I haven't really written any JavaFX, but I have read code and paid attention to what's going on. I recommend trying it yourself to find out what's cooking.
I think Staale's answer is a good start but I would add...
Use JavaFX if
1) If you're interested in developing the application for mobile or TV (note this has yet to be released)
2) If you're working with a graphic designer who is creating the appearance of the application in photoshop and you want to be able to import their look directly.
3) If making the GUI filthy rich is important to you. (so if you want a panel to fade in or out, or slide upon demand)
Use Swing if
1) You're creating an application mainly for the desktop.
2) Performance matters and you know what you are doing (so if you're writing an IDE, Swing would be a better choice)
3) You're looking for a RPC (rich client platform) to build upon.
It is the same reason why we have Java, C++, C#, Python, Perl, Ruby... although we already have C.

Categories

Resources