所以我试图挑战自己并创建一个简单的文字处理器应用程序。我目前正在设置键盘并且在按键方面遇到了一些问题。我有一个包含每个字母的字符串数组,并希望将它们放在按钮上。
我现在有这个:
String FirstRow [] = {"q","w","e","r","t","y","u","i","o","p","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m"};
for(int i = 0; i < 40; i++)
{
if(i < 10)
{
JButton btn = new JButton();
Nums.add(btn);
btn.setText("" + Num);
Num++;
}
else
{
JButton btn1 = new JButton ();
Nums.add(btn1);
btn1.setText("" + FirstRow[n]);
n++;
}
}
如果没有 if 语句的 else 部分,它可以很好地将数字放入第一行。但是,当我尝试放置字母时,我得到了一个超出范围的异常,我不知道如何解决这个问题。