Take off

블로그 이미지
by 안.들
  • Total hit
  • Today hit
  • Yesterday hit

Java MDI(multiple Document Interface)form Application 만들기 using AWT/Swing

JavaMdiformApplication.zip


JAVA에서는 MDIForm이 기본적으로 제공 안됨.
유사한 모습으로 구현 가능한 것이 
Jframe( Parent ) - JinternalFrame ( Child ) 을 JdesktopPane 로 제어하는 프레임 구조임.

샘플화면


1. Java Project 생성


2. JFrame 생성 (Main 페이지)


3. JInternalFrame ( Child )


MDIFrame 수행을 위해서 메인 페이지에 메뉴추가 후 Child1,2,3을 실행 + 프로그래밍
Parent Page : JavaFrameMainPAge에서 메뉴추가



프로그래밍 

**javaFrameMainPAge 클래스에 JDesktopPane import.

import javax.swing.JDesktopPane; /*추가*/
import javax.swing.JInternalFrame;

@SuppressWarnings("serial")
public class javaFrameMainPAge extends JFrame {

        private JPanel contentPane;
        private JDesktopPane desktopPane ; /*추가 : 멀티문서 인터페이스 or 가상 데스크탑을 생성하는 컨테이너*/

        public static void main(String[] args) {
                EventQueue.invokeLater(new Runnable() {
                        public void run() {
                                try {
                                        javaFrameMainPAge frame = new javaFrameMainPAge();
                                        frame.setVisible(true);
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }
                        }
                });
        }


**JDesktopPane 컨테이너에 JInternalFrame Add

private void mdiFormSetting(JInternalFrame oIframe)
        {               
                boolean bObj= true;
                JInternalFrame[] allFrames = desktopPane.getAllFrames();
               
                for(int i=0; i<allFrames.length; i++){
                        if(allFrames[i].getClass() ==  oIframe.getClass()){
                                bObj= false;
                                break;
                        }                       
                }
                
                if(bObj){
                        desktopPane.add(oIframe);
                        oIframe.setVisible(true);
                }
        }


**메뉴에서 Child1,2,3 페이지 호출

JMenuItem mntmChild = new JMenuItem("child1");
                mntmChild.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                
                                child1 obj = new child1();
                                mdiFormSetting(obj);
                        }
                });
                mnMditest.add(mntmChild);




별첨)소스파일


'Java' 카테고리의 다른 글

POJO 란?  (0) 2016.01.11
Maven이란?  (0) 2016.01.11
"HttpClient" 를 이용하여 어플리 케이션 실행화일 업데이트 방법  (0) 2015.11.23
AND

ARTICLE CATEGORY

분류 전체보기 (66)
금융 (0)
관제 (4)
Unix (1)
Android (6)
Windows (2)
Java (4)
oracle (3)
web (3)
English (3)
Physics (1)
Books (6)
요리 (1)
Deep Learning (6)
IoT (21)
to-do list (0)
Music (1)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2026/05   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

ARCHIVE