0

illegal start of expression在下面的代码中遇到错误,在 -> 行public class hindilang,我在这个网站上看到了其他问题和答案,但我不知道我哪里出错了??

    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);
    }
    }

该文件保存为hindilang.java并被编译为javac hindilang.java,我做错了什么?请指导我

尝试了以下建议,但仍然遇到相同的错误...

4

2 回答 2

1

public lang()的构造方法'}'在有问题的行之前的方法定义末尾缺少 a

于 2013-02-16T12:27:50.313 回答
0

您在}这里缺少的是更正的代码

 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);
}
}
于 2013-02-16T12:29:31.910 回答