Posted by ±è´öÅ on November 25, 1997 at 03:06:46:
In Reply to: Ű À̺¥Æ® ó¸®... (½Ç¼ö.. ´Ù½Ã ¿Ã¸®±â) posted by ±è´öÅ on November 25, 1997 at 02:14:54:
´ÙÀ½Àº ÀÌÀü¿¡ ¿Ã¸° ¹æ¹ýÀ» »ç¿ëÇÏ¿©
ÀԷ±⸦ ¸¸µéÁö ¾Ê°í TextField¸¦ »ç¿ëÇÏ¿©
ÀÓÀÇÀÇ ÄÄÆ÷³ÍÆ®¿¡¼ ÇѱÛÀ» ÀԷ¹޴ ¿¹Á¦ ÇÁ·Î±×·¥ÀÔ´Ï´Ù..
ÀÌ·¯ÇÑ ¹æ¹ýÀ» ÀÀ¿ëÇÏ¸é ½ºÀ® ÄÄÆ÷³ÍÆ®¿¡¼µµ
°£´ÜÇÏ°Ô ÇѱÛÀ» ÀԷ¹޵µ·Ï ÇÒ ¼ö ÀÖÀ» °ÍÀÔ´Ï´Ù.
import java.awt.*;
import java.awt.event.*;
class KeyEventTest3
{
public static void main(String[] args)
{
KeyEventTest3 tester = new KeyEventTest3();
Frame f = new Frame();
f.add( tester.display, "Center" );
f.add( tester.input, "West" );
f.setSize(300, 300);
f.setVisible(true);
}
int posX = 0, posY = 0; // Ãâ·Â À§Ä¡
String inputString = ""; // Ãâ·Â ¹®ÀÚ¿
TextField input = new TextField()
{ // TextField°¡ Ãâ·ÂµÇÁö ¾Êµµ·Ï Å©±â¸¦ 0À¸·Î ¸¸µç´Ù.
public Dimension getPreferredSize()
{ return new Dimension(0,0);
}
};
Canvas display = new Canvas()
{
public void paint(Graphics g)
{ g.drawString( inputString, posX, posY );
}
};
KeyEventTest3()
{
display.addMouseListener( ml );
display.addFocusListener( fl );
input.addKeyListener( kl );
}
MouseListener ml = new MouseAdapter()
{ public void mousePressed(MouseEvent ev)
{ inputString = "";
posX = ev.getX();
posY = ev.getY();
input.requestFocus(); // Æ÷Ä¿½º¸¦ TextField·Î Àü¼Û
}
};
FocusListener fl = new FocusAdapter()
{ public void focusGained(FocusEvent ev)
{ input.requestFocus(); // Æ÷Ä¿½º¸¦ TextField·Î Àü¼Û
}
};
KeyListener kl = new KeyAdapter()
{ public void keyTyped(KeyEvent ev)
{ inputString += ev.getKeyChar();
// ³×ÀÌÆ¼ºê ÀԷ±â·ÎºÎÅÍÀÇ ÇѱÛÀÌ Àü´ÞµÈ´Ù.
display.repaint();
}
};
}