我想從批處理文件中啓動一個Java GUI(在Netbeans中創建),而不打開命令窗口。我一直在看最後一個小時,並試圖javaw
,start /B javaw
等,但沒有任何工作。有沒有人知道我在做什麼錯了?沒有控制檯窗口的Java運行GUI
run_GUI.BAT
@ECHO OFF
start /B javaw GUI -ORBInitialPort 1050 -ORBInitialHost localhost
PAUSE
GUI.java
import javax.swing.*;
/**
*
* @author
*/
public class GUI extends javax.swing.JFrame {
/**
* Creates new form GUI
*/
public GUI() {
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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
outerPanel = new javax.swing.JPanel();
upperInnerPanel = new javax.swing.JPanel();
gameWinsPanel = new javax.swing.JPanel();
wonLabel = new javax.swing.JLabel();
lostLabel = new javax.swing.JLabel();
gameWinsLabel = new javax.swing.JLabel();
gameLossesLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
textDisplay = new javax.swing.JTextArea();
gameButtonsPanel = new javax.swing.JPanel();
newGameButton = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
lowerInnerPanel = new javax.swing.JPanel();
optionButtonsPanel = new javax.swing.JPanel();
paperButtton = new javax.swing.JButton();
scissorsButton = new javax.swing.JButton();
stoneButton = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setMaximumSize(new java.awt.Dimension(500, 500));
setMinimumSize(new java.awt.Dimension(500, 0));
setPreferredSize(new java.awt.Dimension(600, 657));
getContentPane().setLayout(new java.awt.GridLayout());
outerPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "PAPER SCISSORS STONE", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 18))); // NOI18N
upperInnerPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
gameWinsPanel.setLayout(new java.awt.GridBagLayout());
wonLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
wonLabel.setText("Won:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.ipady = 12;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 0);
gameWinsPanel.add(wonLabel, gridBagConstraints);
lostLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lostLabel.setText("Lost:");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipady = 12;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(6, 10, 11, 0);
gameWinsPanel.add(lostLabel, gridBagConstraints);
gameWinsLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
gameWinsLabel.setText("0");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.ipadx = 19;
gridBagConstraints.ipady = 12;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 57);
gameWinsPanel.add(gameWinsLabel, gridBagConstraints);
gameLossesLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
gameLossesLabel.setText("0");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.ipadx = 19;
gridBagConstraints.ipady = 12;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(6, 9, 11, 0);
gameWinsPanel.add(gameLossesLabel, gridBagConstraints);
textDisplay.setColumns(20);
textDisplay.setRows(5);
jScrollPane1.setViewportView(textDisplay);
gameButtonsPanel.setLayout(new java.awt.GridLayout(3, 0));
newGameButton.setText("New Game");
gameButtonsPanel.add(newGameButton);
jButton1.setText("Exit");
gameButtonsPanel.add(jButton1);
javax.swing.GroupLayout upperInnerPanelLayout = new javax.swing.GroupLayout(upperInnerPanel);
upperInnerPanel.setLayout(upperInnerPanelLayout);
upperInnerPanelLayout.setHorizontalGroup(
upperInnerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, upperInnerPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(upperInnerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(upperInnerPanelLayout.createSequentialGroup()
.addComponent(gameButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(gameWinsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
upperInnerPanelLayout.setVerticalGroup(
upperInnerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, upperInnerPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(upperInnerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(upperInnerPanelLayout.createSequentialGroup()
.addComponent(gameWinsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(gameButtonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE))
.addContainerGap())
);
lowerInnerPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
optionButtonsPanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
optionButtonsPanel.setLayout(new java.awt.GridLayout());
paperButtton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
paperButtton.setText("PAPER");
optionButtonsPanel.add(paperButtton);
scissorsButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
scissorsButton.setText("SCISSORS");
optionButtonsPanel.add(scissorsButton);
stoneButton.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
stoneButton.setText("STONE");
optionButtonsPanel.add(stoneButton);
javax.swing.GroupLayout lowerInnerPanelLayout = new javax.swing.GroupLayout(lowerInnerPanel);
lowerInnerPanel.setLayout(lowerInnerPanelLayout);
lowerInnerPanelLayout.setHorizontalGroup(
lowerInnerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(lowerInnerPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(optionButtonsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
lowerInnerPanelLayout.setVerticalGroup(
lowerInnerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, lowerInnerPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(optionButtonsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout outerPanelLayout = new javax.swing.GroupLayout(outerPanel);
outerPanel.setLayout(outerPanelLayout);
outerPanelLayout.setHorizontalGroup(
outerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(outerPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(outerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(lowerInnerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(upperInnerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
outerPanelLayout.setVerticalGroup(
outerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(outerPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(upperInnerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(lowerInnerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(13, Short.MAX_VALUE))
);
getContentPane().add(outerPanel);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
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 {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel gameButtonsPanel;
private javax.swing.JLabel gameLossesLabel;
private javax.swing.JLabel gameWinsLabel;
private javax.swing.JPanel gameWinsPanel;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lostLabel;
private javax.swing.JPanel lowerInnerPanel;
private javax.swing.JButton newGameButton;
private javax.swing.JPanel optionButtonsPanel;
private javax.swing.JPanel outerPanel;
private javax.swing.JButton paperButtton;
private javax.swing.JButton scissorsButton;
private javax.swing.JButton stoneButton;
private javax.swing.JTextArea textDisplay;
private javax.swing.JPanel upperInnerPanel;
private javax.swing.JLabel wonLabel;
// End of variables declaration//GEN-END:variables
}
可能重複的[如何運行一個程序從一個批處理文件沒有控制檯打開後](http://stackoverflow.com/questions/ 324539/how-can-i-run-a-program-from-batch-file-without-the-console-open-after) – 2015-04-03 13:10:59
是的,我是個白癡。批處理中的暫停語句導致命令窗口保持打開狀態 – 2015-04-03 13:21:41
輕鬆自己......我們都有時會[意外失明](http://en.wikipedia.org/wiki/Inattentional_blindness)。 – 2015-04-03 13:35:04