Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我的自定义JDialog将出现,但为空_Java_Swing_Jdialog - Fatal编程技术网

Java 我的自定义JDialog将出现,但为空

Java 我的自定义JDialog将出现,但为空,java,swing,jdialog,Java,Swing,Jdialog,在我的程序中的某一点上,它会打开一个JDialog,显示程序运行时发生的事情的相关信息。它有几个标签和一个进度条,但是当对话框窗口打开时,它什么也不显示 以下是自定义对话框及其构造函数: public class DataMiner implements ActionListener { private Hashtable<Integer, GISNode> nodeTable; private Hashtable<Integer, GISLink> li

在我的程序中的某一点上,它会打开一个JDialog,显示程序运行时发生的事情的相关信息。它有几个标签和一个进度条,但是当对话框窗口打开时,它什么也不显示

以下是自定义对话框及其构造函数:

public class DataMiner implements ActionListener
{
    private Hashtable<Integer, GISNode> nodeTable;
    private Hashtable<Integer, GISLink> linkTable;
    private int numLinesIgnored;
    private int numLinesProcessed;
    private int numNodes;
    private int numLinks;
    private int numDuplicates; 
    private int numFailedGeoCodingRequests;
    private boolean cancelled;

// window objects 
    private JDialog window;
    private JLabel LinesIgnored;
    private JLabel LinesProcessed;
    private JLabel Nodes;
    private JLabel Links;
    private JLabel Duplicates; // tracks the number of equivalent data entries found.
    private JLabel FailedGeoCodingRequests;
    private JProgressBar progressBar;
    private JButton cancelButton;

    public DataMiner(JFrame parentWindow)
    {
        nodeTable = new Hashtable<Integer, GISNode>(1000);
        linkTable = new Hashtable<Integer, GISLink>(1000);

        numLinesIgnored = 0;
        numLinesProcessed = 0;
        numNodes = 0;
        numLinks = 0;
        numDuplicates = 0; 
        numFailedGeoCodingRequests = 0;
        cancelled = false;

        LinesIgnored = new JLabel();
        LinesProcessed = new JLabel();
        Nodes = new JLabel();
        Links = new JLabel();
        Duplicates = new JLabel();
        FailedGeoCodingRequests = new JLabel();
        cancelButton = new JButton("Cancel");
        progressBar = new JProgressBar();

        updateLabels(); // assigns a formatted string to each JLabel
        cancelButton.addActionListener(this);

    // initialize window
        window = new JDialog(parentWindow);
        window.setResizable(false);
        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        Container content = window.getContentPane();
        content.setLayout(new GridLayout(7,1));
        content.add(LinesProcessed);
        content.add(Nodes);
        content.add(Links);
        content.add(Duplicates);
        content.add(LinesIgnored);
        content.add(FailedGeoCodingRequests);
        content.add(progressBar);
        JPanel p1 = new JPanel();
        p1.add(new JLabel("")); // takes up space
        p1.add(cancelButton);
        content.add(p1);
        window.pack();
        window.setLocationRelativeTo(parentWindow);
        window.setVisible(true);
    }

    (rest of the class...)
}
公共类DataMiner实现ActionListener
{
私有哈希表节点表;
私有哈希表链接表;
私人国际货币基金组织;
私有整数处理;
私有内节点;
私有整数链接;
私有整数倍;
私有int numFailedGeoCodingRequests;
取消私有布尔值;
//窗口对象
私有JDialog窗口;
私人JLabel行签名;
私人JLabel线路处理;
专用JLabel节点;
专用JLabel链接;
private JLabel Duplicates;//跟踪找到的等效数据项的数量。
私人JLabel FailedGeocoding请求;
私人JProgressBar progressBar;
私有JButton取消按钮;
公共数据挖掘器(JFrame parentWindow)
{
nodeTable=新哈希表(1000);
linkTable=新哈希表(1000);
numLinesIgnored=0;
numlineprocessed=0;
珠心=0;
numLinks=0;
numDuplicates=0;
numFailedGeoCodingRequests=0;
取消=错误;
linesigned=新的JLabel();
LinesProcessed=新的JLabel();
节点=新的JLabel();
Links=新的JLabel();
重复项=新的JLabel();
FailedGeoCodingRequests=新的JLabel();
cancelButton=新按钮(“取消”);
progressBar=新的JProgressBar();
updateLabels();//为每个JLabel分配一个格式化字符串
cancelButton.addActionListener(此);
//初始化窗口
窗口=新JDialog(父窗口);
window.setresizeable(false);
window.setDefaultCloseOperation(JFrame.DISPOSE\u ON\u CLOSE);
容器内容=window.getContentPane();
content.setLayout(新的GridLayout(7,1));
content.add(行处理);
添加(节点);
添加(链接);
内容。添加(副本);
内容。添加(行签名);
内容。添加(FailedGeoCodingRequests);
content.add(progressBar);
JPanel p1=新的JPanel();
p1.添加(新JLabel(“”);//占用空间
p1.添加(取消按钮);
内容。添加(p1);
window.pack();
window.setLocationRelativeTo(父窗口);
window.setVisible(true);
}
(班上其他同学…)
}

一旦此窗口打开,程序的其余部分将继续正常执行,只是此窗口为空。我遗漏了什么吗?真奇怪。这段代码对我来说工作得很好,意思是显示一个空的主窗口(正确)和“弹出”子框架窗口(您说不适合您)。我在Ubuntu下使用了NetBeans 6.8和Java 1.6:

package javaapplication2;

import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class MainFrame extends javax.swing.JFrame {

    private int numLinesIgnored;
    private int numLinesProcessed;
    private int numNodes;
    private int numLinks;
    private int numDuplicates;
    private int numFailedGeoCodingRequests;
    private boolean cancelled;

// window objects
    private JDialog window;
    private JLabel LinesIgnored;
    private JLabel LinesProcessed;
    private JLabel Nodes;
    private JLabel Links;
    private JLabel Duplicates; // tracks the number of equivalent data entries found.
    private JLabel FailedGeoCodingRequests;
    private JProgressBar progressBar;
    private JButton cancelButton;

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();

        JFrame parentWindow = this;


        numLinesIgnored = 0;
        numLinesProcessed = 0;
        numNodes = 0;
        numLinks = 0;
        numDuplicates = 0;
        numFailedGeoCodingRequests = 0;
        cancelled = false;

        LinesIgnored = new JLabel();
        LinesProcessed = new JLabel();
        Nodes = new JLabel();
        Links = new JLabel();
        Duplicates = new JLabel();
        FailedGeoCodingRequests = new JLabel();
        cancelButton = new JButton("Cancel");
        progressBar = new JProgressBar();

    // initialize window
        window = new JDialog(parentWindow);
        window.setResizable(false);
        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        Container content = window.getContentPane();
        content.setLayout(new GridLayout(7,1));
        content.add(LinesProcessed);
        content.add(Nodes);
        content.add(Links);
        content.add(Duplicates);
        content.add(LinesIgnored);
        content.add(FailedGeoCodingRequests);
        content.add(progressBar);
        JPanel p1 = new JPanel();
        p1.add(new JLabel("")); // takes up space
        p1.add(cancelButton);
        content.add(p1);
        window.pack();
        window.setLocationRelativeTo(parentWindow);
        window.setVisible(true);
    }

    /** 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">
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

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

    /**
    * @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
    // End of variables declaration

}
PackageJavaApplication2;
导入java.awt.Container;
导入java.awt.GridLayout;
导入javax.swing.JButton;
导入javax.swing.JDialog;
导入javax.swing.JFrame;
导入javax.swing.JLabel;
导入javax.swing.JPanel;
导入javax.swing.JProgressBar;
公共类大型机扩展了javax.swing.JFrame{
私人国际货币基金组织;
私有整数处理;
私有内节点;
私有整数链接;
私有整数倍;
私有int numFailedGeoCodingRequests;
取消私有布尔值;
//窗口对象
私有JDialog窗口;
私人JLabel行签名;
私人JLabel线路处理;
专用JLabel节点;
专用JLabel链接;
private JLabel Duplicates;//跟踪找到的等效数据项的数量。
私人JLabel FailedGeocoding请求;
私人JProgressBar progressBar;
私有JButton取消按钮;
/**创建新表单大型机*/
公共主机(){
初始化组件();
JFrame parentWindow=这个;
numLinesIgnored=0;
numlineprocessed=0;
珠心=0;
numLinks=0;
numDuplicates=0;
numFailedGeoCodingRequests=0;
取消=错误;
linesigned=新的JLabel();
LinesProcessed=新的JLabel();
节点=新的JLabel();
Links=新的JLabel();
重复项=新的JLabel();
FailedGeoCodingRequests=新的JLabel();
cancelButton=新按钮(“取消”);
progressBar=新的JProgressBar();
//初始化窗口
窗口=新JDialog(父窗口);
window.setresizeable(false);
window.setDefaultCloseOperation(JFrame.DISPOSE\u ON\u CLOSE);
容器内容=window.getContentPane();
content.setLayout(新的GridLayout(7,1));
content.add(行处理);
添加(节点);
添加(链接);
内容。添加(副本);
内容。添加(行签名);
内容。添加(FailedGeoCodingRequests);
content.add(progressBar);
JPanel p1=新的JPanel();
p1.添加(新JLabel(“”);//占用空间
p1.添加(取消按钮);
内容。添加(p1);
window.pack();
window.setLocationRelativeTo(父窗口);
window.setVisible(true);
}
/**此方法从构造函数中调用,以
*初始化表单。
*警告:请勿修改此代码。此方法的内容为
*始终由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
// 
私有组件(){
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout=newjavax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(布局);
layout.setHorizontalGroup(
createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0,400,短。最大值)
);
layout.setVerticalGroup(
layout.cr