[ÇØ°á] JDK1.1·Î ¸¸µé¾îÁø ÅøÆÁ¿¹Á¦ÀÔ´Ï´Ù.


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :ÃÖÁöÈÆ 1998³â 6¿ù 25ÀÏ 09:57:08

In Reply to: [Áú¹®] toop tip À» ±¸ÇöÇϽźРÀÖ½À´Ï±î? posted by ÃÖÁöÈÆ on 1998³â 6¿ù 23ÀÏ 13:16:19:

JDK1.1·Î ¸¸µé¾îÁø Åø¸³¿¹Á¦ ÀÔ´Ï´Ù.
±×·¸Áö¸¸, ¹®Á¦°¡ ¸¹½À´Ï´Ù. °ü½ÉÀÖ´Â ºÐµéÀÌ Á» ¼öÁ¤ÇØÁÖ¼¼¿ä.


1) °¡²û¾¿ À߸øµÈ ¿¬»êÀÌ ¶å´Ï´Ù. ToolTipÀÌ »ý¼ºµÇ´Â ÇÁ·Î¼¼½º
µµÁß¿¡ ¹º°¡ À߸øÀÌ ÀÖ´Â °Í °°½À´Ï´Ù.
2) Applet¿¡´Â ¾µ ¼ö ¾ø½À´Ï´Ù.
3) µü Çѹø, ½ÇÇàÇÏ´Â °úÁ¤¿¡¼­ ÄÄÇ»ÅÍ°¡ Á×¾î¹ö·È½À´Ï´Ù.



import java.awt.*;
import java.awt.event.*;


public class TestFrame extends Frame {
Button b1 = new Button("I am a boy");
Button b2 = new Button("You are a girl");


Timer timer;
Point p;
ToolTip tooltip;


TestFrame() {
super();
setLayout(new FlowLayout());
add(b1); add(b2);
b1.addMouseListener(new ToolTipEvent());
b2.addMouseListener(new ToolTipEvent());
pack();
show();
}


Point translateCoordinate(Component c, int x, int y) {
return new Point(x-this.getLocation().x-c.getBounds().x,
y-this.getLocation().y-c.getBounds().y);
}


class ToolTipEvent extends MouseAdapter {
public void mouseEntered(MouseEvent e) {
Button b = (Button) e.getSource();
Point p = translateCoordinate(b, e.getX(), e.getY());
tooltip = new ToolTip(TestFrame.this, b.getLabel());
timer = new Timer(8000);
timer.addActionListener(tooltip);
tooltip.setBounds(p.x, p.y,
tooltip.getPreferredSize().width, tooltip.getPreferredSize().height);
tooltip.setVisible(true);
}


public void mouseExited(MouseEvent e) {
if(tooltip != null) {
tooltip.setVisible(false);
tooltip.dispose();
tooltip = null;
}


if(timer != null) {
timer.stop();
timer = null;
}
}
}


class Timer extends Thread {
long n;
long currentTime;
ActionListener listener;


Timer(long n) {
this.n = n;
this.start();
}


public void addActionListener(ActionListener l) {
listener = AWTEventMulticaster.add(listener, l);
}


public void run() {
this.currentTime = System.currentTimeMillis();
while(true) {
long nextTime = System.currentTimeMillis();
if(nextTime - currentTime >= n) {
listener.actionPerformed(new ActionEvent(this,
ActionEvent.ACTION_PERFORMED, ""));
break;
}
}
}
}


class ToolTip extends Window implements ActionListener {
String content;
ToolTip(Frame f, String content) {
super(f);
this.content = content;
}


public Dimension getPreferredSize() {
Font f = getFont();
FontMetrics fm = getFontMetrics(f);
int w = fm.stringWidth(content) + 20;
int h = fm.getHeight() + 5;
return new Dimension(w, h);
}


public void paint(Graphics g) {
g.setColor(Color.yellow);
g.fillRect(0, 0, getSize().width-1, getSize().height-1);
Font f = getFont();
FontMetrics fm = getFontMetrics(f);
int x = 5;
int y = 15;
// int y = (getSize().width+fm.getHeight())/2;
g.setColor(Color.black);
g.drawString(content, x, y);
}


public void actionPerformed(ActionEvent e) {
if(this.isVisible()) {
setVisible(false);
this.dispose();
}


if(timer != null) {
timer.stop();
timer = null;
}
}
}


public static void main(String[] args) {
new TestFrame();
}
}






´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]