为什么按纽显示不出来,怎么才能显示
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 
import java.applet.*;
import java.awt.Graphics;
class FrameTest extends JFrame 

public FrameTest() 

super("校园网"); setVisible(true); 
setSize(240,120); 
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } 

class PanelTest extends FrameTest 

public JPanel pObj; 
 
public PanelTest() 

pObj=new JPanel(); 


class ButtonTest extends PanelTest 

JLabel labelName; 
JLabel labelPassword; 
JTextField textName; 
JTextField textPassword; 
JButton buttonObj1; 
JButton buttonObj2; 
JButton buttonObj3; 
public ButtonTest() 

labelName=new JLabel("user:"); 
labelPassword=new JLabel("password:"); 
textName=new JTextField(10); 
textPassword=new JTextField(6); 
buttonObj1=new JButton("登录:"); 
buttonObj2=new JButton("退出:"); 
buttonObj3=new JButton("充值:"); 
pObj.add(labelName); 
pObj.add(labelPassword); 
pObj.add(textName); 
pObj.add(textPassword); 
pObj.add(buttonObj1); 
pObj.add(buttonObj2); 
pObj.add(buttonObj3); 


class GridLayoutTest extends ButtonTest 

GridLayout layoutObj; 
public GridLayoutTest() 

layoutObj=new GridLayout(3,2,10,10); 
pObj.setLayout(layoutObj); 
} } 
public class J02_GridLayout 

public static void main(String[] args) 

new GridLayoutTest(); 

}

解决方案 »

  1.   

    鉴定完毕:楼主看来是在无聊的乱用继承。。
    修改如下:
    import java.awt.GridLayout;import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;class FrameTest extends JFrame
    {
    public FrameTest()
    {
    super("SSS");
    }
    }class PanelTest extends FrameTest
    {
    public JPanel pObj; public PanelTest()
    {
    pObj = new JPanel();
                      pObj.setLayout(new GridLayout(3, 2, 10, 10));//先设置Layout
    }
    }class ButtonTest extends PanelTest
    {
    JLabel labelName; JLabel labelPassword; JTextField textName; JTextField textPassword; JButton buttonObj1; JButton buttonObj2; JButton buttonObj3; public ButtonTest()
    {
    labelName = new JLabel("user:");
    labelPassword = new JLabel("password:");
    textName = new JTextField(10);
    textPassword = new JTextField(6);
    buttonObj1 = new JButton("Login:");
    buttonObj2 = new JButton("Logout:");
    buttonObj3 = new JButton("Recharge:");
    pObj.add(labelName);
    pObj.add(labelPassword);
    pObj.add(textName);
    pObj.add(textPassword);
    pObj.add(buttonObj1);
    pObj.add(buttonObj2);
    pObj.add(buttonObj3);
    }
    }class GridLayoutTest extends ButtonTest
    {
    GridLayout layoutObj; public GridLayoutTest()
    {
    layoutObj = new GridLayout(3, 2, 10, 10);
    pObj.setLayout(layoutObj);
    this.add(pObj);/////////Panel需要被加到JFrame的
    }}public class J02_GridLayout
    {
    public static void main(String[] args)
    {
    JFrame frame = new GridLayoutTest();
    frame.setSize(400, 200);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);//////设置完大小之后再显示
    }
    }