Topic: please help me!

  Print this page

1.please help me! Copy to clipboard
Posted by: 随风之幻
Posted on: 2006-05-25 18:18

import java.awt.*;
import javax.swing.*;

public class TestPanels extends JFrame
{
//Default constructor
public TestPanels()
{
Container container=getContentPane();

//
container.setLayout(new BorderLayout());

JPanel p1=new JPanel();
p1.setLayout(new GridLayout(4,3));

for(int i=1;i<=9;i++)
{
p1.add(new JButton(" "+i));
}

p1.add(new JButton(" "+0));
p1.add(new JButton("Start"));
p1.add(new JButton("Stop"));

JPanel p2=new JPanel();
p2.setLayout(new BorderLayout());
p2.add(new JTextField("Time to be displayed here"),BorderLayout.NORTH);
p2.add(p1,BorderLayout.CENTER);
}

public static void main(String[] args)
{
TestPanels frame=new TestPanels();
frame.setTitle("The Front view of a Microwave OVen");
frame.setSize(400,250);
frame.setVisible(true);
}
}
this is a program in a book.but the result is not what I look forward to.
why I can't see nothing except a blank frame?
please tell me what's wrong with this program.
thank you~

2.Re:please help me! [Re: 随风之幻] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-05-26 10:02

In your Default constructor .
you should add these two sentence"container.add(p1,BorderLayout.NORTH);
    container.add(p2,BorderLayout.CENTER);"


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923