LINUX.ORG.RU

import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JTextArea;
import java.awt.event.KeyEvent;

class Main extends JFrame {
	
    private static void GUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame("Custom");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        
        JMenuBar menuBar = new JMenuBar();
        
        JMenu menu = new JMenu("File");
        menu.setMnemonic(KeyEvent.VK_F);
        menuBar.add(menu);
        
        JMenuItem menuItem = new JMenuItem("New", KeyEvent.VK_N);
        menu.add(menuItem);    
        
        JMenuItem menuItem2 = new JMenuItem("Open", KeyEvent.VK_O);
        menu.add(menuItem2);
        
        JMenuItem menuItem3 = new JMenuItem("Save", KeyEvent.VK_S);
        menu.add(menuItem3); 
        
        JMenuItem menuItem4 = new JMenuItem("Exit", KeyEvent.VK_E);
        menu.add(menuItem4); 
        
        JPanel panel = new JPanel(new BorderLayout());
        
        JTextArea text = new JTextArea(20,40);
        
        panel.add(text, BorderLayout.CENTER);
        
        //Finalize
        frame.setJMenuBar(menuBar);
        frame.add(panel);
		/* Для 1.4.2 */
		//frame.getContentPane().add(panel);
        frame.pack();
        frame.setVisible(true);
    }
	
    public static void main(String args[]) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                GUI();
            }
        });
    }

}

Selecter ★★★★
() автор топика

    public static void centerWindow(java.awt.Window window) {
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        java.awt.Dimension windowSize = window.getSize();
        int x = (int)((screenSize.getWidth() - windowSize.getWidth()) / 2);
        int y = (int)((screenSize.getHeight() - windowSize.getHeight()) / 2);
        window.setLocation(x, y);
    }

    /**
     * Center window relative owner
     * @param window window to center
     * @param owner window owner
     */    
    public static void centerWindow(java.awt.Window window, java.awt.Window owner) {
        java.awt.Rectangle rect = owner.getBounds();
        java.awt.Dimension windowSize = window.getSize();
        int x = (int)(rect.x + (rect.getWidth() - windowSize.getWidth()) / 2);
        int y = (int)(rect.y + (rect.getHeight() - windowSize.getHeight()) / 2);
        window.setLocation(x, y);
    }

asso_w
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.