• Home
  • About
    • Young's Github Pages photo

      一日不作一日不食

    • About
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Java 정리 45

18 Jan 2019

Reading time ~1 minute

Java 정리 45 - 도시락 주문 프로그램(5)


개발

  • 계속 개발..
  • 도시락 주문 관리 프로그램 패키지

  • JOptionPane의 showMessageDialog()가 많이 사용되고 있음
    • static import를 사용하여 JOptionPane 명시를 생략할 수 있음
// static import
import static javax.swing.JOptionPane.showMessageDialog; 
  • 또는 따로 짧은 method를 만들어서 값을 전달했을 때 showMessageDialog() 함수를 호출하도록 할 수 있음
private void msgCenter(Component parentComponent, String  message ) {
     JOptionPane.showMessageDialog(parentComponent,  message);
}
  • 서버 개발 끝(Thread 빼고), 클라이언트 개발 시작
  • 주문자 연락처 검증 코드
// tel이 TextField에 입력한 연락처 문자열(000-0000-0000)
String[] separatedTel = tel.split("-");
try {
     if (separatedTel.length == 3) { // 제대로된 전화번호형식
          if (separatedTel[0].length() != 3 || 
          !(separatedTel[1].length() > 2 &&  separatedTel[1].length()<5) ||
           separatedTel[2].length() != 4) {
              showMessageDialog(lodv, "전화번호의  자리수가 잘못되었습니다.");
              return;
          }
          
          for(int i=0; i<separatedTel.length; i++) { // NumberFormatException 있는지
              Integer.parseInt(separatedTel[i]);
          }
     } else {
          showMessageDialog(lodv, "전화번호의 형식이  올바르지 않습니다.");
          return;
     }
} catch (NumberFormatException e) {
     showMessageDialog(lodv, "전화번호에 문자가  들어있습니다.");
}
  • 클라이언트 도시락 목록, 상세정보 보기, 주문하기 개발

01

02

03



Java