import javax.swing.SwingConstants;
public class MainFrame  extends JPanel implements ActionListener
{
    private JButton saveButton;
    private JButton  resetButton; CardLayout cl;
    JButton b1,b2;
    JRadioButton jb1,jb2;
    JLabel j1;
    JPanel pf ;
    JTextField jt3, jt2;
    private Object fyk;
    MainFrame()
    {
  
JLabel j1,j2,j3;
j1=new JLabel("欢迎使用手机资费系统:",JLabel.CENTER); 
JPanel jp1=new JPanel(new GridLayout());
j1.add(jp1);
j2=new JLabel("用户名:",JLabel.CENTER);
j3=new JLabel("密码:",JLabel.CENTER);
jt3=new JTextField(6);
jt2=new JTextField(6);
jb1=new JRadioButton("管理员");
jb2=new JRadioButton("普通用户"); 
ButtonGroup bg=new ButtonGroup();
bg.add(jb1);
bg.add(jb2);
JPanel jp2=new JPanel(new GridLayout(3,2));
jp2.add(j2);
jp2.add(jt2);
jp2.add(j3);
jp2.add(jt3);
jp2.add(jb1);
jp2.add(jb2);
jb1.addActionListener(this);
jb2.addActionListener(this);
saveButton=new JButton("确定");
resetButton=new JButton("返回");
JPanel jp3=new JPanel(new GridLayout(1,2));
jp3.add(saveButton );
jp3.add(resetButton);
saveButton.addActionListener(this);
resetButton.addActionListener(this);
add(jp1,BorderLayout.NORTH);
add(jp2,BorderLayout.CENTER);
add(jp3,BorderLayout.SOUTH);
}
    public void actionPerformed(ActionEvent e)
    {
     if(e.getSource()==resetButton)
    {
JPanel mainp = new JPanel(new BorderLayout());
JLabel mainl = new JLabel("手机资费系统",SwingConstants.CENTER);
mainl.setFont(new Font("Serif",Font.BOLD,30));
mainp.add(mainl);
pf.add(mainp,"main");
cl.show(pf, "main");
    }
     else
     {
     if(e.getSource()==jb1)
     {
     if(jt2.equals(fyk)&&jt3.equals(fyk))
     {
     if(e.getSource()==saveButton)
     {
     AdminFrame am=new AdminFrame("");
     am.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     am.setVisible(true);
         }
        }
     else
     {
     JOptionPane.showMessageDialog(null, "用户名或密码错误");
     }
            }
     if(e.getSource()==jb2)
     {String s2=jt2.getText().trim();
     String s3=jt3.getText().trim();
     if(e.getSource()==saveButton)
{
     userDb db=new userDb("user");
Vector v=db.inQuery(s2,s3);
if (v.size()!=0)  
{UserFrame am=new UserFrame("");
     am.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     am.setVisible(true);}
     else
     {
JOptionPane.showMessageDialog(null, "用户名或密码错误");
}
     }
     }
     }
    }
}