[code]
private JFrame getJFrame() {
if (jFrame == null) {
Toolkit tk=Toolkit.getDefaultToolkit();
Image img=tk.getImage("PIC/1.jpg");
jFrame = new JFrame(); jFrame.setIconImage(img);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(300, 200);
//jFrame.setResizable(false);禁止标题最大化按钮
jFrame.setContentPane(getJContentPane());
jFrame.setTitle("Application");
}
return jFrame;
}
[/code]
这是JFRAME代码 我想捕获关闭按钮事件 然后弹出一个确认dialog....
[code]
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Test application = new Test();
//application.getJFrame().setVisible(true);
application.getJLabel().show();
application.getJFrame().show();
}
});
}
[/code]
这是MAIN函数 我想让程序显示一个Label 可不对 不知道怎么写这个main 求大虾帮忙!!!!!!!!!!!!!
private JFrame getJFrame() {
if (jFrame == null) {
Toolkit tk=Toolkit.getDefaultToolkit();
Image img=tk.getImage("PIC/1.jpg");
jFrame = new JFrame(); jFrame.setIconImage(img);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setJMenuBar(getJJMenuBar());
jFrame.setSize(300, 200);
//jFrame.setResizable(false);禁止标题最大化按钮
jFrame.setContentPane(getJContentPane());
jFrame.setTitle("Application");
}
return jFrame;
}
[/code]
这是JFRAME代码 我想捕获关闭按钮事件 然后弹出一个确认dialog....
[code]
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Test application = new Test();
//application.getJFrame().setVisible(true);
application.getJLabel().show();
application.getJFrame().show();
}
});
}
[/code]
这是MAIN函数 我想让程序显示一个Label 可不对 不知道怎么写这个main 求大虾帮忙!!!!!!!!!!!!!
下面的程序运行时呈现了一个JLabel以及点击关闭按钮弹出确认对话框...
package mobi.chenwei.test;import javax.swing.JOptionPane;public class MainFrame extends javax.swing.JFrame {
/** Creates new form MainFrame */
public MainFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() { jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
setTitle("www.chenwei.mobi");
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
}); jLabel1.setText("This is a label!");
getContentPane().add(jLabel1, java.awt.BorderLayout.CENTER); pack();
}// </editor-fold> private void formWindowClosing(java.awt.event.WindowEvent evt) {
int option = JOptionPane.showConfirmDialog(this, "Do you want to close this window?", "www.chenwei.mobi", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(option == JOptionPane.YES_OPTION){
this.dispose();
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
[code]
test
[/code]