Java Code Examples for javax.swing.JFrame.addWindowListener()

The following are Jave code examples for showing how to use addWindowListener() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: trashjam2017   File: GradientEditor.java   View Source Code Vote up 6 votes
/**
 * Simple test case for the gradient painter
 * 
 * @param argv The arguments supplied at the command line
 */
public static void main(String[] argv) {
	JFrame frame = new JFrame();
	JPanel panel = new JPanel();
	panel.setBorder(BorderFactory.createTitledBorder("Gradient"));
	panel.setLayout(null);
	frame.setContentPane(panel);
		
	GradientEditor editor = new GradientEditor();
	editor.setBounds(10,15,270,100);
	panel.add(editor);
	frame.setSize(300,200);
	
	frame.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			System.exit(0);
		}
	});
	
	frame.setVisible(true);
}
 
Example 2
Project: The-Mysterious-Mind-Of-Jack   File: Main.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    // Main method
    Main m = new Main(); // Create the game object
    Main.m = m;
    frame = new JFrame("Game");
    frame.setResizable(false);
    frame.setUndecorated(true);
    frame.add(m.canvas);
 
    frame.pack();
    frame.addWindowListener(m);

    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    frame.requestFocus();
    m.start();
}
 
Example 3
Project: call-IDE   File: ConsoleCore.java   View Source Code Vote up 6 votes
/**
 * Description: dispatches the console from its current place properly.
 */
public static void  dispatch(JScrollPane scrollPane, JTextPane cons,
                             JTabbedPane outputTabs, Component tabComp, JFrame frame,
                             Boolean consoleOut, Attachable mainFrame) {
    frame.setSize(600, 400);
    frame.setLocationRelativeTo( (Component) mainFrame);
    frame.setLayout(new BorderLayout());
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    
    scrollPane.setViewportView(cons);
    frame.add(scrollPane);
    
    if (frame.getWindowListeners().length > 0)
        frame.removeWindowListener(frame.getWindowListeners()[0]);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            mainFrame.attachConsole();
        }
    });
    frame.setVisible(true);
}
 
Example 4
Project: openjdk-jdk10   File: TableExample2.java   View Source Code Vote up 6 votes
public TableExample2(String URL, String driver, String user,
        String passwd, String query) {
    JFrame frame = new JFrame("Table");
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });
    JDBCAdapter dt = new JDBCAdapter(URL, driver, user, passwd);
    dt.executeQuery(query);

    // Create the table
    JTable tableView = new JTable(dt);

    JScrollPane scrollpane = new JScrollPane(tableView);
    scrollpane.setPreferredSize(new Dimension(700, 300));

    frame.getContentPane().add(scrollpane);
    frame.pack();
    frame.setVisible(true);
}
 
Example 5
Project: java-open-nl   File: ONLSettings.java   View Source Code Vote up 6 votes
public static void onJFrameClose_Disconnect(JFrame frame) {
	if(frame != null) {
		frame.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				if(Server.isHosting() || Client.isConnected()) {
					if(Server.isHosting()) {
						Server.shutdown("");
					}else {
						Client.disconnect();
					}
				}
			}
		});
	}else {
		System.out.println("Can't add Window Event on a null JFrame.");
	}
}
 
Example 6
Project: asgdrivestrength   File: DrivestrengthRunMain.java   View Source Code Vote up 5 votes
public static int main2(String[] args) {
    boolean isDebug = extractIsDebug(args);
    String dataDir = extractDataDir(args);

    LoggerHelper.initLogger(3, null, false, Mode.cmdline);

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch(ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) {
        return 1;
    }

    DrivestrengthParameters params = new DrivestrengthParameters();

    JFrame runframe = new JFrame("ASGdrivestrength runner");
    RunDrivestrengthPanel runpanel = new RunDrivestrengthPanel(runframe, params, isDebug, false, false, dataDir);
    if(runpanel.hasErrorOccured()) {
        return 1;
    }
    runframe.getContentPane().add(runpanel);
    WatchForCloseWindowAdapter closeAdapter = new WatchForCloseWindowAdapter();
    runframe.addWindowListener(closeAdapter);
    runframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    runframe.pack();
    runframe.setLocationRelativeTo(null); //center
    runframe.setVisible(true);

    while(!closeAdapter.isClosed()) {
        try {
            Thread.sleep(1000);
        } catch(InterruptedException e) {
        }
    }
    return 0;
}
 
