Chant Dhames

Greenhorn
+ Follow
since Jun 22, 2002
Merit badge: grant badges
For More
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 Chant Dhames

Does anyone know how to fire an event for TreeSelectionListener without clicking anywhere inside the jtree? I have a button that, when pressed, selects the next entry in the jtree, and would like the TreeSelectionListener to follow suit and highlight the object when the button is pushed.
Thx.
21 years ago
Does anyone know how to fire an event for TreeSelectionListener without clicking anywhere inside the jtree? I have a button that, when pressed, selects the next entry in the jtree, and would like the TreeSelectionListener to follow suit and highlight the object when the button is pushed.
Thx.
21 years ago
actually, that didn't make any difference. I moved my Dimension down into paint right above the if() statement, and then moved my font declaration above the Font Metrics statement but the same problem exists. Any other suggestions?
21 years ago
thx. The Dimension is fine, or at least in my case it's fine and gives the correct width/height of my applet. I'll keep it in mind though and change it if it ever becomes a problem. thx for helping with the font problem.
21 years ago
I'm having trouble centering my text on an applet window. For whatever reason, I believe it's reporting the width incorrectly, whether I use stringWidth() or assign a bounding box to a 2d rectangle. If you run the code, you'll see what I'm talking about. Any help is appreciated.
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

public class Shapes extends JApplet implements Runnable
{
private Dimension wh;
Thread firstThread;
String sS;
FontMetrics fm;
int textWidth;
int textHeight;
int sleep;
Rectangle2D rect;

private Image backImage;
private Graphics backGraphics;
public void init()
{
wh = getSize();
sleep = 50;
sS = "SIM STUDIO";
}
public void paint(Graphics g)
{
if(backGraphics == null)
{
backImage = createImage(wh.width, wh.height);
backGraphics = backImage.getGraphics();
}

fm = g.getFontMetrics();
rect = fm.getStringBounds(sS, g);

backGraphics.setFont(new Font("SansSerif", Font.BOLD, 26));
textWidth = (wh.width - ((int) (rect.getWidth())))/2;
textHeight = (wh.height + fm.getAscent())/2;
backGraphics.setColor(Color.blue);
backGraphics.fillRect(0, 0, wh.width, wh.height);
backGraphics.setColor(Color.white);
backGraphics.drawString(sS, textWidth + 2, textHeight + 2);
backGraphics.setColor(Color.lightGray);
backGraphics.drawString(sS, textWidth, textHeight);

showStatus("font width is " + fm.stringWidth(sS) + "and" + ((int)
(rect.getWidth())) + " total width " + wh.width);
backGraphics.fillRect(300, 100, 5, 5);
g.drawImage(backImage, 0, 0, this);
}
public void destroy()
{
}
}
21 years ago
Well, I also posted the question on Suns website and received the following reply:
Arc2D.Double ar1;
Rectangle r;
ar1 = new Arc2D.Double(x,y,w,h,st,ex,Arc2D.OPEN);
r = ar1.getBounds2D().getBounds();
for (int x=0; x < r.width; x++)
for (int y=0; y < r.height; y++){if (ar1.intersects(r.x+x,r.y+y,1,1))
// this point is on the arc !!!
From a guy named Noah. I'm not too up on my Math so it'll probably take me a bit to figure this one out. Hopefully it's an easy explanation, i haven't looked up the method calls just yet. But anyway, enjoy!
21 years ago
thx. updated.
21 years ago
is it possible to draw an arc on an applet, and then have an object follow that arc by its x, y coordinates? basically, i'd like to drop a ball down the web page, and have it fall in a realistic curve, and thought that having it follow an arc would be the best solution, if possible.
21 years ago