问题
I am making a trying to display a textarea at the top and Keyboard keys below it, but when I run this code, the whole thing is mixed. What am I doing wrong and how can I solve it? Here is the code:
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]);
}
}
回答1:
Design it may take at least 3 panels. As in following
来源:https://stackoverflow.com/questions/13428104/on-screen-keyboard-gui-is-not-working