Example 7
Project: jdk8u-jdk   File: MultiGradientTest.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    final JFrame frame = new JFrame("Multistop Gradient Demo");
    frame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            frame.dispose();
        }
    });
    frame.add(new MultiGradientTest());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
 
Example 8
Project: incubator-netbeans   File: RendererDisplayerTest.java   View Source Code Vote up 5 votes
public WaitWindow(JFrame f) {
    f.addWindowListener(this);
    f.show();
    if (!shown) {
        synchronized(this) {
            try {
                //System.err.println("Waiting for window");
                wait(5000);
            } catch (Exception e) {}
        }
    }
}
 
Example 9
Project: incubator-netbeans   File: SheetTableTest.java   View Source Code Vote up 5 votes
public WaitWindow(JFrame f) {
    f.addWindowListener(this);
    f.show();
    if (!shown) {
        synchronized(this) {
            try {
                //System.err.println("Waiting for window");
                wait(5000);
            } catch (Exception e) {}
        }
    }
}
 
Example 10
Project: etomica   File: B2Fit.java   View Source Code Vote up 5 votes
public static void main(String[] args) {

        B2Fit graph = new B2Fit();
        JFrame f = new JFrame();
        f.setSize(1000, 600);
        f.getContentPane().add(graph);
        f.setVisible(true);
        f.addWindowListener(SimulationGraphic.WINDOW_CLOSER);
        graph.dPlot.refresh();

    }
 
Example 11
Project: game2048_tetris   File: Main.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
	//新建窗体对象
	frame = new JFrame("2048");
	frame.setIconImage(new ImageIcon(MainPanel.class.getResource("gameicon.png")).getImage());
	//窗体大小
	frame.setSize(460, 680);
	//窗体居中
	frame.setLocationRelativeTo(null);
	//窗体大小不可变
	frame.setResizable(false);
	//默认的关闭操作
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	//新建主面板 对象
	mainPanel = new MainPanel(frame);
	//去掉面板默认布局
	mainPanel.setLayout(new FlowLayout(1, 200, 90));
	//面板背景颜色
	mainPanel.setBackground(new Color(247, 239, 230));
	//把面板添加到窗体中
	frame.add(mainPanel);
	//窗体可见
	frame.setVisible(true);
	//主界面的控制方法
	mainPanel.run();
	frame.addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
			try {
				mainPanel.getClassicPanel().saveScore();
				mainPanel.getClassicPanel().saveState();
				mainPanel.getDropPanel().updateTopScore();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
	});		
	
}
 
Example 12
Project: incubator-netbeans   File: ComboTest.java   View Source Code Vote up 5 votes
public WaitWindow(JFrame f) {
    f.addWindowListener(this);
    f.show();
    if (!shown) {
        synchronized(this) {
            try {
                wait(5000);
            } catch (Exception e) {}
        }
    }
}
 
Example 13
Project: incubator-netbeans   File: EditableDisplayerTest.java   View Source Code Vote up 5 votes
public WaitWindow(JFrame f) {
    f.addWindowListener(this);
    f.show();
    if (!shown) {
        synchronized(this) {
            try {
                //System.err.println("Waiting for window");
                wait(5000);
            } catch (Exception e) {}
        }
    }
}
 
