JPanel出现在Netbeans调试中,但不在运行模式下

时间:2011-07-17 06:33:10

标签: java swing netbeans

我正在使用带有JDK1.6.0_25的NetBeans IDE 7.0。我正在尝试编译以下代码。当我在“调试项目”模式(Ctrl + F5)中运行此代码时,它工作正常。但是,如果我尝试按“运行项目”模式(F6)运行,我在屏幕上看不到任何面板和按钮。请帮忙。 代码:

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
}

此致 普拉卡什

1 个答案:

答案 0 :(得分:1)

确认您正确使用event dispatch thread。调试器有时会减慢速度,足以暴露出这种异常现象。