本文整理汇总了Java中javax.swing.JFrame.addWindowListener方法的典型用法代码示例。如果您正苦于以下问题:Java JFrame.addWindowListener方法的具体用法?Java JFrame.addWindowListener怎么用?Java JFrame.addWindowListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFrame
的用法示例。
在下文中一共展示了JFrame.addWindowListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.swing.JFrame; //导入方法依赖的package包/类
/**
* 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);
}
示例2: main
import javax.swing.JFrame; //导入方法依赖的package包/类
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();
}
示例3: dispatch
import javax.swing.JFrame; //导入方法依赖的package包/类
/**
* 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);
}
示例4: TableExample2
import javax.swing.JFrame; //导入方法依赖的package包/类
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);
}
示例5: onJFrameClose_Disconnect
import javax.swing.JFrame; //导入方法依赖的package包/类
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.");
}
}
示例6: initLayerManager
import javax.swing.JFrame; //导入方法依赖的package包/类
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;
}
示例7: main2
import javax.swing.JFrame; //导入方法依赖的package包/类
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;
}
示例8: main
import javax.swing.JFrame; //导入方法依赖的package包/类
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);
}
示例9: WaitWindow
import javax.swing.JFrame; //导入方法依赖的package包/类
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) {}
}
}
}
示例10: main
import javax.swing.JFrame; //导入方法依赖的package包/类
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();
}
示例11: main
import javax.swing.JFrame; //导入方法依赖的package包/类
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();
}
}
});
}
示例12: WaitWindow
import javax.swing.JFrame; //导入方法依赖的package包/类
public WaitWindow(JFrame f) {
f.addWindowListener(this);
f.show();
if (!shown) {
synchronized(this) {
try {
wait(5000);
} catch (Exception e) {}
}
}
}
示例13: frameOpened
import javax.swing.JFrame; //导入方法依赖的package包/类
public void frameOpened(JFrame frame) {
if (!listenerAdded) {
frame.addWindowListener(myListener);
listenerAdded = true;
}
addToManager();
WindowMenuManager.setCurrentManager(this);
}
示例14: CompositionArea
import javax.swing.JFrame; //导入方法依赖的package包/类
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);
}
示例15: main
import javax.swing.JFrame; //导入方法依赖的package包/类
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);
}