Seapegasus Blog

All | Hacks | Java Mobility | Mac | Misc | NetBeans | NetBeans_de
« Previous month (Oct 2006) | Main | Next month (Dec 2006) »
20061218 Monday December 18, 2006

Antwort Auf Eine NUG-München-Frage

(English version: Here is the Introduction to Developing Rich-Client (Swing) Applications training for NetBeans that people have been asking for.)

Jemand hat während dem letzten NetBeans User Group Treffen in München gefragt, ob es nicht ein Sun-Training for die NetBeans Platform gäbe. Eben habe ich nach einem Swing-Training gesucht, und habe Kurs WJO-1107 (Introduction to Developing Rich-Client (Swing) Applications) entdeckt. Es ist allerdings kein Kurs mit Lehrer, sondern ein kurzes webbasiertes Training, das man im Alleingang im Browser durchgeht.

Schwerpunkte sind das Swing API und wie man mit NetBeans Swing-GUIs macht, und drittens, wie man vorhandenen Code aus der NetBeans Platform für eigene GUI-Anwendungen (rich client applications) recycelt.

Wer Interesse hat: Auf Anfrage ist der Kurs auch beim deutschen und beim schweizer Sun Training buchbar, allerdings gibt es bisher nur die Englische Sprachfassung. (Ohne Untertitel) ;(

Posted by seapegasus ( Dec 18 2006, 11:29:19 AM CET ) Permalink


20061210 Sunday December 10, 2006

I'm Gonna Switch Back to Grayscales

Everytime I compile and run on MacOS X, I get this line of warning in the NetBeans Output window:

2006-12-10 13:01:15.550 java[294] CFLog (0): CFMessagePort: bootstrap_register(): 
  failed 1103 (0x44f), port = 0x10a03, name = 'java.ServiceProvider'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2006-12-10 13:01:15.550 java[294] CFLog (99): CFMessagePortCreateLocal(): 
  failed to name Mach port (java.ServiceProvider)

Nothing crashes or breaks though. What does it want me to do about it? I even looked up what 1103 means, BOOTSTRAP_SERVICE_ACTIVE, thaaanks, very useful.

In case you notice the same, googl-- uh searching digs up two thread replies ([1], [2]) explaining that it warns that more than one process tried to register Services with the same process name "java" -- I assume one is the running IDE and one the app that I compile and run? Or are we talking about the "Services" submenu in the Application menu?

Whatever, the basic answer to this question seems to be: Ignore it! They say it's just an overzealous warning from Apple's side, and it doesn't interfere with the IDE's or any other app's execution. As you can see, the first quote above is even from an Eclipse forum from a Mac user with exactly the same problem, so we are in good company.

Oh well. But still... It's annoying because it's RED!! I don't like red warnings that go "Look out! Do something! Not! Just ignore me! And do it quick!!"

Posted by seapegasus ( Dec 10 2006, 01:24:46 PM CET ) Permalink Comments [1]


20061206 Wednesday December 06, 2006

Busy Week at NASA

This time it's water on Mars. I'm just watching a stream of NASA's Mars Reconnaissance Orbiter press conference that is associated with the article NASA Images Suggest Water Still Flows in Brief Spurts on Mars. Before-after pictures show a trickle of something liquid, they assume water mixed with sediments, that flew down a hill and froze. The question is, how did it turn liquid inside the planet long enough to flow before it froze again? (e.g. is the water acidic?) The NASA guys are excited, the journalists ask "So... is this the holy grail now or what?" and "So... did we get Mars geophysics all wrong?" Hehe. Poor NASA guys. Did somebody threaten to cancel their funding if they don't bring results this week?

Posted by seapegasus ( Dec 06 2006, 08:12:47 PM CET ) Permalink


20061205 Tuesday December 05, 2006

Moonbase!!

Haha! I was right! NASA did announce a moonbase Monday night! :-D I knew it first, I knew it first, haha! *stops jumping up and down, whistles innoncently, and gets back to work...*

Posted by seapegasus ( Dec 05 2006, 01:21:32 PM CET ) Permalink Comments [3]


20061204 Monday December 04, 2006

Taking Notes During Java Class (5)

Yes, I'm gonna post a whole week of class notes, and you can't stop me, muhahahaha! Where was I? Ah!

Serialization: This word at first didn't mean anything to me. Turns out it's the same thing as NSCoder in Cocoa, doh. If an object is serializable it simply means, the data can be written to a file (or any stream), and can be restored later as a Java object. You see how this is essential for storing user preferences or saved game states, etc. Object data is taken apart and the pieces are labled, and then stored as binary data. How is it used? To flag an object as a candidat for serialization, declare it as class MyObject implements Serializable { ... }. Elsewhere, you write your Object (and everything that comes with it) to a file like this:

ObjectOutputStream oo = new 
   ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("my_super_file.ser"))); 
