<JAVA> 20. 메뉴와 대화상자

정지민·2023년 12월 1일

Java

목록 보기
12/12

메뉴

  • 메뉴바 : JMenuBar
  • 주 메뉴 : JMenu
  • 메뉴 항목
    • JMenuItem
    • JCheckBoxMenuItem
  • 메뉴 작성 과정
1. JMenuBar 생성
2. JMenu를 생성하여 JMenuBar에 붙임
3. JMenuItem을 생성하여 JMenu에 붙임
4. 여러개의 메뉴와 메뉴 아이템을 생성
5. JMenuBar를 JFrame에 붙임
  • 주 메뉴 구성
    - JMenuBar 객체 생성 : frame에 stJMenuBar() 호출로 연결

  • 주메뉴 위해 JMenu 객체 생성
    - JMenuBar 객체에 add()로 연결

  • JMenu 객체에 아래 객체를 add()로 연결

    • JMenuItem 객체 생성
    • JCheckBoxMenuItem 객체 생성

대화상자 (JDialog)

  • 메인 윈도우 외에 메세지를 출력하거나 사용자로부터 입력받을때 사용
  • 보통 JDialog로부터 상속받아 새로운 기능을 가진 대화상자를 만듦

팝업 대화상자 (JOptionPane)

  • 미리 지정된 양식의 간단한 대화상자 구성
  • 객체 생성후 static 메서드인 showXXXDialog() 이용하여 생성

메세지 대화상자

  • 간단한 메세지 출력을 위한 대화상자
    void JOptionPane.showMessageDialog(Component parentComponent, Object msg, String title, int messageType)

확인 대화상자

  • 버튼을 통해 확인을 입력받는 대화상자
    int JOptionPane.showConfirmDialog(Component parentComponent, Object msg, String title, int optionType)

입력 대화상자

  • 한 줄의 입력을 받는 다이얼로그 생성 및 출력
    String JOptionPane.showInputDialog(Compnent parentComponent, Object msg, String title, int messageType)

파일 선택 대화상자 (JFileChooser)

  • 사용자에게 파일이나 디렉토리를 쉽게 선택하도록 함
  • 주요 메서드
    • int showOpenDialog(Component pnt)
    • int showSaveDialog(Component pnt)
    • File getSelectedFile()

탭 팬 (JTabbedPane)

  • 여러개의 패널을 겹치게하여 한 공간을 공유하도록 지원
    JTabbedPane()
  • 탭 추가 : void addTab(String title, Component comp)
  • 탭 선택시 자동 전환 지원 - 이벤트 처리 불필요

0개의 댓글