Java Swing - Frame
package jlib5.swing; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Image; import java.awt.Toolkit; import javax.swing.JComponent; import javax.swing.JFrame; public class Frame { JFrame frame; public Frame(String title) { frame = new JFrame(title); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void show(int width, int height) { frame.pack(); frame.setLocationRelativeTo(null); moveToCenterScreen(); frame.setSize( new Dimension(width, height)); frame.setVisible(true); } public void setTop(JComponent node) { frame.getContentPane().add( node, BorderLayout.NORTH); } public void setCenter(JComponent node) { frame.getContentPane().add( node, BorderLayout.CENTER); } public void setBottom(JComponent node) { frame.getContentPane().add( node, BorderLayout.SOUTH); } public void setTitle(String title) { frame.setTitle( title ); } public void setWindowIcon( Image image ) { frame.setIconImage( image ); } public void moveToCenterScreen() { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frm = frame.getSize(); int xpos = (int)(screen.getWidth() / 2 - frm.getWidth() / 2); int ypos = (int)(screen.getHeight() / 2 - frm.getHeight() / 2); frame.setLocation(xpos, ypos); } }
댓글 없음:
댓글 쓰기