Question

I am getting an error illegal start of expression in the code below, at line -> public class hindilang , I have seen other questions and answers on this site, but i don't know where i am going wrong ??

    abstract class lang extends JFrame implements KeyListener
    {
    boolean flag=false;
    String firstRow[] = {">","=","*","_","<","{","(","'","?","-","!","[",")"};
    String secondRow[] = {"|","#",".",":","&","@","]","/","}",",","$","^","~"};
    String thirdRow[] = {"d","v","m","y","e","k","a","j","z","3","0","9"};
    String fourthRow[] = {"r","b","p","o","h","w","g","x","1","7","5","4"};
    String fifthRow[] = {"f","c","n","s","l","t","q","u","i","6","2","8"};
    String sixthRow[] = {"Space","Back","Capslock","Clear","Show me mappings"};
    JButton first[] = new JButton[13];
    JButton second[] = new JButton[13];
    JButton third[] = new JButton[12];
    JButton fourth[] = new JButton[12];
    JButton fifth[]=new JButton[12];
    JButton sixth[]=new JButton[5];
    int count=0;
    Panel main = new Panel();
    Panel keys1 = new Panel();
    Panel keys2 = new Panel();
    Panel keys3 = new Panel();
    Panel keys4 = new Panel();
    Panel keys5 = new Panel();
    Panel keys6 = new Panel();
    Panel text = new Panel();
    TextArea textArea = new TextArea();
    String strText = "";
    private JLabel label1;
    private JLabel label2;
    private JTextField textField;

    public lang()
    {
    super("Typing Application");
    label1 = new JLabel("Type some text using your keyboard. The keys you press will be
    "+ "highlighed and the text will be displayed");
    add(label1);
    label2 = new JLabel("Note: clicking the buttons with your mouse will not perform
    any action");
    add(label2);
    textField = new JTextField(30);
    textField.setEditable(false);
    TextFieldHandler handler = new TextFieldHandler();
    this.setLayout(new BorderLayout(6,6));
    main.setLayout(new GridLayout(6,1));
    keys1.setLayout(new GridLayout(1,13));
    keys2.setLayout(new GridLayout(1,13));
    keys3.setLayout(new GridLayout(1,14));
    keys4.setLayout(new GridLayout(1,12));
    keys5.setLayout(new GridLayout(1,11));
    keys6.setLayout(new GridLayout(1,4));
    text.setLayout(new BorderLayout(1,1));
    text.add(textArea);

    for(int i=0; i<13; i++)
    {
    first[i] = new JButton(firstRow[i]);
    first[i].setSize(100,100);
    keys1.add(first[i]);
    first[i].addActionListener(new TextAreaHandler());
    }



    main.add(keys1);
    for(int i=0; i<13; i++)
    {
    second[i] = new JButton(secondRow[i]);
    second[i].setBackground(Color.white);
    keys2.add(second[i]);
    second[i].addActionListener(new TextAreaHandler());
    }

    main.add(keys2);

    for(int i=0; i<12; i++)
    {
    String t=i+"";
    String m="icon";
    String n=".gif";
    String s=m+t+n;
    ImageIcon img = new ImageIcon(s);
    third[i] = new JButton(img);
    keys3.add(third[i]);
    third[i].addActionListener(new TextAreaHandler());
    }

    main.add(keys3);
    int j=12;

    for(int i=0; i<12; i++)
    {
    String t=j+"";
    String m="icon";
    String n=".gif";
    String s=m+t+n;
    ImageIcon img = new ImageIcon(s);
    fourth[i] = new JButton(img);
    keys4.add(fourth[i]);
    j++;
    fourth[i].addActionListener(new TextAreaHandler());
    }

    public class hindilang
    {
       public static void hindi()
          {
             lang lang = new lang()
               {
                 public void keyTyped(KeyEvent e) 
                   {
                        throw new UnsupportedOperationException("Not supported yet.");
                   }
                 public void keyPressed(KeyEvent e) 
                   {
                        throw new UnsupportedOperationException("Not supported yet.");
                   }
                 public void keyReleased(KeyEvent e)
                   {
                        throw new UnsupportedOperationException("Not supported yet.");
                   }
               };
           }
    } 
            lang.setSize(800, 500); // set dimensions of window
            lang.setVisible(true);
    }
    }

The File is saved as hindilang.java and being compiled as javac hindilang.java, What am i doing wrong?? Please guide me

Tried the suggestions below but , still getting the same errors...

Was it helpful?

Solution

You public lang() constructor method is missing a '}' at the end of its method definition just before the problematic line

OTHER TIPS

You are missing } here is the corrected code

 abstract class lang extends JFrame implements KeyListener
{
boolean flag=false;
String firstRow[] = {">","=","*","_","<","{","(","'","?","-","!","[",")"};
String secondRow[] = {"|","#",".",":","&","@","]","/","}",",","$","^","~"};
String thirdRow[] = {"d","v","m","y","e","k","a","j","z","3","0","9"};
String fourthRow[] = {"r","b","p","o","h","w","g","x","1","7","5","4"};
String fifthRow[] = {"f","c","n","s","l","t","q","u","i","6","2","8"};
String sixthRow[] = {"Space","Back","Capslock","Clear","Show me mappings"};
JButton first[] = new JButton[13];
JButton second[] = new JButton[13];
JButton third[] = new JButton[12];
JButton fourth[] = new JButton[12];
JButton fifth[]=new JButton[12];
JButton sixth[]=new JButton[5];
int count=0;
Panel main = new Panel();
Panel keys1 = new Panel();
Panel keys2 = new Panel();
Panel keys3 = new Panel();
Panel keys4 = new Panel();
Panel keys5 = new Panel();
Panel keys6 = new Panel();
Panel text = new Panel();
TextArea textArea = new TextArea();
String strText = "";
private JLabel label1;
private JLabel label2;
private JTextField textField;

public lang()
{
super("Typing Application");
label1 = new JLabel("Type some text using your keyboard. The keys you press will be
"+ "highlighed and the text will be displayed");
add(label1);
label2 = new JLabel("Note: clicking the buttons with your mouse will not perform
any action");
add(label2);
textField = new JTextField(30);
textField.setEditable(false);
TextFieldHandler handler = new TextFieldHandler();
this.setLayout(new BorderLayout(6,6));
main.setLayout(new GridLayout(6,1));
keys1.setLayout(new GridLayout(1,13));
keys2.setLayout(new GridLayout(1,13));
keys3.setLayout(new GridLayout(1,14));
keys4.setLayout(new GridLayout(1,12));
keys5.setLayout(new GridLayout(1,11));
keys6.setLayout(new GridLayout(1,4));
text.setLayout(new BorderLayout(1,1));
text.add(textArea);

for(int i=0; i<13; i++)
{
first[i] = new JButton(firstRow[i]);
first[i].setSize(100,100);
keys1.add(first[i]);
first[i].addActionListener(new TextAreaHandler());
}



main.add(keys1);
for(int i=0; i<13; i++)
{
second[i] = new JButton(secondRow[i]);
second[i].setBackground(Color.white);
keys2.add(second[i]);
second[i].addActionListener(new TextAreaHandler());
}

main.add(keys2);

for(int i=0; i<12; i++)
{
String t=i+"";
String m="icon";
String n=".gif";
String s=m+t+n;
ImageIcon img = new ImageIcon(s);
third[i] = new JButton(img);
keys3.add(third[i]);
third[i].addActionListener(new TextAreaHandler());
}

main.add(keys3);
int j=12;

for(int i=0; i<12; i++)
{
String t=j+"";
String m="icon";
String n=".gif";
String s=m+t+n;
ImageIcon img = new ImageIcon(s);
fourth[i] = new JButton(img);
keys4.add(fourth[i]);
j++;
fourth[i].addActionListener(new TextAreaHandler());
}
}
}
public class hindilang
{
   public static void hindi()
      {
         lang lang = new lang()
           {
             public void keyTyped(KeyEvent e) 
               {
                    throw new UnsupportedOperationException("Not supported yet.");
               }
             public void keyPressed(KeyEvent e) 
               {
                    throw new UnsupportedOperationException("Not supported yet.");
               }
             public void keyReleased(KeyEvent e)
               {
                    throw new UnsupportedOperationException("Not supported yet.");
               }
           };
       }
} 
        lang.setSize(800, 500); // set dimensions of window
        lang.setVisible(true);
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top