无法显示多个JPanel [英] Failure to show multiple JPanels

查看:84
本文介绍了无法显示多个JPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我今天的问题就是这个问题。我正在尝试开发一个琐事游戏,为此我需要在屏幕上添加2个JPanels。问题,只有一个出现,特别是第一个初始化。我在这个网站上查了一些其他类似的问题,但无济于事。有想法该怎么解决这个吗? questionPanel和anotherPanel都是扩展JPanel的类。为什么两者都不会同时出现?

so today's question on my mind is this. I'm trying to develop a trivia game and to do so I need to add 2 JPanels to the screen. The problem, only one shows up, specifically the first one initialized. I checked out some other similar questions on this site but to no avail. Any ideas on how to fix this? questionPanel and anotherPanel both are classes that extend JPanel. Why won't both show up at the same time?

 import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Trivia extends JFrame{

    questionPanel qp;
    private JButton q1,q2,q3,q4;

    public Trivia(){
        setSize(600,600);
        setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        qp = new questionPanel();
        add(qp,BorderLayout.SOUTH);

        anotherPanel ap = new anotherPanel();
        add(ap,BorderLayout.NORTH);


    }

    public static void main(String args[]){
        Trivia t = new Trivia();
    }

}


推荐答案

在Trivia构造函数的末尾调用 setVisible(true);

Call setVisible(true); at the end of the Trivia constructor

这篇关于无法显示多个JPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