1. Java Swing API
package com.home.swing; import com.home.java.IconApi; import javax.swing.*; import java.awt.*; import java.io.IOException; public class JS { public static void runLater( Runnable handler ) { SwingUtilities.invokeLater(handler); } public static Dimension getScreenSize() { return Toolkit.getDefaultToolkit().getScreenSize(); } public static Double getScreenSizeWidth() { return Toolkit.getDefaultToolkit().getScreenSize().getWidth(); } public static Double getScreenHeight() { return Toolkit.getDefaultToolkit().getScreenSize().getHeight(); } public static void setWindowIcon(Frame frame, String icon) { frame.setIconImage( IconApi.getBase64Image(icon) ); } public static void setWindowIconRes(Frame frame, String image) throws IOException { /* ClassLoader cl = frame.getClass().getClassLoader(); InputStream is = cl.getResourceAsStream(image); if( is != null ) frame.setIconImage(ImageIO.read(is)); */ } public static void setWindowTitle(Frame frame, String title) { frame.setTitle(title); } public static void setWindowCenter(Frame frame) { 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); } public static void addTop(Frame frame, JComponent obj) { frame.add( obj, BorderLayout.NORTH); } public static void addCenter(Frame frame, JComponent obj) { frame.add( obj, BorderLayout.CENTER); } public static void addBottom(Frame frame, JComponent obj) { frame.add( obj, BorderLayout.SOUTH); } public static JMenuBar getMenuBar() { JMenuBar menubar = new JMenuBar(); menubar.add(getFileMenu()); return menubar; } public static JMenu getFileMenu() { JMenu menu = new JMenu("File"); JMenuItem exit_item = new JMenuItem("Exit"); exit_item.addActionListener((e) -> { System.exit(0); }); menu.add(exit_item); return menu; } public static JSplitPane getHSplitPane(JComponent left, JComponent right) { JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, right); split.setDividerLocation(400); split.setResizeWeight(1); return split; } public static JSplitPane getVSplitPane(JComponent left, JComponent right) { JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, left, right); split.setDividerLocation(400); split.setResizeWeight(1); return split; } public static JTabbedPane getTabbedPane() { JTabbedPane pane = new JTabbedPane(); return pane; } public static void addTab( JTabbedPane pane, String name, JComponent node) { pane.add( name, node ); } }
댓글 없음:
댓글 쓰기