This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!

Craig Wood

Ranch Hand
+ Follow
since Jan 14, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Craig Wood

8 years ago
8 years ago
9 years ago
I would try to get points closer together than the distance increment along the curve that you want for your animation. Then you can move along the curve and collect points that are close to your desired distance increment.
In the example here it looks like the parametric form is more amenable to this.
9 years ago
There are two fairly straightforward ways:
1 — use a FlatteningPathIterator with a suitably small flatness, say 0.01 to start, to get the coordinates along the curve. You can get a PathIterator from both the QuadCurve2D and CubicCurve2D classes.
2 — use the parametric form of the curve to get (x,y) for [0<= t <= 1.0]
These equations are given in the Field Detail section of the PathIterator interface for the SEG_QUADTO and SEG_CUBICTO fields.
9 years ago
I can think of two possibilities for this:
The basic idea is to use the Area class to make a highlighted border for your image.
Make an Area the size of the highlight rectangle size.
Substract an Area the size of the first/original image from it.
You can fill this area, now just a border, with your 0.5 alpha yellow color.
Then you can either:
1 — fill the area in the graphic component and draw your image centered in/above it, or
2 — make a new BufferedImage the size of the highlight rectangle size and the same type as your first/original image; make an area the size of the BufferedImage and subtract an area the size of the first/original image, fill the area in the new BufferedImage as above. Then draw the source/original image centered into the new BufferedImage. Draw this new BufferedImage in your graphic component.
The two areas will be initialized with rectangles that have different origins, the one in option 2 will be located at (0,0).
9 years ago
9 years ago
The components in each row are laid out in columns and their size determines the width of the columns. One way to work with this is to use a separate panel (to bridge across columns) for/in a row.
9 years ago
I would like to know what is the best Swing component to arrange and hold Icons in the GIF file format.
There are two general ways to show images:
1 – put the image in an ImageIcon and add it to a JLabel and add the JLabel to your container. This is easy and care–free; you let java do all the background work. You only have to deal with layout managers to get the layout you want.
2 – render/draw the image inside the overridden paintComponent method of an extension of JComponent or JPanel. Then you add this graphic component to your container. This can be fairly easy but allows much more room for creative display. One area that bears mention is the sizing of the graphic component. The parent layout manager will want to know its size which, since it contains no children, will be reported as either (0,0) or a default minimum, (10,10) for JPanel. So you provide a size hint in one of two ways:
1 — call the setPreferredSize method on the component
2 — override the getPreferredsize method to return the size you want; often the size of the image.

Depending on how you choose to load your images java will support gif, jpg and png files. ImageIO will load these plus, in j2se 1.5+, bmp and wbmp file extensions.

Would it be better to subclass the JComponent class and use a FlowLayout, or use JTextPane directly
JTextPane is generally for embedding components in text.
If you want a component, vis–a–vis graphic, approach try a JPanel with suitable layout manager (depending on what you want) and add JLabels with ImageIcons.

Some helpful resource links for more information:
How to Use Icons
Lesson: Working with Images
Lesson: Performing Custom Painting
9 years ago
9 years ago
9 years ago
Can I accomplish this at the Swing level,
Yes.
or do I have to resort to an AWT solution?
No.
Can the two live together?
Sometimes, yes.

If you want the cursor to show the copy_cursor inside/over the list you can return true from canImport and override importData to return false inside listHandler.
9 years ago
9 years ago
Use a scale value of "-1" to reflect about an axis.
9 years ago
not sure whether this method is suppose to take a matrix or if it's suppose to take a set of arbitrary points
AffineTransform contains the matrix and does the matrix math in the background. The transform method takes an arry of arbitrary points (in any space) and transforms them into the space defined by the AffineTransform.
9 years ago