oo.writeObject(myObj); 
oo.close();

(Use a path that works for you for "my_super_file.ser") To restore the serialized object to its fomer glory, you write:

ObjectInputStream oi = new 
   ObjectInputStream(new BufferedInputStream(new FileInputStream("my_super_file.ser")); 
MyObject myObj = (MyObject) oi.readObject( ); 
oi.close();

And swoosh it's back. (Unless you changed the object's instance variables' identifiers -- this will render your data unreadable.) By the way, the two functions used, readObject( ) and writeObject( ), are provided by the runtime for you. You can override them. If you think you can do better...

Threads á la grec: The teacher asked us what we thought a Java thread looked like. Hm. I always envisioned a thread as part of a plaited carpet...? Nope, his threading metaphor was ... different.

So, the application is the maze of Knossos, right? And Ariadne, who plays the role of the JVM, right?, sends in Theseus to complete a "job" (to kill the Minotaur). And to make sure that Theseus (who's is, like, one of the processes) gets the job done without getting lost AGAIN like all those other stupid processes before him, Ariadne (who's the JVM) ties one end of a ball of yarn to the entrance, and Theseus uses the thread to guide him in and out of the maze without missing any turns or steps. If the JVM pulls the thread and Theseus doesn't answer, the Minotaurus must have gotten him first, and it's time to call the Garbage Collector. (He, life on Knossos was rough those days! No fancy ambulances.) So basically threading is like the legend of the Minotaur, just with as many Theseuses as you want. DoEsN'T iT nOw aLL mAkE sEnsE To YoU?! Thought so.

Analysis and Design And some more things I realized while discussing this stuff with Uli:

Swing Unfortunately, Swing wasn't covered in the course. Well, the important thing is, if you need a window, it's called JFrame. If you need a dialog box (a window that is dependent on the main window and has no menubar of it own), it's a JDialog. I also discovered the difference between Pane and Panel: A JPanel is what you normally use to subdivide the JFrame into areas. A Pane is like a glass pane, a layer that is used in exotic cases, e.g. when you want to put two GUI elements (graphics, buttons) on top of each other. The difference between Container and Component however gives me a headache. Both are something abstract that I herewith officially ignore, as long as just buttons are buttons and frames are frames.

Please open the windows: And now... my totally most favorite command ever!

this.setVisible(true);

It opens a window (JFrame), finally! Do you know how long beginners search for a way to be actually able to pop up a window they just carefully crafted in Matisse, hm?! This is it! Use it as an action, in a button, or a menu. For example, create a new JDialog class and name it, say SettingsWindow.java, and pop it up when the settings menu item was accessed:

EditMenu.setText("Edit");
SettingsMenuItem.setLabel("Settings");
SettingsMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
                SettingsMenuItemActionPerformed(evt);
            }
        });
EditMenu.add(SettingsMenuItem);
MainMenuBar.add(EditMenu);

...

private void SettingsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
    SettingsWindow sw = new SettingsWindow(); 
    sw.setVisible(true);
}

Phew. That was my Java class. Well, of course I knew a bit of Java before, but this one was a professional class that actually covered all the topics. (as opposed to my notes, which do not cover all the topics, just things that I had wondered about for quite a while and that now make more sense.)

Posted by seapegasus ( Dec 04 2006, 11:12:46 PM CET ) Permalink


Taking Notes During Java Class (4)

Thursday's notes. (More notes from Monday, Tuesday, and Wednesday).

Commandline arguments = System Properties System Properties are variables you set from the command line:

java -Dmy.stuff.foo="my value" MyApp

in MyApp.java:

String input = System.getProperty("my.stuff.foo");

Or if it is a number, use the special static method for reading system properties, Integer.getInteger():

java -Dmy.stuff.foo="876" MyApp

in MyApp.java:

int input = Integer.getInteger("my.stuff.foo").intValue();

