62,623
社区成员
发帖
与我相关
我的任务
分享
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;
}
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();
}
});
}
test
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
}