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.
Related
Are there any advantages to hand-coding your Java Swing GUI rather than using the Netbeans Drag n Drop editor? Maybe such as run-time? It seems to me that the Editor auto-creates quite a bit of extra code but I don't know if that has much impact on the runtime of loading the views. The only reason I'm currently using the editor is because it makes the GUI building quick and simple. But are there things you can do only by hand-coding that isn't possible through the editor?
Also is there a better GUI Framework? I've peeked at Java FX, but I really want the kind of effect that the Github desktop software has. It looks so slick and clean, almost like a webapp. Although I'm sure they did that in C++. It just seems to me like there isn't much for Java when it comes to graphics. One of my friends commented that all Java programs look the same and so far it seems true.
I know there are similar posts, but quite frankly they aren't very recent, such as Write gui programatically, or using an advanced gui editor (Java Swing)? which was posted in 2010 or Learning Java Swing (GUI builder or not?) which was also in 2010. If there's nothing new, sorry to bother you.
Are there any advantages to hand-coding your Java Swing GUI rather than using the Netbeans Drag n Drop editor?
There are lots, but lets start with the obvious...
Doesn't lock you into a single development environment. This means your code is sharable to others who may not be using Netbeans. This is of particular importantance when you are using things like Maven based projects
Encourages you to learn the API. You get a good understanding of how the API actually works and learn plenty of tricks to make fluent and flexible interfaces.
Encourages greater separation of respobsibilty. It's all to easy to simply keep dragging components onto a form, which does nothing for encapsulation or management. By dividing your UI into areas of responsibility it makes it easier to mange the distinct states and relations between your components. It also makes the code generally easier to read, as you don't need to keep discarding content which is not relevant to what you are trying to figure out.
Better extendability. Extending components is not easy at the best of times, but is made next to near impossible with form based components (or at least an order of magnitude more difficult)
Netbeans form editor code is...a mess...
Don't get me wrong, I use the form editor, but I've been hand coding Swing GUI's for ten years before I picked up the form editor. I like the form editor for laying out final screens and tend to use hand coded UIs for every step up to that point, putting the pegs in the hole so to speak.
The short answer is - until you can make a multi-level GUI by hand, stay away from the form designers - IMHO.
I know some people think they make great learning tools, I think the opposite, I think they allow you to develope lazy and bad habits which will affect everything you do into the future.
While the development enviroment shouldn't make a difference, not everyone will want to use Netbeans, best to learn to do without
Also is there a better GUI Framework?
That's rather a matter of opinion. Swing brings a concept of skinning through the use of the look and feel architecture, which provides you with the ability to change the way that components look and feel.
JavaFX provides similar functionality through the use of CSS
Swing is also highly customisable, it's very easy to get into the "paint" level of the components and even generate your own should you want to.
The ability to make a "slick" UI isn't about the toolkit but down to the developer. It's easy to just drop fields and other components onto a container, but it will take a developer with a good understanding of the underlying API and some talent for what actually looks good to make it look "slick".
Pretty doesn't always equal functional. The best UI's are ones you don't have to think about, that don't get in your way and just work. When you've been working with a program for hours, days, weeks, you're not going to be looking at how pretty the UI looks but how well it lets you get what you want done - IMHO
The #1 thing that hand-coding accomplishes that the GUI Builder cannot is: dynamically changing interfaces.
For example:
If you wanted to build a form that involves several JTextFields, but you aren't sure how many there will be when you build your GUI. The program will need to populate the JTextFields dynamically. This is impossible with a GUI Builder.
Also, when you have complex interfaces, the resizing behavior of GroupLayout can be cumbersome and confusing. On the flip side, hand-coded layouts are a lot of work when you are writing a complex interface (but, at least their resize behavior is predictable).
A classic GUI builder should be used for prototyping your GUI. Once you know exactly what you want, you should get rid of it and clean the code (factorize it, document it, ... in short make it simple & readable).
One of my friends commented that all Java programs look the same and so far it seems true.
Not absolutely true: JavaFX look is customizable through css. Swing is also fully customizable through the LAF system or by overriding the paint* methods (more time-consuming I admit).
If you look for something easy without the drawbacks of generated code I recommend you have a look at ReflectionUI: easy appearance customization (and that's not the only benefit):.
I am so-so with Swing and just starting to learn JavaFX. I went over a few answers on SO with regards to which one to use and I still can not make up my mind.
Is it possible to get the best of both the worlds ??
Like, use JavaFX with I want to give some visually appealing graphics and add some Swing to JavaFX when I want to ?
You can use JavaFX in Swing applications via the JFXPanel control. See the SwingInterOp sample. You can also utilize JavaFX from inside sophisticated Swing based platforms such as NetBeans RCP.
A current limitation of JavaFX/Swing integration is that you can embed JavaFX components in a Swing application, but not Swing components in a JavaFX application. RT-12100 Swing in JavaFX embedding support is currently scheduled for Java 8.
If you have a green field new application to develop, I'd advise choosing one technology or the other and sticking with that or at least keeping the integration points localized and few and far between. Both frameworks are large and take time to learn, plus you will avoid any integration headaches such as needing to take care that Swing processing is done on the Swing Event Dispatch thread and JavaFX processing is done on the JavaFX Application Thread.
JavaFX also integrates with SWT and that integration is currently simpler than the JavaFX/Swing integration (because there is only a single GUI thread to worry about).
Here is a screenshot of JavaFX/Swing interop sample from Oracle:
I went over a few answers on SO with regards to which one to use and I still can not make up my mind.
Rather than doing that, I'd advise picking a small application and implementing it from scratch in Swing and JavaFX and seeing which you prefer. It's time better spent as there is no substitute for hands on experience - then, if you still have questions (hopefully more specific and targeted), come back to StackOverflow to research or ask them.
It depends on your motivation for learning them. If you're looking primarily to boost your CV in the near future and become attractive to businesses, then (for the moment at least) there's many more applications out there written in Swing than JavaFX, purely because the latter is a much newer toolkit.
However, if you're thinking more long term or just want the best tool for the job, personally I find JavaFX to offer more flexibility, be much easier to code in an aesthetically pleasing way, and easier to learn as well (the API behind it is just much nicer.) The only thing against it at the moment is that there's some features that I'd really like to be included, but aren't yet (again, naturally this is what you get by going for the newer toolkit.)
I'd also advise against mixing the two. I'm currently involved in two projects using JavaFX, one entirely JavaFX based and the other a mixture of FX and swing. The latter is much more fiddly to maintain, primarily because of the difference in dispatch threading.
As a previous poster stated, you can use JavaFX in Swing applications now. But since Oracle has declared that JavaFX is the future of the desktop for Java, why not just learn it. I've tried to keep current on both and it's a chore. I'm planning on focusing on JavaFX exclusively in the future -- less chance of confusing myself.
That said, JavaFX still doesn't seem to be a full-fledged member of the JDK, especially if used in conjunction with other languages, like Clojure for example. Depending on the JavaFX version, there are different machinations to go through to pull it into build tools. But that situation is getting better with each release.
I have a relatively large program that I'm working on that's about half finished. So far, all I have used for graphics are things like JFrame, JPanel, and a myriad of JComponents. In the future, I will be painting really 2D or 3D images to the screen but for right now all I'm doing is the GUI and title/game screen. I just realized that there are two graphical categories called SWING and AWT and I looked at some AWT code and it looked quite a bit different than what I have been using.
What do you think, should I try to convert all of my code to AWT format or leave it the way it is?
Thank you for your time.
AWT is actually a bit deprecated native-dependant GUI. It has lots of problems (including performance) and doesn't really act well on all of the various platforms.
The best way is to use either Swing, JavaFX or SWT to create rich desktop applications on Java. Each of the has lots of pros and cons - it would take a year to tell about all of them. The best way is to watch some of the samples and demos and decide what is best for you.
I have already decided for myself that Swing is the best and most stable GUI platform for now. In your case either Swing or JavaFX might be the best due to lots of possible work with 2D/3D graphics.
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.
Are Swing applications really used nowadays? I don't find a place where they are used. Is it okay to skip the AWT and Swing package (I learned a bit of the basics though)?
If you are writing for the web exclusively, you can probably skip Swing, but otherwise you're absolutely going to run into it. I've never worked on a non-trivial Java app without a Swing GUI.
Also, Swing is one of the better APIs to use. If you use most others, you are going to find them more difficult to use and/or platform incompatible. (If anyone reading this is aware of exceptions to this, please leave comments, I haven't looked for a while and am kind of curious if anything better has become available)
Other JVM languages like JRuby and Jython are often used because of their access to Swing.
You may checkout Swing Sightings.
This website is hosted by SUN and it is dedicated to sw projects that use Swing.
There are a lot of projects using Swing ...
http://java.sun.com/products/jfc/tsc/sightings/
Swing is heavily used in business specific (vertical)/internal application development.
Hmmmm... how about NetBeans? You know, the IDE? It uses Swing.
Swing applications are used in most cases where a Java app runs on the desktop. Sometimes you don't even know - for example, LimeWire is a Java Swing application.
When learning Swing, you'll find that you will come to know those parts of AWT that are still important, such as Event, LayoutManager, Graphics, Font, Color, etc.
You should certainly write Swing for desktop Java, only using AWT to the degree that Swing demands it.
I'm sure people can come up with examples of very good Swing apps besides SQL Squirrel and IntelliJ.
I think that RIA technologies like Flex, Silverlight, etc. are ascendant because the web and services are taking mindshare from desktops. It's not just Swing that's losing out.
Whenever you want to write a desktop GUI app for non-Windows OS, you use Swing as the only sane and guaranteed cross-platform GUI framework.
Besides, Swing has a very good design. I recommend to learn it anyways, to make yourself a better programmer.
Check out Filthy Rich Clients. It explains some of the history of AWT and Swing. Swing, being a lightweight alternative (successor) to most of the AWT classes.
IIRC jEdit is also a Swing app. Quite a popular text editor.
Skip AWT and Swing? To jump where? SWT? Web-based development?
In the broader sense, I have a number of Java applications, although I am not too sure if they use Swing or SWT.
Lot of database tools like SQuirreL SQL Client are written in Java. I think SQuirrel uses stuff from Netbean, which is, of course, Swing based.
yEd is written in Java, probably Swing.
A number of P2P softwares are written in Java, including Frostwire (I see no trace of SWT there, but I can just miss it).
And this list is far from exhaustive!
Lol! I forgot to mention the software suite made by the company I work for! It is quite specialized, used by mobile phone companies to monitor health of their network nodes (superficially looks like a spreadsheet). Totally Swing based.
While Swing has some cross-platform look-and-feel deficiencies and it would be nice if it was updated to support generics, it is still well designed and quite usable. I have always been a fan of the sheer amount of customization offered. SWT is nice and is more native, but you give up some power and control with that as well. In addition, it seems simpler to use, which can be a plus, since Swing can be overly complex due to its flexibility.
Geertjan Wielenga often blogs about applications based on the NetBeans platform, and therefore Swing. The applications range across the board from rather small esoteric applications to very large, mission-critical systems (Boeing Aircraft comes to mind). Many of the enterprise-level applications that Geertjan misses are mentioned on Planet NetBeans. It seems like every few weeks there is an announcement or description of such a program.
As noted above, lots of tools use Swing including the IntelliJ IDEA IDE, a favorite. I'm surprised no one else mentioned it.
Sun also used to maintain a Swing Sightings web site, but it hasn't been updated in a few years.
Where I work, Swing is used in the presentation layer for a very large document management system. In my own development experience I've used Swing for desktop applications in the areas of image processing, device control (video, motors, etc.), math, statistics, and medical devices.
BTW, I agree about the slowness of file choosers. But there are lots of alternatives that will use the native file chooser. It can just be a bit jarring if the L&F's don't match up very well.
EDIT: Oh, and as others have mentioned, it's very easy to use Swing from other languages on the JVM. With Clojure, for example, it is even easier to use than in Java, in my opinion.
There is no universal question to whether it is ok to skip something or not. It's a matter of priorities. While Swing has a lot to teach you (and it is too heavily infused with AWT), if you're never going to be writing GUIs you may be better off investing in something else.
Swing, while ugly as hell, is still used in many places. A quick search on "java swing" in Indeed or dice would reveal many jobs and industries that require it.
Are you skipping it for an exam/interview? Besides really good apps like IntelliJ IDEA and NetBeans, there are lots of Swing like frameworks [SWT (Eclipse), GWT etc.] which you can learn faster with Swing knowledge...
You should probably be looking at JavaFX for future work. As the FAQ states,
Sun is not replacing Swing with JavaFX Script. Instead, JavaFX Script makes Swing easier to use.
Using/learning it will give you a very good understanding of the important Swing concepts, and how they fit in with "the future". I haven't used JavaFX yet, but heard very good things about it.
Armitage tool is made in swing , GUI tool of metasploit framework.