Abstract Class If you want to remind yourself to implement certain fields and methods in a bunch of related classes, create an abstract class to group the minimum set of attributes. (e.g. all zoo animals have name, age, race, and a location.) Subclass the actual classes from the abstract one and fill subclasses with individual settings. (e.g. a subclass for Fish where location is aquarium, and a subclass for birds with location birdcage.) Then you instanciate the subclasses (Fish dolphin and Bird flamingo). You never instanciate the abstract class.

Exception vs Error: The difference is that your program is not expected to recover from an error, but it is expected to recover from any exception. If you don't try and catch Exceptions, you will receive a friendly reminder from the compiler such as "Look here, you learning-resistant shallow parser, you know we all made this mistake before, so why don't you just frigging write code to prevent it this time?!?! Sheesh."

Catching Exceptions: In the try-catch block, catch exceptions from the most specific down to the most general one. Remember that the finally clause in a try-catch-finally block is always executed afterwards -- even if you call return in one of the other blocks.

Data Structures: The differences are resizability, whether they can contain only one datatype or different ones, whether items are ordered or not, whether they can contain duplicate objects, and especially varying speeds for certain operations.

I am glad to see that Java also supports an easy syntax to loop over array elements:

for( int elem : myArray){ System.out.println(elem); }

In NetBeans, type fore and a blank and the IDE will expand it to a for loop with colon syntax. Similarly, typing fori expands automatically to a "normal" for loop with a counter. Nifty!

Generics We also talked about generics, that's the mysterious syntax with the <angular brackets>. I didn't really get what this was all about. It seems a way of labelling a List (which is not restricted to any type) to certain types, that you know you will use exclusively, so the compiler can warn you in time when you put a wrong object in the List (which it normally wouldn't do because the List doesn't care about types). Also when you access an element and return it, it will automatically be cast to the type you chose earlier in angular brackets when defining the list. Hm. There is probably more to it, since it lets you use type wildcards, but, err, don't ask me... (Read this PDF if you need to learn about Generics.)

Posted by seapegasus ( Dec 04 2006, 09:12:49 PM CET ) Permalink Comments [1]


I Want A Moonbase (And Aliens)

Some years ago, I said "I want a space station", and NASA announced the ISS. I am confident it works with moon bases too. =)

What got me started thinking about moon bases was this: In secondlife, there's a Space Museum and a planetarium. On Sunday I decided it couldn't hurt to... indulge in some educational content, especially since they had announced some new Planetarium shows (written by astronomy students). When I arrived, one thing was already over while the next had not started yet, but at least one Avatar who seemed to be running this thing had time to give me a tour of the Planetarium: A short little show about the tale behind Andromeda and its neighboring constellations, well done, considering the limited means of this platform.

Later that day I checked back, and walked right into a meeting: A dozen avatars sitting around a planning table with a model in the middle, discussing, as I understood, how they wanted to terra-form the island to showcase Astronomy and space exploration. They even got some buy-in from NASA they said. Since they were looking for volunteer builders, I spontaneously joined them.

Among the proposals for what should be build on the island was also the item "lunar base". When I asked whether we should just improvise or whether we were building according to somebody's blueprints, one of the guys replied, the lunar base was of course to be built according to the plans that NASA would release "tomorrow at the Houston conference". The crowd answered "Oh cool" and the subject changed to something else. Houston conference? Tomorrow? Moon base?? Hmmm. I couldn't find anything online about NASA announcing plans for a moon base.

The only things about moon bases I found online were: One page about the Orion project that mentions a crew landing on the moon again before 2020; an edu page where NASA makes poor students solve their space habitat problems by disguising them as homework; then a Youtube or Google video about how NASA uses Photoshop's blur tool to erase all those alien moon bases from photographs before they are published; oh and a movie that says that the governments develop alien-based technology together which will make fuel redundant, but they cannot tell us because then oil stocks would drop, and people would panic because Aliens in UFOs watch us as cheap reality entertainment. Hmmm... Maybe chatting in second life or watching Youtube is not the most reliable source of real life information, when you think of it.

But in any case, At least the NASA rumor is easy to disprove or confirm: If NASA announces a lunar base today, I will post the link here. If you see no link here tomorrow, the Avatars were just kidding, and the moon base will exist only in secondlife. Easy solution. :-)

PS: the result!!

Posted by seapegasus ( Dec 04 2006, 11:36:32 AM CET ) Permalink


Calendar

Content

Search

Links

RSS Feeds

Recent...