當我在Netbeans中創建新的JFrame時,會自動創建一個主類。即使我把它放在/* */
內,代碼也能正常工作。我在任何Java程序中學到,只有一個主類是程序的起點。netbeans GUI設計中的新JFrame中自動生成的「主」類
- JFrame中主類的用法是什麼?
- 如果我保留或刪除它,是否有任何問題?
- 什麼時候可以調用主類中的代碼?
// public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
/* try {
System.out.println("111111111111111");
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Welcome.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
/* Create and display the form
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
//welcomeUser.setText("Welcome");
System.out.println("111111111111111");
//new Welcome().setVisible(true);
System.out.println("333333333333333");
}
});*/
// }
在編寫JUnit之前,通常會將測試代碼放入要測試的類的主要方法中。幸運的是,這已經過時了。 – 2013-05-08 02:35:05