Example 14
Project: Logisim   File: WindowMenuItemManager.java   View Source Code Vote up 5 votes
public void frameOpened(JFrame frame) {
	if (!listenerAdded) {
		frame.addWindowListener(myListener);
		listenerAdded = true;
	}
	addToManager();
	WindowMenuManager.setCurrentManager(this);
}
 
Example 15
Project: jdk8u-jdk   File: CompositionArea.java   View Source Code Vote up 5 votes
CompositionArea() {
    // create composition window with localized title
    String windowTitle = Toolkit.getProperty("AWT.CompositionWindowTitle", "Input Window");
    compositionWindow =
        (JFrame)InputMethodContext.createInputMethodWindow(windowTitle, null, true);

    setOpaque(true);
    setBorder(LineBorder.createGrayLineBorder());
    setForeground(Color.black);
    setBackground(Color.white);

    // if we get the focus, we still want to let the client's
    // input context handle the event
    enableInputMethods(true);
    enableEvents(AWTEvent.KEY_EVENT_MASK);

    compositionWindow.getContentPane().add(this);
    compositionWindow.addWindowListener(new FrameWindowAdapter());
    addInputMethodListener(this);
    compositionWindow.enableInputMethods(false);
    compositionWindow.pack();
    Dimension windowSize = compositionWindow.getSize();
    Dimension screenSize = (getToolkit()).getScreenSize();
    compositionWindow.setLocation(screenSize.width - windowSize.width-20,
                                screenSize.height - windowSize.height-100);
    compositionWindow.setVisible(false);
}
 
Example 16
Project: VASSAL-src   File: PolygonEditor.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
  JFrame f = new JFrame();
  f.add(new PolygonEditor(null));
  f.setSize(500, 500);
  f.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
      System.exit(0);
    }
  });
  f.setVisible(true);
}
 
Example 17
Project: geomapapp   File: MapApp.java   View Source Code Vote up 5 votes
protected void initLayerManager() {

		JFrame d = new JFrame();
		d.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				((JCheckBoxMenuItem)(XML_Menu.commandToMenuItemHash.get("layer_manager_cmd"))).setSelected(false);
			}
		});
		LayerManager lm;
		
		//use existing layer manager if it already exists
		if (layerManager != null) {
			lm = layerManager;
		} else {
			lm = new LayerManager();
		}
		
		lm.setLayerList( toLayerList(map.overlays) );
		lm.setMap(map);

		lm.setDialog(d);
		JScrollPane sp = new JScrollPane(lm);
		sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		d.setTitle("Layer Manager");
		d.setContentPane(sp);
//		d.getContentPane().add(sp);
		d.pack();
		d.setSize(new Dimension(lm.getPreferredSize().width+20,lm.getPreferredSize().height+55));
		d.setMaximumSize(new Dimension(400,300));

		d.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
		d.setLocationRelativeTo(frame);
		d.setState(Frame.NORMAL);
		d.setAlwaysOnTop(true);
		this.layerManager = lm;
		this.layerManagerDialog = d;	
	}
 
Example 18
Project: CustomWorldGen   File: MinecraftServerGui.java   View Source Code Vote up 4 votes
/**
 * Creates the server GUI and sets it visible for the user.
 */
