English 中文(简体)
如何使关闭JPanel触发一种方法
原标题:how to make closing JPanel trigger a method
  • 时间:2012-04-23 23:20:57
  •  标签:
  • jpanel

I got an example of JPanel from the Oracle tutorials I see it uses a default method to close the window

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

我想的是,在点击了近东时关闭窗口,以触发另一种方法。

我如何能够这样做?

最佳回答
frame.addWindowListener(new WindowAdapter() {
  public void windowClosing(WindowEvent e) {
    //do something
  }
});

见:

问题回答

当你试图终止“游轮”或“青少年”方案时,该法典将予以执行。

Runtime.getRuntime().addShutdownHook(new Thread()
{
    @Override
    public void run()
    {
        //code goes here
    }
});




相关问题
java grid bag layout: avoiding center alignment

In my GUI application, I have several JPanels that are instantiated at various points during the running of my program, and certain actions will cause one of them to be displayed in a scroll pane: ...

Convert a region of a JPanel into a BufferedImage

I need to convert a certain region of an jpanel into a bufferedImage, or other format to be shown in another jpanel. By now, I only saw codes that converts the whole jpanel into a bufferedImage, but ...

Java JTabbedPane questions

I m using a JTabbedPane to hold each step in the wizard that I am building. Navigation between steps is doing using the Previous/Next buttons or by selecting a tab. The buttons decrement/increment ...

How to draw a JPanel on a canvas?

is there a possibility to draw a JPanel on a specific location op a Graphics (or Graphics2D) object? I override the paint method of my canvas, and call panel.paint(g) in there, but it does not work ...

How to paint a gridline as a background on JPanel

I have a problem. I used Gridbaglayout in my JFrame. One of the component is JPanel. I wanted to draw a gridline as a background for my JPanel. e.g in the program below, it supposed to produce 3 ...

why isn t my Jlabels or Jpanels showing?

i ve added a title to my Jframe, and now its blocked everything else, what have I done?? public class addressbook { public JFrame frame; public JButton btnadd, btndelete, btnsave, btnprev, btnnext; ...

adding JLayeredPane to JPanel

I am trying to add a JLayeredPane to a JPanel and then add an image (JLabel icon) and a button to the JLayeredPane, but neither show up. I ve tested the image without the button and the layeredpane ...

热门标签