public static void createAndShowGUI() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { ex.printStackTrace(); } JFrame frame = new JFrame("@title@"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.getContentPane().add(new MainPanel()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
public static void main(String s[]) { final MemoryMonitor demo = new MemoryMonitor(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } public void windowDeiconified(WindowEvent e) { demo.surf.start(); } public void windowIconified(WindowEvent e) { demo.surf.stop(); } }; JFrame f = new JFrame("Java2D Demo - MemoryMonitor"); f.addWindowListener(l); f.getContentPane().add("Center", demo); f.pack(); f.setSize(new Dimension(200, 200)); f.setVisible(true); demo.surf.start(); }