Java Swing窗口将不会出现

问题描述

您需要将其设置为可见。用:

setVisible(true)

解决方法

好的,谦卑来了。自从我使用Java
Swing已有很长时间了,所以我知道有一些非常明显的解决方案。我想做的是让所有这些不同的摆动元素出现在窗口中。当我运行代码时,什么也没有发生。我什么也没看到。每次我用google搜索答案时,都会得到有关各种复杂的JPanel问题的信息,我几乎肯定这不是一个难题。所以这是我的代码:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;


public class LimoSysDriver extends JFrame implements ActionListener {

    /**
     * @param args
     */
    JLabel title = new JLabel("Thread Test Application");

    JLabel numOne = new JLabel("1");
    JLabel numTwo = new JLabel("2");
    JLabel numThr = new JLabel("3");
    JLabel numFou = new JLabel("4");

    JProgressBar progOne = new JProgressBar();
    JProgressBar progTwo = new JProgressBar();
    JProgressBar progThr = new JProgressBar();
    JProgressBar progFou = new JProgressBar();

    JLabel counterOne = new JLabel(Integer.toString(progOne.getValue()));
    JLabel counterTwo = new JLabel(Integer.toString(progTwo.getValue()));
    JLabel counterThr = new JLabel(Integer.toString(progThr.getValue()));
    JLabel counterFou = new JLabel(Integer.toString(progFou.getValue()));

    JLabel numGrandTot = new JLabel("Grand Total");
    JLabel counterTot = new JLabel();

    JButton start = new JButton();
    JButton pause = new JButton();
    JButton resume = new JButton();


    public LimoSysDriver(){
        setSize(700,300);
        JPanel pane = new JPanel();
        pane.setLayout(new BoxLayout(pane,BoxLayout.PAGE_AXIS));
        add(pane);
        JPanel lowerPanel = new JPanel();
        lowerPanel.setLayout(new BoxLayout(lowerPanel,BoxLayout.LINE_AXIS));
        add(lowerPanel);

        pane.add(title);
        pane.add(numOne);
        pane.add(progOne);
        pane.add(counterOne);

        pane.add(numTwo);
        pane.add(progTwo);
        pane.add(counterTwo);

        pane.add(numThr);
        pane.add(progThr);
        pane.add(counterThr);

        pane.add(numFou);
        pane.add(progFou);
        pane.add(counterFou);


    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        LimoSysDriver window = new LimoSysDriver();

    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        // TODO Auto-generated method stub

    }

}

问题是,该窗口根本不显示。一旦可以解决该问题,便可以对其余问题进行故障排除。预先感谢大家。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...