The code I have so far is as follows:
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.GridLayout;
import java.awt.FlowLayout;
public class GUI extends JFrame
{
private JButton button;
private JPanel panel;
private static final String[][] key = { { "Esc", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12", "PrtSc", "Insert", "Delete", "Home", "End", "PgUp", "PgDn"}, { "3\n2", "&", "é", "\"", "'", "(", "§", "è", "!", "ç", "à", ")", "-", "BkSpc", "NumLock", "/", "*", "-" }, { "Tab", "A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P", "^", "$", "Enter", "7", "8", "9", "+" }, { "ShiftLock", "Q", "S", "D", "F", "G", "H", "J", "K", "L", "M", "ù", "µ", "4", "5", "6" }, { "Shift", "<", "W", "X", "C", "V", "B", "N", ",", ";", ":", "=", "Shift", "Up", "1", "2", "3", "Enter" }, { "Ctrl", "Fn", "Win", "Alt", "Space", "AltGr", "Context", "Ctrl", "Left", "Down", "Right", "0", "." } };
public GUI()
{
super( "Typing Tutor" );
setLayout( new GridLayout( key.length, 0 ) );
for ( int row = 0; row < key.length; row++)
{
panel = new JPanel();
panel.setLayout(new FlowLayout());
for ( int column = 0; column < key[ row ].length; column++ )
{
button = new JButton( key[ row ][ column ] );
panel.add( button );
}
add( panel );
}
}
}
==================================================================
import javax.swing.JFrame;
public class GUITest extends JFrame
{
public static void main(String[] args)
{
GUI gui = new GUI();
gui.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
gui.setSize( 1600, 250 );
gui.setVisible( true );
}
}
It shows keys in correct rows but not exactly as it is. For example enter button is not rectangular and one rowed. Any suggestions to improve it?
PS: What I am trying to do is create an typing tutor that acts as a normal text editor or better yet a program that passes keystrokes across other programs while I can still see visual keyboard on screen for reference (and feedback). Just to make sure that I don't have to look at real keyboard and can always practice touch typing. If you have beter suggestions/alternatives or know if its possible or not, do let me know.