Friday, November 14, 2008

201 new GUI code

Short version of the below: new Skeleton later today.

I have been working on two things:

The first is a hybrid Skeleton that combines the use of the Swing/AWT palettes provided in NetBeans with drawing ops, called painting in Java, that I used in samples OneBlob and FloppyLine. (For those, I did use the NetBeans IDE, which was very convenient, but not the palette: all of my objects are explicitly drawn by my code, not by code auto-generated by NetBeans.) I probably won't finish this until late this afternoon. Looks like not everyone wants to do it:

This lesson describes custom painting in Swing. Many programs will get by just fine without writing their own painting code; they will simply use the standard GUI components that are already available in the Swing API. But if you need specific control over how your graphics are drawn, then this lesson is for you. (That's the lesson cited in OneBlob code.)

The second item, which Mr. VS and I discussed after class, is a way of painting in a JPanel that is an instance variable owned by a JFrame, with these created using a NetBeans JFrame program and the Swing palette tools. I don't think that this is going to work. From what I have seen so far, the panel needs to be in a class of its own so that it can extend JPanel. This is because the paintComponent method needs to be called for a JComponent, and JFrame is an awt.Component, not a JComponent.

However, the relationship can work in the other direction, with the top class being an extension of JPanel whose main( ) method creates a JFrame. And, for another variation, back to OneBlob, which class owns the main( ) method and the JFrame (in a second method), and a second class in the same file, an extension of JPanel, has the painComponent( ) method. Oops, I meant paintComponent( ), I think.

And Mr. F is working on a third plan using a Canvas object. More power to him!

You can always use the authors' StdDraw, too. That would save all of us a whole lot of cycles. What have we got against it?

This article tells more about painting with both AWT and Swing than I really wanted to know.

No comments: