'Swing'에 해당되는 글 1건

  1. 2014.12.08 JFrame 기본
Java/Swing2014. 12. 8. 15:09

package org.test.swing;

 

import java.awt.*;

import java.awt.event.*;

 

import javax.swing.*;

 

public class MyJFrame extends JFrame{

    

    public static void main(String[] args){

        new MyJFrame();

    }

    public MyJFrame(){

        super();

        init();

    }

    public void init(){

        setTitle("MyFrame");

        addContent();

        setSize(300,200);

        //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

        addWindowListener(new WindowAdapter(){

            public void windowClosing(WindowEvent e) {

                close();

            }

        });

        

        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

        int x = (int) (screen.getWidth()/2 - getSize().getWidth()/2);

        int y = (int) (screen.getHeight()/2 - getSize().getHeight()/2);

        setLocation(x,y);

        

        setVisible(true);

    }

    public void addContent(){

        setLayout(new BorderLayout());

        

        JMenuBar menuBar = new JMenuBar();

        JMenu menu = new JMenu("Menu Bar");

        menuBar.add(menu);

        setJMenuBar(menuBar);

        

        JPanel toolbar = new JPanel(new FlowLayout(FlowLayout.LEFT));

        toolbar.add(new JLabel("Tool Bar"));

        add(toolbar,BorderLayout.NORTH);

        

        JPanel layout = new JPanel(new BorderLayout());

        layout.add(new JLabel("Content"));

        add(layout,BorderLayout.CENTER);

        

        JPanel status = new JPanel(new FlowLayout(FlowLayout.RIGHT));

        status.add(new JLabel("Status"));

        add(status,BorderLayout.SOUTH);

        

    }

    public void close(){

        dispose();

    }

}

 

 

'Java > Swing' 카테고리의 다른 글

WindowBuilder  (0) 2016.12.16
JTextField 를 상속받은 IPTextField Component 구현  (0) 2014.12.03
Posted by idwook