public static void createServerGui(final DedicatedServer serverIn)
{
    try
    {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch (Exception var3)
    {
        ;
    }

    MinecraftServerGui minecraftservergui = new MinecraftServerGui(serverIn);
    JFrame jframe = new JFrame("Minecraft server");
    jframe.add(minecraftservergui);
    jframe.pack();
    jframe.setLocationRelativeTo((Component)null);
    jframe.setVisible(true);
    jframe.addWindowListener(new WindowAdapter()
    {
        public void windowClosing(WindowEvent p_windowClosing_1_)
        {
            serverIn.initiateShutdown();

            while (!serverIn.isServerStopped())
            {
                try
                {
                    Thread.sleep(100L);
                }
                catch (InterruptedException interruptedexception)
                {
                    interruptedexception.printStackTrace();
                }
            }

            System.exit(0);
        }
    });
    minecraftservergui.latch.countDown();
}
 
Example 19
Project: incubator-netbeans   File: EditorPaneDemo.java   View Source Code Vote up 4 votes
public EditorPaneDemo(Language language, boolean maintainLookbacks,
String initialContent) {

    super(new PlainDocument(), language, maintainLookbacks);
    
    JFrame frame = new JFrame();
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            System.exit(0);
        }
    });

    frame.setTitle("Test of " + splitClassName(language.getClass().getName())[1]
        + " - Use Ctrl+L to dump tokens");

    JEditorPane jep = new JEditorPane();
    
    Document doc = getDocument();
    jep.setDocument(doc);
    // Insert initial content string
    try {
        if (initialContent != null) {
            doc.insertString(0, initialContent, null);
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
        return;
    }
    
    // Initially debug token changes
    setDebugTokenChanges(true);

    frame.getContentPane().add(jep);
    
    DumpAction da = new DumpAction();
    jep.registerKeyboardAction(da,
        KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_MASK), 0);
    
    DebugTokenChangesAction dtca = new DebugTokenChangesAction();
    jep.registerKeyboardAction(dtca,
        KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_MASK), 0);
    
    
    System.err.println("NOTE: Press Ctrl+L to dump the document's token list.\n");
    System.err.println("      Press Ctrl+T to toggle debugging of token changes.\n");
    
    // Debug initially
    dump();

    frame.setSize(400, 300);
    frame.setVisible(true);
    
}
 
Example 20
Project: chordatlas   File: TweedFrame.java   View Source Code Vote up 4 votes
public TweedFrame() {

		instance = this;

		frame = new JFrame();

		WindowManager.register( frame );

		Dimension d3Dim = new Dimension( 1024, 640 );

		AppSettings settings = new AppSettings( true );

		settings.setWidth( d3Dim.width );
		settings.setHeight( d3Dim.height );
		settings.setSamples( 4 );
		settings.setVSync( true );
		settings.setFrameRate( 60 );

		tweed = new Tweed( this );
		tweed.setSettings( settings );
		tweed.createCanvas();
		JmeCanvasContext ctx = (JmeCanvasContext) tweed.getContext();
		ctx.setSystemListener( tweed );

		canvas = ctx.getCanvas();
		canvas.setPreferredSize( d3Dim );

		frame.setLayout( new BorderLayout() );
		frame.add( buildUI(), BorderLayout.EAST );
		frame.add( canvas, BorderLayout.CENTER );
		frame.setExtendedState( frame.getExtendedState() | JFrame.MAXIMIZED_BOTH );

		frame.addWindowListener( new WindowAdapter() {
			public void windowClosing( WindowEvent e ) {
				TweedSettings.save(true);
				Tweed.deleteScratch();
			};
		} );

		scheduler.scheduleAtFixedRate( new Runnable() {
			@Override
			public void run() {
				TweedSettings.save(true);
			}
		}, 30, 30, TimeUnit.SECONDS );

		scheduler.scheduleAtFixedRate( new Runnable() {
			@Override
			public void run() {
				Vector3d pt = tweed.cursorPosition;
				if ( coordLabel != null && TweedSettings.settings.trans != null) {
					worldLabel.setText( pt == null ? "..." : String.format( "%.4f, %.4f ", 
							pt.x, 
							pt.z) );
					coordLabel.setText( pt == null ? "..." : String.format( "%.4f, %.4f ", 
							pt.x + TweedSettings.settings.trans[0], 
							pt.z + TweedSettings.settings.trans[1]) );
					crsLabel.setText(TweedSettings.settings.gmlCoordSystem);
				}

				JFrame.setDefaultLookAndFeelDecorated( true );

			}
		}, 100, 100, TimeUnit.MILLISECONDS );

		frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		frame.pack();
		frame.setVisible( !HEADLESS );

		tweed.startCanvas();
	}