'분류 전체보기'에 해당되는 글 243건
- 2008.08.19 :: FoucsListener 구현하기
- 2008.08.18 :: js 한글+ eng 합계 글자
- 2008.08.15 :: 자바 날짜 형식
FocusListener 구현 및 실행단계
- Class Name 다음에 implements FocusListener를 선언해 주었다.
- 아래와 같은2개의 메소드를 정의해준다.
- public void focusGained(FocusEvent e){}
public void focusLost(FocusEvent e){} - Focus Event를 발생시켜줄 Component에 addFocusListener(this);을달아준다.
- 예)ui.jLabel2.addFocusListener(this);
- 포커스를 점유할때 발생하는 Event처리는 focusGained, 포커스가 떠날때 발생하는 Event처리는 focusLost메소드에 각각 정의해 준다.
- 아래 예제는 jLabel2에 포커스가 왔을대 sumSu(iCount); 메소드를 호출하는 로직을 구현한것이다.
public void focusGained(FocusEvent e){
int iCount = 0;
//Event를 발생시킨 Component를 찾아 getEvent에 담는다.
Object getEvent = e.getSource();
//getEvent와 ActionEvent가 발생할수 있는 Component를 비교하여 Event를 발생시킨 Component를 찾아내고
//Action 처리를 해준다.
if(getEvent.equals(ui.jLabel2)) {
iCount = Integer.parseInt(ui.jTextField1.getText());
sumSu(iCount);
}
}
private void addEvent() {
ui.jLabel2.addFocusListener(this);
}
어디서 퍼왔는지는 가물 가물
개인 학습용이니 너무 욕하지는 마세요~
<html>
<head>
<script language="javascript">
function textCounter(theField,maxChars)
{
var strCharCounter = 0;
var intLength = theField.value.length;
if((event.keyCode == '37') || (event.keyCode == '39') || (event.keyCode == '8'))
{
return ;
}
for (var i = 0; i < intLength; i++)
{
var charCode = theField.value.charCodeAt(i);
//한글일 경우
if (charCode > 128)
{
strCharCounter += 2;
}
else
{
strCharCounter++;
}
if(strCharCounter >= (maxChars)+1)
{
eval("alert('한글" + maxChars/2 + ", 영문" + maxChars+ "자 제한입니다. 초과된 문자는 잘립니다.')");
//theField.value = "";
theField.value = theField.value.substring(0,intLength-1)
return;
}
}
}
function textCounter2()
{
//document.a.tel.value = document.a.tel.value.substring(0,5);
var maxChars =10;
var strCharCounter = 0;
var intLength = document.a.tel.value.length;
for (var i = 0; i < intLength; i++)
{
var charCode = document.a.tel.value.charCodeAt(i);
//한글일 경우
if (charCode > 128)
{
strCharCounter += 2;
}
else
{
strCharCounter++;
}
if(strCharCounter >= (maxChars)+1)
{
eval("alert('한글" + maxChars/2 + ", 영문" + maxChars+ "자 제한입니다.맞게 입력하세요.')");
return;
}
}
}
</script>
</head>
<form name="a">
<body>
전번 입력: <input type="text" size =20 name="tel" onkeyup="textCounter(this,10);">
<br>
저장 : <input type="button" value="save" onClick="textCounter2();">
</form>
</body>
</html>
class OutDate
{
public static void main(String[] args)
{
java.util.Date setValue = new java.util.Date();
String strSetValue;
System.out.println("[Date -> String]");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.text.SimpleDateFormat ymd = new java.text.SimpleDateFormat("yyyy-MM-dd");
strSetValue = sdf.format(setValue);
System.out.println(strSetValue);
strSetValue = ymd.format(setValue);
System.out.println(strSetValue);
}
}
/*
[Date -> String]
Date setValue = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
strSetValue = sdf.format(setValue);
[String-> Date]
String value = "2008-01-30";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Date tmp = df.parse(value);
[어제 날짜 얻기]
Calendar calendar1 = new GregorianCalendar();
calendar1.add(Calendar.DATE, -1);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String defaultStartRegDate = sdf.format(calendar1.getTime());
*/