Graphics, AWT, Swing II part
MouseEvent e;
if ((e.getModifiers() & e.BUTTON1_MASK) != 0)
{ // code for left button click }
and just so you know,
InputEvent.BUTTON2_MASK is the middle or scroller button
InputEvent.BUTTON3_MASK is the right button in windows
by MSW
Q: How do I count the width in pixels of the text before drawing them into
graphics?
I have the Font and the String and I am using them in an applet:
graphics.setFont(font);
graphics.drawString(str);
How do I count the width in pixels of the text before drawing them into graphics?
Answer: import java.awt.*;
Toolkit tk = java.awt.Toolkit.getDefaultToolkit();
FontMetrics fm = tk.getFontMetrics(new Font("Arial", Font.PLAIN, 10));
int width = fm.stringWidth("Your String");
Jarkko
Q: If I do (CustomFrame extends Frame) smth. like this:
Frame newFrame = new CustomFrame();
what are the advantages of doing this over:
CustomFrame newFrame = new CustomFrame();
Answer:
There is one difference.
If the reference is a Frame type you can always downcast it, but not if it
is a CustomFrame type.
Might be nice sometimes.
Soren Disky Reinke
Q: I want to know what is the difference between JScrollPane and JScrollBar...is
both same or not..?
Answer: No. A JScrollPane is a container for components which can grow larger than
the visible area that can be displayed (i.e., a JTable or a JTree, for example). When
you place a component like these into a JScrollPane then the visible area is
displayed and appropriate scrollbars presented to allow scrolling to non visible
areas.
file:///F|/a_jsite/350_tips/graphics II.htm (2 of 5) [2001 07 08 11:24:55]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved