我要做的是将JLabel添加到applet中的JPanel。但是,我似乎无法让JLabel出现。我认为我的问题是我添加Jlabels的地方,我不是“刷新屏幕”而且它们不可见。
编辑我看到的图片:Picture of the panels
以下是代码: Main.java
public class Main extends JApplet{
/**
*
*/
private static final long serialVersionUID = -6568278275823927953L;
public void init() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
createGUI();
}
});
} catch(Exception e) {
System.err.println("createGUI did not complete!");
}
}
private void createGUI() {
this.setLayout(new GridLayout(2,1));
Quiz myQuiz = new Quiz();
Options myOption = new Options();
JLabel[] answers = new JLabel[16];
for(int i = 0; i < 16; i++)
{
answers[i] = new JLabel();
answers[i].setText("HI!");
answers[i].setOpaque(true);
myOption.add(answers[i]);
}
myQuiz.setOpaque(true);
myOption.setOpaque(true);
this.add(myQuiz);
this.add(myOption);
}
}
Options.java
public class Options extends JPanel
implements MouseListener {
/**
*
*/
private static final long serialVersionUID = 3701573579935678995L;
Font myFont = new Font("Serif", Font.BOLD | Font.ITALIC, 20);
GridLayout myLayout = new GridLayout(4,4);
int HALF_WIDTH = getWidth() / 2;
int HALF_HEIGHT = getHeight() / 2;
public void init() {
addMouseListener(this);
this.setLayout(myLayout);
}