如何将JPanel添加到JFrame [英] How to add JPanel in to JFrame

查看:99
本文介绍了如何将JPanel添加到JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我在Java中有2个课程.
1)扩展Jframe的类
2)另一种扩展JPanel

我尝试在JFram类中添加JPanel,它看起来像这样:

Hello,
i have 2 classes in java.
1)a class that extends Jframe
2)another that extends JPanel

I try to add the JPanel in the JFram class , it looks something like this:

public static void main(String args[]) { // the main is in the JFram class
        Othello Oth= new Othello();    // instance of the JFram class
        Oth.setLocation(250, 150);
        OthelloBoard OB = new OthelloBoard();     // instance of JPanel class
        Oth.add(OB);
        Oth.setVisible(true);



但是只显示了JFrame,而且看来我添加的JPanel并没有进入JFrame(我正在使用NetBeans).

我该如何解决这个问题?

谢谢...



but only the JFrame got shown and it seems that the JPanel i added did not go onto the JFrame (i am using NetBeans).

How can I solve this problem??

Thank you...

推荐答案

这可能对您没有帮助,请回复,
This could help you no then please reply,
public static void main(String args[]) { 
// the main is in the JFram class        
Othello Oth= new Othello();    // instance of the JFram class       
 Oth.setLocation(250, 150);        
OthelloBoard OB = new OthelloBoard();   // instance of JPanel class        
Oth.setLayout(new GridLayout(1,1));

///Oth.add(OB,BorderLayout.CENTER);
//Oth.setContentPane( BorderLayout.CENTER);
Oth.setVisible(true);



并请

查看这个将面板添加到框架的经典示例

面板到框架
[ ^ ]



and please

review this classic example of adding panel to frame

panel to frame
[^]


任何人都可以帮我..

我应用了santosh dhanawade解决方案,但没有成功.

这是两个主要方面:

Othello.Java
Can any one help me please ..

I applied the santosh dhanawade solution but it didn''t work.

this is the two main clasess:

Othello.Java
public class Othello extends javax.swing.JFrame {

    OthelloBoard OB;

    /** Creates new form Othello */

    public Othello() {

        initComponents();
        OB = new OthelloBoard();
        add(OB,BorderLayout.CENTER);
        setVisible(true);
}

public static void main(String args[]) {


            Othello Oth= new Othello();
            Oth.setLocation(250, 150);




    }


这篇关于如何将JPanel添加到JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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