Well, I think I once tried to get input from the console or something.
I had to do something like create a Reader, and a BufferedReader, and LineReader, I had like 3 or 4 objects stacked on one another just to get some input.
OK, using it for commandline is a bit ugly compared to C++.. Probably because the keyboard input in the console is a Stream just like the Stream you have when you open a file and so on.
Currently, it's like this:
Code:
System.out.println("Enter smth"); // note that you can just type "syso" and use autocomplete magic in most IDEs
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String reply = br.readLine();
Not that bad, but a bit uncommon when you come from another language.
IIRC it handles GUI events by subclassing? So to make a button do something when you click it, you subclass it. Then to make a form, you subclass a JFrame and tell it to add buttons to itself.
You don't need to subclass. For example, adding a panel with some text in it can be done like this:
Code:
frame.add(new MyPanel());
[...]
public class MyPanel extends JPanel {
JLabel lbl = new JLabel();
public MyPanel() {
lbl.setText("bla");
this.add(lbl);
}
}
or you could just do this:
Code:
JPanel pnl = new JPanel();
pnl.add(new JLabel("bla"));
frame.add(pnl);
Some times, subclassing is the cleaner solution, for exaple if you want to reuse it (a panel that contains an image that is automatically stretched to its dimensions would be such a case), but most of the time, you don't bother with it. Personally, I just subclass the JFrame, but you most often only have one per app anyway (just for clarification, JFrame is a window, complete with window title bar etc, JPanel is just an area inside a Window)
For the button one, I never subclassed a button. You probably only have to do this if you want to style it youself or something. Usually, you do something like this:
Code:
JButton btn = new JButton("click me");
btn.addActionListener(new ActionListener() {
actionPerformed(Event e) { // note, this is out of memory, the function could be named differently
// handle click
}
});
Of course, you don't have to add an action listener using an anonymous inner class, you can also just implement the ActionListener for all buttons in your frame, panel or whereever you want to. (Java has two forms of subclassing - extending and implementing. Extending is used like it is in C++, but you can only extend from a single class. Implementing is just used with interfaces and you can implement as many classes as you like. This seems weird at first and I suck at explaining, but it actually does make sense.)
I could probably give it another shot, but I don't know why I would. Qt seems to work very well for similar tasks and has the advantage of C/C++ libraries such as GStreamer.
I never really liked Qt. It's not bad or anything, I just never really liked the whole signal/slot mechanism and I miss the TableLayout layout manager. But this may be just because I almost never use it and lack the familitary
You have many multimedia stuff included in the java library (java.media.*), more than enough for simple tasks (and more than C++ without Qt offers
). If you need something more powerful, you can always use other libs, like...
http://code.google.com/p/gstreamer-java/
If you really need it, you can also invoke native compiled code from java -
http://en.wikipedia.org/wiki/Java_Native_Interface (I never needed to, tough)
If I could get applets to work, that would be great, but my browser plugin kept caching them, so I couldn't reload the page to test an applet. And the appletviewer didn't work at all. I said to myself, "FFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUU-" and played video games instead.
Can't help you there, I never made an applet.
Sorry for the offtopic, I'm just kinda sick of all the java bashing