我正在从其他框架生成一个JTabbedFrame。
在原始框架中,用户输入“用户ID”和“密码”,并通过单击提交按钮JTabbedFrame生成。我的JTabbedFrame已成功编译,但是由于公共无效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);
}
}
最佳答案
方法中有一个方法,这是不允许的。从actionPerformed
方法中拉出Logon
。
顺便说一句,检查您的Login
和Logon
命名。如果您打算Logon
成为构造函数,则它必须与您的类具有相同的名称。