´äº¯ °¨»çÇÕ´Ï´Ù. ±×¸®°í¿ä.


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

±Û¾´ÀÌ :odero 2000³â 3¿ù 23ÀÏ 16:35:06

In Reply to: FocusManager¸¦ »ç¿ëÇغ¸¼¼¿ä. posted by À±°æ±¸ on 2000³â 3¿ù 22ÀÏ 19:13:09:

FocusManager¸¦ »ý°¢ ¾ÈÇß´ø °ÍÀº ¾Æ´Ï¶ó µÚÀûµÚÀû °Å¸®¸é¼­ Çߴµ¥.. »ý°¢º¸´Ù ¸Å´ÏÁ®¸¦ ¾²±â°¡ Á¦°Õ Á» ¾î·Æ´õ¶ó±¸¿ä.
ÀÌ°ÍÀú°Í Çغ¸´Ù°¡..keyevent¿Í requestFocus()·Î ¿øÇÏ´Â °ÍÀº ÇØ°áÇß½À´Ï´Ù.
¾Æ·¡´Â ¼Ò½ºÀÔ´Ï´Ù.
/*
* Swing version
*/


import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.Dimension;


public class KeyEventDemo extends JApplet implements KeyListener,ActionListener {
JTextField typingArea2;
JTextField typingArea1;
JTextArea displayArea;
static final String newline = "\n";


public void init() {

JButton button = new JButton("Clear");
button.addActionListener(this);


typingArea1 = new JTextField(10);
typingArea1.addKeyListener(this);


typingArea2 = new JTextField(10);
typingArea2.addKeyListener(this);
displayArea = new JTextArea();
displayArea.setEditable(true);

JPanel contentPane = new JPanel();
JPanel content1 = new JPanel();
contentPane.setLayout(new BorderLayout());

content1.add(typingArea1);
content1.add(typingArea2);
content1.add(button);
contentPane.add(content1, BorderLayout.NORTH);
contentPane.add(displayArea, BorderLayout.CENTER);
typingArea1.requestFocus();
setContentPane(contentPane);
}



/** Handle the key pressed event from the text field. */
public void keyPressed(KeyEvent e) {
}


/** Handle the key released event from the text field. */
public void keyReleased(KeyEvent e) {
String text1 = typingArea1.getText();
String text2 = typingArea2.getText();

if(text1.length() == 4){
text1 = text1 + "/";
} else if ( text1.length() == 7 ) {
text1 = text1 + "/";
} else if(text1.length() ==10){
typingArea2.requestFocus();
}
if(text2.length() == 4){
text2 = text2 + "/";
}else if(text2.length()==7){
text2 = text2 + "/";
}else if(text2.length()==10){
displayArea.requestFocus();
displayInfo(e,text1,text2);
}
typingArea1.setText(text1);
typingArea2.setText(text2);
}


/** Handle the key typed event from the text field. */
public void keyTyped(KeyEvent e) {

}
/** Handle the button click. */
public void actionPerformed(ActionEvent e) {
//Clear the text components.
typingArea1.setText("");
typingArea2.setText("");
displayArea.setText("");


//Return the focus to the typing area.
typingArea1.requestFocus();
}


/*
* We have to jump through some hoops to avoid
* trying to print non-printing characters
* such as Shift. (Not only do they not print,
* but if you put them in a String, the characters
* afterward won't show up in the text area.)
*/
protected void displayInfo(KeyEvent e, String s1,String s2){
String charString, keyCodeString, modString, tmpString;


char c = e.getKeyChar();
int keyCode = e.getKeyCode();
int modifiers = e.getModifiers();


if (Character.isISOControl(c)) {
charString = "key character = "
+ "(an unprintable control character)";
} else {
charString = "key character = '"
+ c + "'";
}


keyCodeString = "key code = " + keyCode
+ " ("
+ KeyEvent.getKeyText(keyCode)
+ ")";


modString = "modifiers = " + modifiers;
tmpString = KeyEvent.getKeyModifiersText(modifiers);
if (tmpString.length() > 0) {
modString += " (" + tmpString + ")";
} else {
modString += " (no modifiers)";
}


displayArea.append("½ÃÀÛÀÏ:" +s1 + " " + "Á¾·áÀÏ:" +s2+ newline
+ " " + charString + newline
+ " " + keyCodeString + newline
+ " " + modString + newline);
}
}






´ÙÀ½ ±Ûµé:



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

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


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