Help with on screen keyboard Capslock
i have been making an on screen keyboard for my intro to JAVA class. the keyboard is very basic but, no matter what method i try i cannot get the toggle caps-lock button to work.
in the l.getSource() area for the bottom row(third loop) the 10th button in the array(9th by index) is the caps lock button, but no matter where i try to re-initialize the strings, they either have an error, or don't work as lower case letters Code:
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.*;
public class Keyboard extends Frame implements ActionListener
{
int place,length = 0;
int tries=0;
boolean capslock = true;
String topRow[] = {"Q","W","E","R","T","Y","U","I","O","P"};
String midRow[] = {"A","S","D","F","G","H","J","K","L","Enter"};
String botRow[] = {"Space","Z","X","C","V","B","N","M","Back","Lower"};
Button top[] = new Button[10];
Button mid[] = new Button[10];
Button bot[] = new Button[10];
Panel keys = new Panel();
Panel text = new Panel();
TextArea tArea = new TextArea();
String strText = "";
public Keyboard()
{
this.setLayout(new BorderLayout(1,1));
keys.setLayout(new GridLayout(3,10));
text.setLayout(new BorderLayout(1,1));
text.add(tArea);
for(int i=0; i<10; i++)
{
top[i] = new Button(topRow[i]);
top[i].setBackground(Color.white);
keys.add(top[i]);
top[i].addActionListener(this);
}
for(int i=0; i<10; i++)
{
mid[i] = new Button(midRow[i]);
mid[i].setBackground(Color.white);
keys.add(mid[i]);
mid[i].addActionListener(this);
}
for(int i=0; i<10; i++)
{
bot[i] = new Button(botRow[i]);
bot[i].setBackground(Color.white);
keys.add(bot[i]);
bot[i].addActionListener(this);
}
add(text, BorderLayout.NORTH);
add(keys,BorderLayout.CENTER);
addWindowListener(
new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public static void main(String[] args)
{
Keyboard f = new Keyboard();
f.setBounds(100,100,500,400);
f.setTitle("Keyboard");
f.setVisible(true);
}
public void actionPerformed(ActionEvent l)
{
for(int i=0;i<10;i++)
{
if(l.getSource() == top[i])strText = strText+topRow[i];
}
for(int i=0;i<10;i++)
{
if(l.getSource()== mid[i])
{
if(i == 9) strText = strText+"\n";
else strText = strText + midRow[i];
}
}
for(int i=0;i<10;i++)
{
if(l.getSource () == bot[i])
{
if(i == 0) strText = strText+" ";
if(i == 8)
{
length = strText.length();
strText = strText.substring(0,(length-1));
}
else
{
if(i == 9)
{
if(capslock == true) capslock = false;
if(capslock == false) capslock = true;
}else strText = strText +botRow[i];
}
}
}tArea.setText(strText);
}
}