我正在尝试在顶部显示 textarea 并在其下方显示键盘键,但是当我运行此代码时,整个事情都是混合的。我做错了什么,我该如何解决?这是代码:
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]);
}
}