2011-07-17 107 views
1

我正在使用NetBeans IDE 7.0和JDK1.6.0_25。我正在編譯下面的代碼。當我在「調試項目」模式(Ctrl + F5)中運行此代碼時,它工作正常。但是,如果我嘗試通過「運行項目」模式(F6)運行,屏幕上看不到任何面板和按鈕。請幫忙。 代碼:JPanel在Netbeans調試中出現,但不在運行模式下

package pss; 

import java.awt.Dimension; 
import java.awt.Toolkit; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.swing.ImageIcon; 
import javax.swing.BorderFactory; 
import java.io.IOException; 
import java.io.FileNotFoundException; 
import org.lirc.util.*; 
import org.lirc.LIRCException; 

public class ErrMessage extends javax.swing.JFrame { 

    public static SimpleLIRCClient client; 
    public static String configFile = "/etc/Remote.lirc"; 

    public ErrMessage(String ErrMessage, String ErrButton) { 

     initComponents(); 
     setLocationRelativeTo(null); 
     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
     setBounds(0, 0, screenSize.width, screenSize.height); 

     EPanel.setOpaque(false); 
     EPanel.setPreferredSize(screenSize); 
     EPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); 
     ImageIcon ii = new ImageIcon("/etc/assets/bg.jpg"); 
     wrapInBackgroundImage inBackgroundImageObj = new wrapInBackgroundImage(); 
     this.setContentPane(wrapInBackgroundImage.wrapInBackgroundImage(EPanel, ii)); 
     EMsgLabel.setText(ErrMessage); 
     EMsgLabel.setPreferredSize(screenSize); 
     EMsgButton.setText(ErrButton); 

     addRemoteListener(); 
     client.addIRActionListener(new IRListenerList()); 
     this.setVisible(true); 

    } 

    public static void addRemoteListener() { 
     try { 
      client = new SimpleLIRCClient(configFile); 
     } catch (LIRCException ex) { 
      Logger.getLogger(ErrMessage.class.getName()).log(Level.SEVERE, null, ex); 
     } catch (FileNotFoundException ex) { 
      Logger.getLogger(ErrMessage.class.getName()).log(Level.SEVERE, null, ex); 
     } catch (IOException ex) { 
      Logger.getLogger(ErrMessage.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 

    private class IRListenerList implements IRActionListener { 

     public void action(String command) { 
      if (command.equals("Ok")) {         // Proceed for selected item 
       selectOk(); 
      } 
     } 
    } 
public void selectOk() { 

    client.stopListening(); 
    this.setVisible(false); 

} 
    @SuppressWarnings("unchecked") 
    // <editor-fold defaultstate="collapsed" desc="Generated Code"> 
    private void initComponents() { 

     EPanel = new javax.swing.JPanel(); 
     EMsgLabel = new javax.swing.JLabel(); 
     EMsgButton = new javax.swing.JButton(); 

     setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); 
     setResizable(false); 
     setUndecorated(true); 

     EPanel.setBackground(new java.awt.Color(156, 172, 202)); 

     EMsgLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 36)); 
     EMsgLabel.setForeground(java.awt.Color.red); 
     EMsgLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); 
     EMsgLabel.setText("jLabel1"); 
     EMsgLabel.setInheritsPopupMenu(false); 
     EMsgLabel.setMaximumSize(new java.awt.Dimension(1000, 50)); 
     EMsgLabel.setMinimumSize(new java.awt.Dimension(1000, 50)); 

     EMsgButton.setBackground(java.awt.Color.yellow); 
     EMsgButton.setFont(new java.awt.Font("DejaVu Sans", 0, 18)); 
     EMsgButton.setText("jButton1"); 
     EMsgButton.setBorder(javax.swing.BorderFactory.createEtchedBorder()); 
     EMsgButton.setBorderPainted(false); 
     EMsgButton.setOpaque(true); 
     EMsgButton.addActionListener(new java.awt.event.ActionListener() { 
      public void actionPerformed(java.awt.event.ActionEvent evt) { 
       EMsgButtonActionPerformed(evt); 
      } 
     }); 

     javax.swing.GroupLayout EPanelLayout = new javax.swing.GroupLayout(EPanel); 
     EPanel.setLayout(EPanelLayout); 
     EPanelLayout.setHorizontalGroup(
      EPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(EPanelLayout.createSequentialGroup() 
       .addContainerGap() 
       .addGroup(EPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER) 
        .addComponent(EMsgButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE) 
        .addComponent(EMsgLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 740, Short.MAX_VALUE)) 
       .addContainerGap()) 
     ); 
     EPanelLayout.setVerticalGroup(
      EPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(EPanelLayout.createSequentialGroup() 
       .addGap(118, 118, 118) 
       .addComponent(EMsgLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE) 
       .addGap(40, 40, 40) 
       .addComponent(EMsgButton, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE) 
       .addContainerGap(302, Short.MAX_VALUE)) 
     ); 

     javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 
     getContentPane().setLayout(layout); 
     layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(layout.createSequentialGroup() 
       .addContainerGap() 
       .addComponent(EPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
       .addContainerGap()) 
     ); 
     layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 
       .addContainerGap() 
       .addComponent(EPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 
       .addContainerGap()) 
     ); 

     pack(); 
    }// </editor-fold> 

    private void EMsgButtonActionPerformed(java.awt.event.ActionEvent evt) {           
     selectOk(); 
    }           

    // Variables declaration - do not modify 
    private javax.swing.JButton EMsgButton; 
    private javax.swing.JLabel EMsgLabel; 
    private javax.swing.JPanel EPanel; 
    // End of variables declaration 
} 

問候 普拉卡什

回答

相關問題