Help coderanch get a
new server
by contributing to the fundraiser

Steve Lovelace

Ranch Hand
+ Follow
since Sep 03, 2003
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Steve Lovelace

Shouldn't GlyphVector report positions/bounds for glyphs which reflect kerning and ligatures, i.e., shouldn't it yield metrics which correspond to what is actually rendered by Graphics2D.drawString() or TextLayout.draw()? Below is a little app which will throw up a frame showing a string rendered in black, the GlyphVector's logicalBounds in yellow fill, and the logicalBounds of each glyph in red. You can see the bounding rectangles creep as kerns and ligatures are encountered. I had to pick a font that actually does kerning and ligatures (DejaVu Sans) because on my system (JDK1.6-u13 on Ubuntu 9.04) the default fonts do not. Attached is a screen shot of the frame produced.

15 years ago
The basic trick is to subclass JPanel (I'm assuming you're using Swing) and override the paintComponent() method. Your method will use java.awt.Graphics2D.draw(Shape) to render your polypolygon. You could put draw() in a loop and iterate over a collection of polygon edges (java.awt.geom.Line2D), or you could build a java.awt.geom.GeneralPath for each polygon, inner and outer, and then invoke draw() on each one.
20 years ago
You don't have to implement addRow() and removeRow() and very likely don't want to. The big problem is addRow(), which in DefaultTableModel requires either an Object array or a Vector as an argument. You don't have either one - you have a Test. So write methods to suit you, something like:
20 years ago
Here are a few possiblities:
(1) Invoke getValueAt(int row, int col) on your table to fetch the objects one at a time.
(2) Do something like:
DefaultTableModel m = (DefaultTableModel) myTable.getModel();
Vector v = m.getDataVector();
Vector v now contains one vector of objects for each row in your table.
(3) Build your own table model by subclassing AbstractTableModel. Have this table model store the data in a way that is convenient for you. You can then build your table with something like:
TableModel model = new MyTableModel();
JTable table = new JTable(model);
20 years ago
To wait, you simply do nothing, or rather, you invoke show() on your form and do nothing. Swing has control at this point (or at least that's an easy way to think about it). Swing waits for an event to be handed to it as the result of the user pressing something.
Suppose that the item pressed is a JButton which you have called "Next Test". Swing will cause this button to fire an ActionEvent. "firing" means that the button will broadcast the event to any listeners which have registered with this button for ActionEvents (ActionListeners). Each listener will have its actionPerformed() method invoked with the ActionEvent as an argument.
This is where you get control back. You must build an ActionListener with an actionPerformed() method which, in this case, shows a form with the next test. There are various ways to go about this. I would recommend going through the Swing thread of the Java Tutorial: tutorial.
By the way the particular Swing topic here is "event handling" and you will be learning to write event handlers. This may seem a bit intimidating at first, especially if you have not met up with anonymous classes yet, as this is the most natural way to build an event handler. But it's not really very hard.
Its also worth pointing out that there is a bit of a paradigm shift here. You are used to always having control of the program flow, but in Swing as in all GUI programming, you show the user something and then do nothing - invoking show() gave control back to the system. When something happens, the system will raise an event which causes one of your event handlers to get control. You then take appropriate action and, almost always, relinguish control again by invoking show() on something. This is the rhythm of GUI programming.
A-n-d one more thing: show() is a deprecated method - you're supposed to say setVisible(true). IMHO this is baloney - I use show() because its short and says what it is. So do what you like.
20 years ago
Looks like you'll have to do something like load your Tests/TestCases into lists (ArrayLists maybe) and provide the user with navigation controls: "Next Test", "Previous Test", etc.
It looks like your form only shows one step at a time, in which case you need navigation at that level: "Next Step", etc.
So you load the list(s) in your for loops, display the first test/step, and then wait patiently for the user to press something.
20 years ago
You can use either of these expressions:
selectedNode.getUserObject() instanceof TestCase
You do need to find this out before cast to TestCase.
[ April 07, 2004: Message edited by: Steve Lovelace ]
20 years ago
I'm not sure what you mean by a "JTextBox", but no matter. All the descendents of JTextComponent tell you about text changes in the same way: by notifying DocumentListeners registered with their contained Document. So what you want to do is create a DocumentListener and add it thusly:
20 years ago
"Need"??? The extension mechanism is so-o-o much cleaner than diddling around with the class path. I would also like to know why John had this problem. Does anybody know the answer?
20 years ago
Since all classes descend from Object, all abstract classes descend from a concrete class.
It's a little confusing to say that a nested class is quite different from an inner class - an inner class IS a nested class. As per the JLS, any class defined within another class is a nested class, and a top-level class is any class which is not nested. Note that this renders the term "top-level nested" an oxymoron.
Using "inner" to describe those classes which require an enclosing instance of their enclosing class seems to be the most natural and useful use of the term, but the JLS throws a curve here. The JLS has it that an inner class is any nested class which is not declared static. This turns out to be every nested class other than a static member class - a useless distinction.
Actually, the JLS says: "An inner class is a nested class which is not explicitly or implicitly declared static." (8.1.2). If local and anonymous classes declared in static contexts can be considered "implicitly declared static", then the term "inner" means what we would like: needs an enclosing instance.
But the JLS nixes this in 14.3 and 15.9.5, where it states (arbitrarily?) that anonymous and local classes are always inner. It's as if the JLS forgets that local and anonymous classes can be declared in static contexts, where they have no enclosing instance. I believe this is a JLS bug. If it just didn't say that anonymous and local classes are always inner, we could use the term "inner" where we need it - or maybe people are ignoring the JLS and doing this anyway, as in inner story.
Actually, I think this problem and much of the obscurity of nested classes would disappear if inner (JLS sense) classeswere allowed to have static members, but I suppose this is another topic.
[ April 02, 2004: Message edited by: Steve Lovelace ]
First, I believe the answer is 5, not -6.
To see how to do the inversion easily, picture what this number looks like in binary. It is:
11111111 11111111 11111111 11111010
Inverting means 1 becomes 0 and vice versa:
00000000 00000000 00000000 00000101
or 101 for short, which is to say 5.
The amount to shift is taken to be the modulus 32 (for int; 64 for long) of the argument, so x >> -3 is taken as x >> 29. By the same token, x >> 35 becomes x >> 3. And watch out for x >> 32; this is a no-op.
Interesting that the vm accomplishes this 'modulus' by simply masking off all but the low 5 bits (6 for long) of the argument, and that this works for negative as well as positive values.
[ November 19, 2003: Message edited by: Steve Lovelace ]
private methods cannot be overridden. In fact, outside of the class in which they are defined, they simply don't exist (and therefore can't be overridden) - even subclasses don't know about them.
Your anonymous class is a subclass. It's redeclaration of the private methods does not override them. Hence the behavior.
The variable containing your anonymous class is of type SomeObject. Looking at SomeObject, you can see that it only has one method defined: method1(). As far as any class using a 'SomeObject' is concerned, this is the only method it has.
While the anonymous class is a subclass with method2() defined, it has no visibility (outside of the expression in which it is created), i.e., there is no type exposing method2() for any other code to see.
You could do something like this: and "hello" will print, but there is no other point in the code, other than inside the anonymous class, where method2() can be seen.
[ November 19, 2003: Message edited by: Steve Lovelace ]