屏幕键盘gui无法正常工作

时间:2012-11-17 05:49:56

标签: java swing jbutton grid-layout border-layout

我正在尝试在顶部显示一个textarea,在它下面显示Keyboard键,但是当我运行这段代码时,整个事情就变得混杂了。我做错了什么,我该如何解决?这是代码:

public Keyboard()
{
    super("Typing Tutor");

    pane1= new JPanel();
    pane2= new JPanel();
    pane3= new JPanel();
    pane4= new JPanel();
    pane5= new JPanel();
    pane6= new JPanel();

    glayout= new GridLayout(5,14);
    text= new JTextArea(770,300);

    text.setFocusable(true);

    Handler = new HandlerClass();

    pane1.add(text);

    setLayout(glayout);

    but= new JButton[57];

    AssignLettersToButtons();

    text.addKeyListener(Handler);

    add(pane1,BorderLayout.NORTH);
    add(pane2);
    add(pane3);
    add(pane4);
    add(pane5);
    add(pane6);

}

private void AssignLettersToButtons()
{       
    for(int i=0;i<names.length;i++)
    {
        if(i<14)
        {
            but[i]=new JButton(names[i]);
            pane1.add(but[i]);
        }
  }

enter image description here

1 个答案:

答案 0 :(得分:3)

设计可能需要至少3个面板。如下面的enter image description here