[ Swing ] MDI 샘플예제 본문

[PL]/JAVA

[ Swing ] MDI 샘플예제

객과 함께. 2014. 5. 30. 12:06

[mdi main() ]

아래 예제는 이클립스 사용.


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

 

public class testMain extends JFrame {

 private static final long serialVersionUID = 1L;
 
 private JPanel contentPane;
 JDesktopPane desktopPane;
 private Dimension dFrame , screenSize;
 private int posX, posY; 

 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     testMain frame = new testMain();
     frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
 }
 
 public testMain() {
  setTitle("MDI 예제");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setBounds(100, 100, 823, 580);
  setResizable(false);
  
  dFrame = super.getSize();
  screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  
  posX = (int)(screenSize.getWidth() / 2) - (int)(dFrame.getWidth() / 2);
  posY = (int)(screenSize.getHeight() / 2) - (int)(dFrame.getHeight() /2);
  
  setLocation(posX, posY);
  
  contentPane = new JPanel();
  contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  contentPane.setLayout(new BorderLayout(0, 0));
  contentPane.setBackground(Color.blue);
  setContentPane(contentPane);
  
  desktopPane = new JDesktopPane();
  contentPane.add(desktopPane, BorderLayout.CENTER);
  
  JMenuBar menuBar = new JMenuBar();
  menuBar.setBounds(0, 0, 806, 30);
  desktopPane.add(menuBar);
  desktopPane.setBackground(Color.green);
  
  JMenu menu = new JMenu("\uAD00\uB9AC");
  menuBar.add(menu);
  
  JMenuItem menuItem_1 = new JMenuItem("\uD589\uC815\uAD00\uB9AC");
  menuItem_1.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    test03 t3 = new test03();
    t3.setResizable(true);
    desktopPane.add(t3);
    getContentPane().add(desktopPane);
   
    t3.setVisible(true);
   }
  });
  menu.add(menuItem_1);
  
  JMenu mnNewMenu = new JMenu("\uC601\uC5C5\uAD00\uB9AC");
  menuBar.add(mnNewMenu);
  
  JMenuItem mntmNewMenuItem = new JMenuItem("\uC601\uC5C5 \uD604\uD669");
  mntmNewMenuItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    
    testInfo t = new testInfo();
    testInfo.setStrString1("t2");
    
    if(t.getflog1() == false) {
     test02 t2 = new test02();
     t2.setResizable(true);
     desktopPane.add(t2);
     getContentPane().add(desktopPane);
    
     t2.setVisible(true);
     testInfo.setflog1(true);
    }
   }
  });
  mnNewMenu.add(mntmNewMenuItem);
  
  JMenu mnNewMenu_1 = new JMenu("\uD488\uC9C8\uAD00\uB9AC");
  menuBar.add(mnNewMenu_1);
  
  JMenuItem menuItem = new JMenuItem("\uD488\uC9C8\uD604\uD669");
  menuItem.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    
    testInfo ti = new testInfo();
    ti.setStrString("t1");
    
    if(ti.getflog() == false) {
     test01 t1 = new test01();
     t1.setResizable(false); 
     desktopPane.add(t1);
     getContentPane().add(desktopPane);
    
     t1.setVisible(true);
     testInfo.setflog(true);
    }
   }
  });
  mnNewMenu_1.add(menuItem);
 }
}

 

//============================================================================================

[test01.java]


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class test01 extends JInternalFrame {

 private static final long serialVersionUID = 1L;
 
 private JPanel contentPane;
 testInfo eInfo;
 private JTextField textField;
 private JTable table;

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

 
 public test01() {
  setTitle("\uCCAB\uBC88\uC9F8 \uD3FC\uC785\uB2C8\uB2E4.");
  setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  setBounds(100, 100, 450, 300);
  setResizable(false);
  contentPane = new JPanel();
  contentPane.setBorder(new EmptyBorder(2,2, 2, 2));
  setContentPane(contentPane);
  GridBagLayout gbl_contentPane = new GridBagLayout();
  gbl_contentPane.columnWidths = new int[]{1, 1, 1, 1,1, 1, 1, 1, 1, 1, 1, 1, 1};
  gbl_contentPane.rowHeights = new int[]{1, 1, 1, 1, 1, 1, 1, 1};
  gbl_contentPane.columnWeights = new double[]{1.0, 0.0, 1.0, 0.0, 1.0,0.0, 1.0, 0.0, 1.0,0.0,1.0,0.0, Double.MIN_VALUE};
  gbl_contentPane.rowWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
  contentPane.setLayout(gbl_contentPane);
  
  JButton btnNewButton = new JButton("\uB2EB\uAE30");
  btnNewButton.addActionListener(new ActionListener() {
   public void actionPerformed(ActionEvent e) {
    eInfo = new testInfo();
    
    testInfo.setStrString("t1");
    testInfo.setflog( false);
    
    dispose();
   }
  });
  
  JLabel label = new JLabel("\uCCAB \uD3FC");
  GridBagConstraints gbc_label = new GridBagConstraints();
  gbc_label.anchor = GridBagConstraints.EAST;
  gbc_label.insets = new Insets(0, 0, 5, 5);
  gbc_label.gridx = 1;
  gbc_label.gridy = 1;
  contentPane.add(label, gbc_label);
  
  textField = new JTextField();
  GridBagConstraints gbc_textField = new GridBagConstraints();
  gbc_textField.gridwidth = 4;
  gbc_textField.insets = new Insets(0, 0, 5, 5);
  gbc_textField.fill = GridBagConstraints.HORIZONTAL;
  gbc_textField.gridx = 2;
  gbc_textField.gridy = 1;
  contentPane.add(textField, gbc_textField);
  textField.setColumns(10);
  GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
  gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
  gbc_btnNewButton.gridx = 5;
  gbc_btnNewButton.gridy = 2;
  contentPane.add(btnNewButton, gbc_btnNewButton);
  
  JButton btnNewButton_1 = new JButton("\uC800\uB2F9");
  GridBagConstraints gbc_btnNewButton_1 = new GridBagConstraints();
  gbc_btnNewButton_1.insets = new Insets(0, 0, 5, 5);
  gbc_btnNewButton_1.gridx = 7;
  gbc_btnNewButton_1.gridy = 2;
  contentPane.add(btnNewButton_1, gbc_btnNewButton_1);
  
  table = new JTable();
  GridBagConstraints gbc_table = new GridBagConstraints();
  gbc_table.gridheight = 3;
  gbc_table.gridwidth = 9;
  gbc_table.insets = new Insets(0, 0, 5, 5);
  gbc_table.fill = GridBagConstraints.BOTH;
  gbc_table.gridx = 1;
  gbc_table.gridy = 3;
  contentPane.add(table, gbc_table);
  
  JLabel lblNewLabel = new JLabel("\uCCAB \uD3FC");
  GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
  gbc_lblNewLabel.gridx = 11;
  gbc_lblNewLabel.gridy = 6;
  contentPane.add(lblNewLabel, gbc_lblNewLabel);
  
 }

}

'[PL] > JAVA' 카테고리의 다른 글

puzzle 게임  (0) 2014.09.18
[ Swing ] Dialog예제  (0) 2014.06.02
[ Opnecv ] javacv 버그 관련   (0) 2014.06.02
WindowBuild Pro 관련  (0) 2014.04.24
GUI에서 한글이 네모 모양으로 나올때   (0) 2014.03.26