Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.40 KB | None | 0 0
  1. /// SSCCE modified from the Oracle JInternalFrame example to reproduce OpenJDK issue
  2.  
  3. package test;
  4.  
  5. import javax.swing.JInternalFrame;
  6. import javax.swing.JDesktopPane;
  7. import javax.swing.JDialog;
  8. import javax.swing.JMenu;
  9. import javax.swing.JMenuItem;
  10. import javax.swing.JRootPane;
  11. import javax.swing.JMenuBar;
  12. import javax.swing.JFrame;
  13. import javax.swing.KeyStroke;
  14. import javax.swing.UIManager;
  15. import javax.swing.UnsupportedLookAndFeelException;
  16.  
  17. import java.awt.event.*;
  18. import java.awt.*;
  19.  
  20. /*
  21.  * InternalFrameDemo.java requires:
  22.  *   MyInternalFrame.java
  23.  */
  24. public class JInternalFrameIcon extends JFrame
  25.                                implements ActionListener {
  26.     JDesktopPane desktop;
  27.  
  28.     public JInternalFrameIcon() {
  29.         super("InternalFrameDemo");
  30.  
  31.         //Make the big window be indented 50 pixels from each edge
  32.         //of the screen.
  33.         int inset = 50;
  34.         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  35.         setBounds(inset, inset,
  36.                   screenSize.width/2  - inset*2,
  37.                   screenSize.height/2 - inset*2);
  38.  
  39.         //Set up the GUI.
  40.         desktop = new JDesktopPane(); //a specialized layered pane
  41.         createFrame(); //create first "window"
  42.         setContentPane(desktop);
  43.         setJMenuBar(createMenuBar());
  44.  
  45.         //Make dragging a little faster but perhaps uglier.
  46.         desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
  47.     }
  48.  
  49.     protected JMenuBar createMenuBar() {
  50.         JMenuBar menuBar = new JMenuBar();
  51.  
  52.         //Set up the lone menu.
  53.         JMenu menu = new JMenu("Document");
  54.         menu.setMnemonic(KeyEvent.VK_D);
  55.         menuBar.add(menu);
  56.  
  57.         //Set up the first menu item.
  58.         JMenuItem menuItem = new JMenuItem("New");
  59.         menuItem.setMnemonic(KeyEvent.VK_N);
  60.         menuItem.setAccelerator(KeyStroke.getKeyStroke(
  61.                 KeyEvent.VK_N, ActionEvent.ALT_MASK));
  62.         menuItem.setActionCommand("new");
  63.         menuItem.addActionListener(this);
  64.         menu.add(menuItem);
  65.  
  66.         //Set up the second menu item.
  67.         menuItem = new JMenuItem("New Window");
  68.         menuItem.setMnemonic(KeyEvent.VK_W);
  69.         menuItem.setAccelerator(KeyStroke.getKeyStroke(
  70.                 KeyEvent.VK_W, ActionEvent.ALT_MASK));
  71.         menuItem.setActionCommand("newwindow");
  72.         menuItem.addActionListener(this);
  73.         menu.add(menuItem);
  74.  
  75.         //Set up the third menu item.
  76.         menuItem = new JMenuItem("Quit");
  77.         menuItem.setMnemonic(KeyEvent.VK_Q);
  78.         menuItem.setAccelerator(KeyStroke.getKeyStroke(
  79.                 KeyEvent.VK_Q, ActionEvent.ALT_MASK));
  80.         menuItem.setActionCommand("quit");
  81.         menuItem.addActionListener(this);
  82.         menu.add(menuItem);
  83.  
  84.         return menuBar;
  85.     }
  86.  
  87.     //React to menu selections.
  88.     public void actionPerformed(ActionEvent e) {
  89.         if ("new".equals(e.getActionCommand())) { //new
  90.             createFrame();
  91.         } else if ("newwindow".equals(e.getActionCommand())) { //new
  92.             createDialog();
  93.         } else { //quit
  94.             quit();
  95.         }
  96.     }
  97.  
  98.     //Create a new internal frame.
  99.     protected void createFrame() {
  100.         JInternalFrame frame = new JInternalFrame("Frame", true, true, true, true);
  101.         frame.setSize(600, 400);
  102.         frame.setFrameIcon(null); // TODO: Layout is not adjusted properly
  103.         frame.setVisible(true); //necessary as of 1.3
  104.         desktop.add(frame);
  105.         try {
  106.             frame.setSelected(true);
  107.         } catch (java.beans.PropertyVetoException e) {}
  108.     }
  109.  
  110.     //Create a new dialog.
  111.     protected void createDialog() {
  112.         JDialog dialog = new JDialog(this, "Dialog", false);
  113.         dialog.setSize(600, 400);
  114.         dialog.setResizable(false);
  115.         dialog.setVisible(true);
  116.     }
  117.  
  118.     //Quit the application.
  119.     protected void quit() {
  120.         System.exit(0);
  121.     }
  122.  
  123.     /**
  124.      * Create the GUI and show it.  For thread safety,
  125.      * this method should be invoked from the
  126.      * event-dispatching thread.
  127.      */
  128.     private static void createAndShowGUI() {
  129.         //Make sure we have nice window decorations.
  130.         JFrame.setDefaultLookAndFeelDecorated(true);
  131.  
  132.         //Create and set up the window.
  133.         JInternalFrameIcon frame = new JInternalFrameIcon();
  134.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  135.  
  136.         //Display the window.
  137.         frame.setVisible(true);
  138.     }
  139.  
  140.     public static void main(String[] args) {
  141.         // Set the Windows Look and Feel
  142.         try {
  143.           UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  144.         } catch (ClassNotFoundException e) {
  145.           // TODO Auto-generated catch block
  146.           e.printStackTrace();
  147.         } catch (InstantiationException e) {
  148.           // TODO Auto-generated catch block
  149.           e.printStackTrace();
  150.         } catch (IllegalAccessException e) {
  151.           // TODO Auto-generated catch block
  152.           e.printStackTrace();
  153.         } catch (UnsupportedLookAndFeelException e) {
  154.           // TODO Auto-generated catch block
  155.           e.printStackTrace();
  156.         }
  157.  
  158.         //Schedule a job for the event-dispatching thread:
  159.         //creating and showing this application's GUI.
  160.         javax.swing.SwingUtilities.invokeLater(new Runnable() {
  161.             public void run() {
  162.                 createAndShowGUI();
  163.             }
  164.         });
  165.     }
  166. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement