Porting AWT graphics code to Android - java

We would like to use some of our existing Java AWT graphics code on the Android platform. As far as I can tell, Android does not include any of the AWT classes -- no Graphics2D, Path2D, FontMetrics, etc.
What is the best approach to port our drawing code to Android? Ideally, we would like to modify our code base to target both Android and generic Java.

The android platform supports a small subset of awt. By small, I mean it supports awt fonts. Going from java swing (are you really just using awt as a standalone UI?) to Android is going to be a shock to the system. One defines Android's UI in XML resource files, and those resources are loaded into Activity classes which represents a logical unit of the application. Canvas' replace Graphics2D objects, and they have somewhat different functionality.The Android UI system seeks to avoid absolute positioning, which is common in java UI's. And there is so much more to consider for Android, like varying screen sizes and differences in resolution. Neither of which were much of a issue for Java SE. To answer your question: you have your work cut out for you and you will have to start much of your coding from scratch.
I'm not sure what 'drawing code' means, but in my case, I have a large amount of animation code that is displayed via awt shapes. This is reproducable on android as there are graphics.drawable.shapes objects, and one can display primitive shapes by doing something like canvas.drawCircle(x,y,z,h) (remind you of something?). But when I ported it, it was difficulty and felt like I was cortorting the android to do something it really didn't want to, and wasn't intended to do. It's hard to answer your question exactly given the vagueness of it.

I don't think you can port AWT to Android. I mean, it's Java SE vs a subset of it (or an updated Java ME with steroids, as you prefer).
There are though, some UI classes for Java ME that work perfectly on Android. Personally I like LWUIT but it's not the only one.

appengine-awt is a pure java implementation of the java.awt and javax.imageio packages for use in the Google AppEngine environment.
https://github.com/witwall/appengine-awt
SwingWT is a 100% pure Java library which aims to be a free implementation of Swing and AWT. Unlike Swing, it drives native peer widgets for your platform from SWT.
https://github.com/witwall/SwingWT

Related

JOGL or LWJGL pre-existing project

