2010년 7월 26일 월요일

Android에서 Timer 사용하기

스플래쉬 화면은 잠깐 표시되고
다음 화면으로 넘어가기 때문에
이것을 타이머를 사용해서 구현했다.

private Timer mTimer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

mTimer = new Timer();
mTimer.schedule(new TimerTask() {
@Override
public void run() {
TimerMethod(); // 지정된 시간에 실행할 메소드
}
}, 5000); // 밀리세컨드 단위로 딜레이될 시간
}

private void TimerMethod(){
Intent intent = new Intent(DhrActivity.this, LoginActivity.class);
startActivity(intent);
mTimer.cancel(); // 타이머를 취소하지 않으면 계속 실행이 된다.
finish(); // finish를 하지 않으면 뒤로가기 버튼을 누를 때 스플래쉬 화면으로 간다.
}

JavaScript에서 Target 지정하기

_top : top.location='주소';
_self : self.location.href='주소';
_parent : _parent.window.location='주소';

프레임을 사용했을 경우(프레임 파일에서)
document.frames['프레임명'].location='주소';
document.frames[숫자].location='주소';

프레임의 자식(프레임에 지정된 파일)에서는 parent를 붙인다.
parent.document.frames['프레임명'].location='주소';
parent.document.frames[숫자].location='주소';

2010년 7월 25일 일요일

JAVA에서 문자열을 숫자, 영문자, 한글로 구분하기

Pattern클래스는 첫 번째 파라미터인 패턴과
두 번째 파라미터인 문자열을 비교해
두 번째 문자열이 첫 번째 패턴과 일치하는 지를 알려준다.

숫자 한글자 : [0-9]
영소문자 한글자 : [a-z]
영대문자 한글자 : [A-Z]
유니코드 한글 한 글자 : [가-힣]

한글자가 아닌 문자열일 경우 *를 붙여준다.
숫자 : [0-9]*
영소문자 : [a-z]*
영대문자 : [A-Z]*
유니코드 한글 : [가-힣]*

자주 쓰이는 형식에 대해서 다음과 같은 축약형이 있다.
\d 하나의 숫자 : [0-9]
\D 하나의 숫자가 아닌 문자 : [^0-9]
\s 하나의 공백 문자 : [ \t\n\x0B\f\r]
\S 하나의 공백 문자 이외의 문자 :[^\s]
\w 하나의 영숫자 : [a-zA-Z_0-9]
\W 하나의 영숫자 이외의 문자 :[^\w]

또한 POSIX 형식의 분류가 있다.
\p{Lower} 하나의 소문자 알파벳 문자: [a-z]
\p{Upper} 하나의 대문자 알파벳 문자: [A-Z]
\p{ASCII} 모든 ASCII: [\x00-\x7f]
\p{Alpha} 하나의 알파벳 문자: [\p{Lower}\p{Upper}]
\p{Digit} 하나의 십진 숫자: [0-9]
\p{Alnum} 하나의 영숫자 문자: [\p{Alpha}\p{Digit}]
\p{Punct} 구두점: !”#$%&’()*,-./:;<=>?@[\]^_`{|}
\p{Graph} 하나의 눈에 보이는 문자7: [\p{Alnum}\p{Punct}]
\p{Print} 하나의 프린트 가능한 문자: [\p{Graph}]
\p{Blank} 하나의 스페이스(space)나 탭(tab): [ \t]
\p{Cntrl} 하나의 제어 문자: [\x00-\x1F\x7F]
\p{XDigit} 하나의 16진수 숫자: [0-9a-fA-F]
\p{Space} 하나의 공백문자: [\t\n\x0B\f\r]

주의 사항: \는 이스케이프 문자이기 때문에 \\ 이렇게 표시해야 한다.

자바에서의 실용예
num 이 숫자인지 확인
boolean a = Pattern.matches("\\p{Digit}*", num);
boolean b = Pattern.matches("[0-9]*", num);
boolean c = Pattern.matches("[\\d]*", num);

Android에서 POST로 파라미터 보내기


// url로 HttpPost객체를 생성한다.
httpPost = new HttpPost(url);
// NameValuePair로 보내고자 하는 파라미터를 추가한다.
List params = new ArrayList();
params.add(new BasicNameValuePair("uid", uid));
params.add(new BasicNameValuePair("ukey", ukey));

UrlEncodedFormEntity entity = null;

try {
// 원하는 인코딩으로 entity 객체를 생성한다.
enity= new UrlEncodedFormEntity(params, "UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// HttpPost 객체에 entity를 설정한다.
httpPost.setEntity(entity);

2010년 7월 24일 토요일

FRAMESET 만들기



<html>
<head>
</head>
<frameset rows="200, *" frameborder="0">
<frame src="head_top.php" name="top" scrolling="no" noresize/>
<frame src="head_body.php" name="body" noresize/>
</frameset>
</html>



주의할 점은 일반 HTML문서와 같이 <body>를 넣으면 frame이 표시되지 않는다.

PHP에서 Redirect

<? header("Location: URL"); exit; ?>

헤더가 이미 전송되었을 경우에는 아래의 방법으로 한다.
헤더가 전송되었는지 확인하는 함수 headers_sent()

echo "<meta http-equiv='refresh' content='0;url=URL'>";

PHP 버전 확인

<? php
phpinfo();
?>

2010년 7월 21일 수요일

MySQL에서 스크립트 파일 실행하기

mysql 프롬프트에서..
mysql> source 파일명

linux 프롬프트에서..
[xxxx]$ mysql -u 아이디 -p 비밀번호 데이터베이스명 < 파일명