下面列出了怎么用java.awt.event.WindowAdapter的API类实例代码及写法,或者点击链接到github查看源代码。
private void createTree()
{
m_gameTreeViewer = new GameTreeViewer(this, this, m_messageDialogs);
m_gameTreeViewer.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
actionDisposeTree();
}
});
GuiAction.registerAll(m_gameTreeViewer.getLayeredPane());
m_gameTreeViewer.setLabelMode(m_treeLabels);
m_gameTreeViewer.setSizeMode(m_treeSize);
m_gameTreeViewer.setShowSubtreeSizes(m_showSubtreeSizes);
restoreSize(m_gameTreeViewer, "tree");
m_gameTreeViewer.update(getTree(), getCurrentNode());
m_gameTreeViewer.setVisible(true);
}
public GUIDiffDialogParent(JFrame owner) throws Exception {
super(owner);
setTitle("Diff");
Rectangle rect = owner.getBounds();
width = rect.width - 100;
height = rect.height - 100;
setBounds(rect.x + rect.width/2 - width/2, rect.y + rect.height/2 - height/2, width, height); /* ド真ん中 */
createPanel();
Container c = getContentPane();
c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
c.add(main_panel);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
try {
dispose();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public GUIFilterConfigDialog(JFrame owner) throws Exception {
super(owner);
this.owner = owner;
setTitle(I18nString.get("Manage filters"));
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
dispose();
}
});
Rectangle rect = owner.getBounds();
setBounds(rect.x + rect.width/2 - width/2, rect.y + rect.height/2 - height/2, width, height); /* ド真ん中 */
Container c = getContentPane();
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new GUIFilterConfig(owner).createPanel());
c.add(panel);
}
private void initComponents() {
ExtractDialog _this = this;
setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
// setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setIconImage(MainWin.icon);
setSize(820, 460);
// setResizable(false);
setLocationRelativeTo(this.getParent());
setTitle("请选择压缩包中要保存的字幕文件");
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
_this.clear();
_this.dispose();
}
});
add(bsPanel, BorderLayout.CENTER);
openUrl(MainWin.class.getResource("/html/extract_dialog.html").toExternalForm());
}
/**
* Create the UI.
* @throws Exception if any error occurs.
*/
private static void createUI() throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
final JFrame frame = new JFrame("N-Body demo");
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(final WindowEvent e) {
System.exit(0);
}
});
final JPanel topPanel = new JPanel();
label = new JLabel("Time steps: 0");
label.setHorizontalAlignment(SwingConstants.LEFT);
label.setAlignmentX(0f);
topPanel.add(label, BorderLayout.WEST);
frame.getContentPane().add(topPanel, BorderLayout.NORTH);
panel = new NBodyPanel();
final Dimension dim = new Dimension((int) radius, (int) radius);
panel.setMinimumSize(dim);
panel.setMaximumSize(dim);
panel.setPreferredSize(dim);
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setSize((int) radius + 50, (int) radius + 70);
frame.setVisible(true);
}
public ERDesignerMainFrame() {
super(ERDesignerBundle.TITLE);
initialize();
setSize(800, 600);
setExtendedState(MAXIMIZED_BOTH);
setIconImage(IconFactory.getERDesignerIcon().getImage());
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
exitApplication();
}
});
UIInitializer.getInstance().initialize(this);
initTitle();
}
/**
* ���ش���
*/
public void loadFrame(){
this.setTitle("����˹����");
this.setSize(Constant.FRAME_WIDTH, Constant.FRAME_HEIGHT);
this.setBackground(Color.WHITE);
this.setLocationRelativeTo(null);//����
this.setResizable(false);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setVisible(true);
new MyThread().start();
}
public void loadFrame() {
initRandomTree();
this.setTitle("����");
this.setSize(FRAME_WIDTH, FRAME_HEIGHT);
this.setBackground(Color.WHITE);
this.setLocationRelativeTo(null);// ����
this.setResizable(false);
this.setFont(new Font("��Բ", Font.BOLD, 20));
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setLayout(null);
this.initComponent();// ��ʼ�����
this.setVisible(true);
}
/**
* �Զ������ɴ��ڵķ���
*
* @throws InterruptedException
*/
public void launchFrame() {
// ���ô��ڴ�С
setSize(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
// ���ô���λ��
// setLocation(0, 0);
setLocationRelativeTo(null);// ��Ծ��У�����null���������ʾ����Ļ
// ���ô��ڱ���
setTitle("�ɻ���ս");
// ���ÿɼ�
setVisible(true);
// ���ò��ܸı��С
setResizable(false);
// ���ùرմ���
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);// ���ùر�
}
});
enableInputMethods(false);//�������뷨
setBackground(Color.BLACK);
new MyThread().start();
}
/**
* �Զ������ɴ��ڵķ���
*
* @throws InterruptedException
*/
public void launchFrame() {
// ���ô��ڴ�С
setSize(Constant.GAME_WIDTH, Constant.GAME_HEIGHT);
// ���ô���λ��
// setLocation(0, 0);
setLocationRelativeTo(null);// ��Ծ��У�����null���������ʾ����Ļ
// ���ô��ڱ���
setTitle("�ɻ���ս(����)");
// ���ÿɼ�
setVisible(true);
// ���ò��ܸı��С
setResizable(false);
// ���ùرմ���
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);// ���ùر�
}
});
enableInputMethods(false);//�������뷨
setBackground(Color.BLACK);
new MyThread().start();
}
/**
* ���ش���
*/
public void loadFrame(){
this.setTitle("����˹����");
this.setSize(Constant.FRAME_WIDTH, Constant.FRAME_HEIGHT);
this.setBackground(Color.WHITE);
this.setLocationRelativeTo(null);//����
this.setResizable(false);
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setVisible(true);
new MyThread().start();
}
/**
* Show measurment form
*/
public void showMeasurementForm() {
if (_frmMeasure == null) {
_frmMeasure = new FrmMeasurement((JFrame) SwingUtilities.getWindowAncestor(this), false);
_frmMeasure.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
_currentLayoutMap.getMapFrame().getMapView().setDrawIdentiferShape(false);
//repaint();
repaintOld();
}
});
_frmMeasure.setLocationRelativeTo(this);
_frmMeasure.setVisible(true);
} else if (!_frmMeasure.isVisible()) {
_frmMeasure.setVisible(true);
}
}
public static void main(String[] args) {
final GLProfile gp = GLProfile.get(GLProfile.GL2);
GLCapabilities cap = new GLCapabilities(gp);
final GLCanvas gc = new GLCanvas(cap);
Triangle tr = new Triangle();
gc.addGLEventListener(tr);
gc.setSize(400, 400);
final JFrame frame = new JFrame("JOGL Triangle");
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowevent) {
frame.dispose();
System.exit(0);
}
});
frame.add(gc);
frame.setSize(500, 400);
frame.setVisible(true);
}
private void loadComparisonPNG( String fileName ) {
try {
BufferedImage image =
javax.imageio.ImageIO.read(new File(fileName));
JFrame f = new JFrame( "Comparison PNG" );
ImagePanel ip = new ImagePanel( image );
f.setResizable( false );
f.getContentPane().add( ip );
f.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
( (JFrame) e.getSource() ).dispose();
}
});
f.pack();
f.show();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );
ex.printStackTrace();
}
}
private static void append(String s) {
if (frame == null) {
// FIXME: The frame title should be a localized string.
frame = new JFrame("JConsole: Output");
ta = new JTextArea();
ta.setEditable(false);
frame.getContentPane().add(new JScrollPane(ta));
ta.setFont(new Font("Monospaced", Font.BOLD, 14));
frame.setSize(500, 600);
frame.setLocation(1024-500, 768-600);
// Exit JConsole if no window remains.
// e.g. jconsole -version only creates the OutputViewer
// but no other window.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (JFrame.getFrames().length == 1) {
System.exit(0);
}
}
});
}
ta.append(s);
ta.setCaretPosition(ta.getText().length());
frame.setVisible(true);
}
private JFrame createMainFrame() {
JFrame mainFrame = new JFrame();
mainFrame.setTitle("Image Recognizer");
mainFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
mainFrame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
mainFrame.setLocationRelativeTo(null);
mainFrame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
System.exit(0);
}
});
ImageIcon imageIcon = new ImageIcon("icon.png");
mainFrame.setIconImage(imageIcon.getImage());
return mainFrame;
}
private TestGraphAlgorithmSteppingViewerPanel<TestV, TestE> showViewer(
AlgorithmSteppingTaskMonitor steppingMonitor) {
String isHeadless = Boolean.toString(false);
System.setProperty(SystemUtilities.HEADLESS_PROPERTY, isHeadless);
System.setProperty("java.awt.headless", isHeadless);
JFrame frame = new JFrame("Graph");
TestGraphAlgorithmSteppingViewerPanel<TestV, TestE> gp =
new TestGraphAlgorithmSteppingViewerPanel<>(g, steppingMonitor);
frame.getContentPane().add(gp);
frame.setSize(800, 800);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
steppingMonitor.cancel();
}
});
return gp;
}
private void createAnalyzeDialog()
{
m_analyzeDialog = new AnalyzeDialog(this, this, m_analyzeCommands,
m_gtp, m_messageDialogs);
m_analyzeDialog.setReuseTextWindow(
m_prefs.getBoolean("analyze-reuse-text-window", false));
GuiAction.registerAll(m_analyzeDialog.getLayeredPane());
m_analyzeDialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
actionDisposeAnalyzeDialog();
}
});
m_analyzeDialog.setBoardSize(getBoardSize());
m_analyzeDialog.setSelectedColor(getToMove());
restoreSize(m_analyzeDialog, "analyze");
m_analyzeDialog.setVisible(true);
}
public Window show(Model model) {
Window window = windows.computeIfAbsent(model.getAddress(), (address) -> {
ModelTableView view = new ModelTableView();
view.bind(new DefaultSelectionModel<Model>(model));
JDialog dialog = new JDialog(null, model.getAddress(), ModalityType.MODELESS);
dialog.add(new JScrollPane(view.getComponent()));
dialog.setSize(600, 400);
dialog.addWindowListener(new WindowAdapter() {
/* (non-Javadoc)
* @see java.awt.event.WindowAdapter#windowClosed(java.awt.event.WindowEvent)
*/
@Override
public void windowClosed(WindowEvent e) {
view.dispose();
}
});
return dialog;
});
window.setVisible(true);
return window;
}
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);
}
public MetalworksFrame() {
super("Metalworks");
final int inset = 50;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(inset, inset, screenSize.width - inset * 2, screenSize.height - inset
* 2);
buildContent();
buildMenus();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
quit();
}
});
UIManager.addPropertyChangeListener(new UISwitchListener(
(JComponent) getRootPane()));
}
public ClickableWindow(Guide guide) {
super(new Color(0.1f, 0f, 0f, 0.005f), null);
this.guide = guide;
jp = getJPanel();
mouseTracker = GlobalMouseMotionTracker.getInstance();
mouseTracker.addListener(this);
setVisible(false);
setFocusableWindowState(false);
addMouseListener(this);
addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent e) {
// stop the global mouse tracker's timer thread
mouseTracker.stop();
}
});
}
/**
* Display the given plot. Unlike the two argument constructor, this does
* not take command-line arguments, and does not fill the plot with a sample
* plot.
*
* @param plot
* The instance of Plot to display.
*/
public PlotApplication(PlotBox plot) {
// Invoke the base class constructor and pass in the argument a Plot
// object. This makes sure that the plot field is an instance of
// Plot class.
super("PlotApplication", plot);
// Handle window closing by exiting the application.
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Strangely, calling _close() here sends javac into
// an infinite loop (in jdk 1.1.4).
// _close();
System.exit(0);
}
});
setVisible(true);
}
public VideoDownloadWindow(HttpMetadata metadata, String file) {
// this.folder = Config.getInstance().getDownloadFolder();
this.metadata = metadata;
if (this.metadata == null) {
this.metadata = new HttpMetadata();
}
initUI();
if (file != null && file.length() > 0) {
filePane.setFileName(file);
// txtFile.setCaretPosition(0);
originalExt = XDMUtils.getExtension(filePane.getFileName());
}
getRootPane().setDefaultButton(btnDN);
addWindowListener(new WindowAdapter() {
@Override
public void windowActivated(WindowEvent e) {
filePane.setFocus();
}
});
queueId = "";
}
private void setupUI() {
mainPanel = new JPanel(new BorderLayout());
dialog.getContentPane().add(mainPanel);
mainPanel.add(createOptionsPanel(), BorderLayout.NORTH);
mainPanel.add(createCenterPanel(), BorderLayout.CENTER);
mainPanel.add(createOkCancelPanel(), BorderLayout.SOUTH);
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
close(false);
}
});
dialog.setSize(600, 750);
dialog.setLocationRelativeTo(dialog.getParent());
}
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);
}
private static void append(String s) {
if (frame == null) {
// FIXME: The frame title should be a localized string.
frame = new JFrame("JConsole: Output");
ta = new JTextArea();
ta.setEditable(false);
frame.getContentPane().add(new JScrollPane(ta));
ta.setFont(new Font("Monospaced", Font.BOLD, 14));
frame.setSize(500, 600);
frame.setLocation(1024-500, 768-600);
// Exit JConsole if no window remains.
// e.g. jconsole -version only creates the OutputViewer
// but no other window.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (JFrame.getFrames().length == 1) {
System.exit(0);
}
}
});
}
ta.append(s);
ta.setCaretPosition(ta.getText().length());
frame.setVisible(true);
}
private void loadComparisonPNG( String fileName ) {
try {
BufferedImage image =
javax.imageio.ImageIO.read(new File(fileName));
JFrame f = new JFrame( "Comparison PNG" );
ImagePanel ip = new ImagePanel( image );
f.setResizable( false );
f.getContentPane().add( ip );
f.addWindowListener( new WindowAdapter() {
public void windowClosing( WindowEvent e ) {
( (JFrame) e.getSource() ).dispose();
}
});
f.pack();
f.show();
}
catch ( Exception ex ) {
fireChangeStatus( "ERROR: Failed to Load PNG File; See Stack Trace", true );
ex.printStackTrace();
}
}
private static void append(String s) {
if (frame == null) {
// FIXME: The frame title should be a localized string.
frame = new JFrame("JConsole: Output");
ta = new JTextArea();
ta.setEditable(false);
frame.getContentPane().add(new JScrollPane(ta));
ta.setFont(new Font("Monospaced", Font.BOLD, 14));
frame.setSize(500, 600);
frame.setLocation(1024-500, 768-600);
// Exit JConsole if no window remains.
// e.g. jconsole -version only creates the OutputViewer
// but no other window.
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (JFrame.getFrames().length == 1) {
System.exit(0);
}
}
});
}
ta.append(s);
ta.setCaretPosition(ta.getText().length());
frame.setVisible(true);
}
public GLVisualProcessorDemo() {
frame = new Frame("JOGL Tester");
frame.setSize(1920, 1080);
frame.setResizable(false);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
frame.dispose();
System.exit(0);
}
});
}