由于最近才开始学java,想做个小应用,在一个界面上出了问题,向容器中添加的组件为什么没有不显示呢!?求各位高手指点指点,谢谢!!
代码如下:
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class fdsf
{
private JFrame jframe = new JFrame("选择操作窗口");
private Container c = jframe.getContentPane();
private JLabel jlabel = new JLabel("请选择将要进行的操作:");
private JPanel jpanelLabel = new JPanel();
private JButton jbutton1 = new JButton(" 学生信息注册 ");
private JButton jbutton2 = new JButton(" 学生成绩查询 ");
private JPanel jpanelButton1 = new JPanel();
private JPanel jpanelButton2 = new JPanel();
public void initial0()
{
jframe.setSize(300,200);
c.setLayout(new BorderLayout());
jpanelLabel.setLayout(null);
jlabel.setBounds(50, 20, 50, 20);
jpanelLabel.add(jlabel);
c.add(jpanelLabel,"North");
jpanelButton1.setLayout(null);
jbutton1.setBounds(60,40,50,20);
jpanelButton1.add(jbutton1);
c.add(jpanelButton1,"Center");
jpanelButton2.setLayout(null);
jbutton2.setBounds(60,60,50,20);
jpanelButton2.add(jbutton1);
c.add(jpanelButton2,BorderLayout.SOUTH);
jframe.setVisible(true);
}
public static void main(String[] args)
{
sumarizeWindows sw = new sumarizeWindows();
sw.initial0();
}
}
运行结果如下:
请问是什么原因,如何改正啊!?
------解决方案--------------------
你的panel没有填到frame
------解决方案--------------------
将程序中的那几行 jpanelLabel.setLayout(null);给注释掉;
还有 jpanelButton2.add(jbutton1);
jpanelButton1.add(jbutton1);
是不是重复了