好吧,這裏就是謙遜。我使用Java Swing已經很長時間了,所以我知道這個問題有一些非常明顯的解決方案。我想要做的是讓所有這些不同的擺動元素出現在窗口中。當我運行代碼時,沒有任何反應。我什麼都看不到。每當我回答Google的答案時,我都會得到關於各種複雜的JPanel問題的東西,而且我幾乎是積極的,這不是一個難題。所以這是我的代碼:Java Swing Window不會出現
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
}
}
問題是,窗口根本沒有顯示出來。一旦我能把它整理出來,我就可以解決其餘的問題。在此先感謝大家。
確保您在將所有內容添加到要顯示的窗格後結束操作 – Levenal