I've noticed that using the Java libraries that are default built in, rendering the simplest graphics absolutely kills the FPS, and furthermore, looks ugly.
Now I was wondering if I could use JOGL or LWJGL libraries to use in my pre-existing program. (I'm making a game which renders cubes as planets, and you have to build planets.) Do I need to completely rewrite my code? Or can I just install these and render freely? And which one of the above is easier to understand, because I have limited knowledge in these libraries.
Btw, right now, I am using JFrames, does that need to go as well?
Also, what is OpenGL, is that good to use as well without rewriting code?
OpenGL is a standardized graphics interface for use between programs and your graphics card. A proprietary version of this by Microsoft is known as DirectX. LWJGL and JOGL are two different Java bindings to OpenGL libraries, both of which have native code they load in.
LWJGL is much more aimed towards gaming with OpenGL, where as JOGL is more worried about complete and perfect bindings to OpenGL/OpenCL. I would recommend LWJGL if you're just getting started.
You're going to have to rewrite your rendering code, yes. But assuming you designed your project well, you shouldn't need to rewrite the game logic. JFrames will probably also have to go, but I'm not completely sure about that.
Please don't turn this question into another "JOGL vs LWJGL" thread. Moreover, JOGL is used in several games including Poxnora and Salem (MMO). You'll have to learn OpenGL if you want to use any Java binding of this API anyway.
Finally, you can use GLG2D in order to get a better hardware acceleration with plain Swing, it would allow you to benefit of better performance only with a very few changes in your program. GLG2D relies on JOGL 2, you can find more information about it here: http://brandonborkholder.github.io/glg2d/

Designing a UI for Programmers to Use

I am doing UI design for a group of programmers who are working on building music-related software. I have created .psd files for all of the mockups, graphics, etc.
I was assuming they just needed the (many) images to put into the code, but they want me to use a GUI to spit out the necessary code. (I looked at Antetype, but it just seems so basic compared to my Photoshop mockups.)
My question: Is there a GUI tool that can build VERY UNIQUE designs, and can export the mockups in code using MatLab or Java? -- Or should I just say no and give them the images to use in the code. (we are talking guitar-pedal knobs, EQ sliders, etc.)
Netbeans has a decent swing WYSIWYG editor for Java GUIs that's certainly worth looking into. There's going to be some significant back-end work getting your graphics to look just right if you have particular/complex designs in mind, but that said customizing Java GUI's is much easier than MATLAB. . . I believe eclipse also has plug ins available for this same sort of thing.
Anyways, that is probably the closest you'll get to a nice drag-n-drop interface in Java for GUI design.
JFace is also a pretty spectacular framework that sits atop SWT for building Java GUI's. I would say that it's power lies in how it handles different windows/components, but of course the trade off is that it's more complicated to put together (no WYSIWYG that I know of)
Also consider the Microsoft route, Visual Studio is designed to take the pain out of layout designs in writing Visual Basic/C#/.net applications. If you're a student your university probably has a deal to get you a free copy (mine did) otherwise visual studio express should be free (I think? ...citation needed?)
To create a UI you can use some tools, Netbeans in first .. but i think that is better to create a consistent code using simple layout and component, so doing it by hand (Oracle interesting tutorials). If you aren't a java programmer i suggest you can simply give them your image.

Displaying audio signals

We are trying to display the input audio signals already recorded form an electric guitar, using a variety of amplifiers. We are looking for an algorithm to display with Java.
We are currently looking at AWT and Swing libraries and are wondering: which would be better suited to graphic or visually displaying this?
Use Swing rather than AWT for this. Either is capable of doing it, but Swing is more modern and supports components (JTree, JTable..) and functionality (double-buffering built-in, key bindings, PLAFs, support for rich text) that is missing from the AWT APIs.
Another advantage of using Swing is that it seems you are at a stage where you need to ask further questions. Most people who program GUIs using Java SE have never used AWT components, and the rest of us have mostly forgotten how! (There are also many more people who can help with Swing than JavaFX, at this point.)
In AWT you might use a Canvas for drawing the waveform, but in Swing you would use either of the following:
A JPanel (or sometimes a JComponent) where to paint we override paintComponent(Graphics)
A BufferedImage display in a JLabel.
You can see examples of the first technique at DrewTubeish - here is Leftover Wine.
Would you be allowed to use JavaFx? Reason I ask is JavaFx 2.0 has some excellent api's designed specifically for this sort of multimedia task. This is doable with swing or awt for sure but why not be kind to yourself? I don't have time or space to go deeply into it here but I'd recommend either 'Introduction to Javafx 2.0 by Example' or 'Pro JavaFx 2.0' both by Apress. I'd say the second is better, more comprehensive. I believe both have sample code that does pretty much what you just described.
Good luck!!
JFreeChart includes a variety of suitable charts; there's a time domain example here. This KineticModel extends JLabel and implements Icon to display a frequency domain Histogram. Neither requires Swing, but either works better in a Swing context.
I've used AWT, Swing and JavaFX for major projects in Audio, including waveform drawing and editing. Here are my thoughts:
AWT is not being developed or taught. I don't know of any developers who still work with it. I would not use it.
JavaFX is a disaster. Back in 2010 I was working on the largest JavaFX codebase around, and we dropped it for swing. I'm sure it's gotten better, but I haven't yet heard anyone say it can handle major projects. If your project is small, JavaFX may be a good choice, or if you feel strongly, you may want to do further research. You can read more about my experience here: http://blog.bjornroche.com/2010/03/java-nofx-why-one-project-dropped.html
Swing has problems, and deserves much of the criticism it receives, but if you know what you are doing it can be awesome. I have developed some kick-ass UI's with it (they looked EXACTLY like the designs). Swing is written on top of AWT, which you would think would make it slower, but there are a lot of optimizations that actually make it very fast on most platforms. If I understand correctly, CodenameOne uses a swing-like interface, so in my book, that's another vote for swing: http://www.codenameone.com/
SWT is another option. http://www.eclipse.org/swt/ I have never used it, but I understand you have to do your own memory management with that, which, IMO, takes away a lot of the advantages of using Java. Like I said, though, I've never used it so I could be wrong. It is the native toolkit of Eclipse.

Differences between Java applet and application graphic capabilities

Is there anything, talking about graphic capabilities, that a Java application can do, while an applet cannot?
I'm referring to java libraries (like Swing), not to native ones.
edit: I need to create a user interface for graph visualization, probably using the spring embedder algorithm
Initial downloading times are not so important, now I'm focusing mainly on what 2D graphic capabilities using Swing that one application has that an applet hasn't
I think that my graphic interface should look like Visual Thesaurus
There is nothing regarding graphic capabilities a Java application can do an applet can't.
Unsigned applets have some restrictions, while signed applets can do anything a Java application can.
Read: http://download.oracle.com/javase/tutorial/deployment/applet/security.html
If you are thinking of using JOGL for 3D graphics, read about unsigned applets in http://download.java.net/media/jogl/builds/archive/jsr-231-1.1.0/jogl-1.1.0-windows-i586/Userguide.html
When you are using an applet, without jumping through major hoops, you won't be able to get access to the lower graphic levels, so you won't be able to use the OpenGL binding libries, such as jogl, which could be a major issue, depending on what you are trying to do.
You will also experience significant download penalties if you use something like Java3D in the applet.
What are you looking at trying to do, that would lead to this question?
Some context would help in you getting better answers.
A Java applet basically uses Swing so the simple answer is; no, not really.
However, if you are writing a Java application (non-applet) you may utilize other GUI libraries than Swing (such as SWT), so in that regard a Java application has greater choices and (potentially) capabilities.

What to use for writing a user interface?

I've written a series of classes to interperet data from a serial port. This data needs to be displayed on the screen. I am trying to go for straight up eye candy with a refined look.
Swing UI- Easy to program, yields mediocre results
Open GL- Hard to program, yields good results.
Are there any other options?
Give SWT a go, the API is a lot simpler than Swing. Here is a recent question outlining the differences between SWT and Swing.
I'm not aware of any alternatives, but in my opinion it is possible to write beautiful GUI with Swing. Just changing the ugly default look and feel goes a long way. Visual appeal just doesn't seem to be a top priority for most Java coders and therefore you have to make an effort to make anything pretty.
JavaFX maybe? Didn't tried it yet, it obviously offers some eye candy.
You can use NetBeans combined with JOGL (Java bindings for OpenGL) or simply with Java2D.
NetBeans has an easy GUI Builder for Swing applications -- you can make beautiful interfaces (if you get into it), easily change the Look&Feel, etc etc.., and you can use Java2D or JOGL for visualizing your data and embed it in the GUI to display it.
There's a plugin for JOGL for NetBeans so getting started is hassle free.
use html, css, javascript. Much easier to get wizz-bang UI than using Swing or related technologies.
For my projects at work, we have purchased a licence of JFormDesigner.
This is really a great tool that saved us a lot of time.
Writing Swing application by hand can be a real pain and is awful to maintain.
This tool choose the right approach : The model-view-controller.
The GUI builder creates XML files for you that represent the interface. These XML files are loaded at runtime and transformed into Swing objects. The builder also generates Java stubs that you can fill with event handlers.
It also handles Localization and nice layout goodies.
Give it a try.

Categories