JPanel如何调用另一个JPanel?
如题,调用了JPanel之后显示结果有不对~~~
贴上代码:
import javax.swing.*;
import java.awt.*;
//import java.awt.event.*;
public class JFramePaneDemo {
public static void main(String[]args){
JFrame f=new JFrame("JFrame/JPanel测试");
f.setSize(250,250);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p1=new JPanel();
p1.setSize(100,100);
p1.setBackground(Color.RED);
JPanel p2=new JPanel();
p2.setSize(50,50);//图形比例和设置比例不相同?
p2.setBackground(Color.BLACK);
p1.add(p2);
Container cp=f.getContentPane();
cp.setLayout(null);
cp.add(p1);
}
}
100分求助~~