非法开始表达错误

时间:2014-01-20 13:25:01

标签: java swing

我正在从其他帧生成JTabbedFrame。

在原始框架中,用户输入“用户ID”和“密码”&通过单击提交按钮生成JTabbedFrame。我的JTabbedFrame已成功编译,但我在原始帧中收到错误,因为在public void actionPerformed(Actionevent ae)

中非法启动表达式

我附上了两个帧的代码。请帮忙......

原始框架代码

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Login extends JFrame implements ActionListener
{
     JLabel l1,l2;
     JTextFiels t1,t2;
     JButton b;
     Login()
     {
         super("Login");
         Container c = this.getContentPane();

         setLayout(null);
         l1 = new JLabel("User Id"); 
         11.setBounds(20,45,100,30);
         c.add(l1);

         t1 = new JTextField();
         t1.setBounds(110,50,150,20);
         t1.addActionListener(this);
         c.add(t1);

         l2 = new JLabel("Password"); 
         l2.setBounds(20,95,100,30);
         c.add(l2);

         t2 = new JTextField();
         t2.setBounds(110,100,150,20);
         t2.addActionListener(this);
         c.add(t2);

         b = new JButton("Submit");
         b.setBounds(90,160,90,30);
         b.addActionListener(this);
         c.add(b);

         public void actionPerformed(ActionEvent ae)
         {
             String s1="admin",s2="bravo";
             String user = t1.getText();
             String pwd  = t2.getText();
             if(ae.getsource()==b)
             {
                 if(user.equals(s1)&&pwd.equals(s2))
                 {
                    Vehicle v=new Vehicle();
                    v.setSize(800,800);
                    v.setVisible(true);
                 }
                 else
                 {
                    System.out.println("Enter data Proparly");
                    JOptionPane.showMessageDialog(this,"Plse Fillup All Field","Error",JOptionPane.ERROR_MESSAGE);
                 }
             }
          } 
    }       
     public static void main(String args[])
     {
        Login l = new Login();
        l.setSize(300,300);
        l.setVisible(true);
        l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
}

TabbedFrame的代码

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Vehicle extends JFrame 
{
    Vehicle()
    {
        Container c  = getContentPane();
        JTabbedPane jtp = new JTabbedPane();
        jtp.addTab("Car", new Car());
        jtp.addTab("Country", new Country());
        c.add(jtp);
     }
     public static void main(String args[])
     {
        Student s1=new Student();
        s1.setSize(800,800);
        s1.setVisible(true);
        s1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     }
}   
class Car extends JPanel
{
    Car()
    {
        JButton b1 = new JButton("Volkswagen");
        JButton b2 = new JButton("Honda");
        JButton b3 = new JButton("GM");
        add(b1);
        add(b2);
        add(b3);
    }
}
class Country extends JPanel
{
    Country()
    {
        JCheckBox c1 = new JCheckBox ("Germany");
        JCheckBox c2 = new JCheckBox ("Japan");
        JCheckBox c3 = new JCheckBox ("USA");
        add(c1);
        add(c2);
        add(c3);
    }
}

2 个答案:

答案 0 :(得分:3)

您在方法中有一个方法,这是不允许的。从actionPerformed方法中拉出Logon

顺便说一句,请检查您的LoginLogon命名。如果您希望Logon成为构造函数,则它必须与您的类具有相同的名称。

答案 1 :(得分:0)

  1. 您的班级是班级Login,但您的构造函数名为Logon。此外,当您的班级为Logon时,您尝试实例化Login。你必须决定你想要哪一个。
  2. 另外,从构造函数中取出actionPerformed