java程序纠错

import java.io.*;
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

class guiClass implements ActionListener
{
JButton queding;
JButton quxiao;
JLabel yonghuming;
JLabel mima;
JTextField JT1;
JPasswordField JT2;
public void init()
{
JFrame f=new JFrame("用户登录");
JPanel j1=new JPanel();
JPanel j2=new JPanel();
JPanel j3=new JPanel();
FlowLayout flow=new FlowLayout();
j1.setLayout(flow);
j2.setLayout(flow);
j3.setLayout(flow);
f.getContentPane().setLayout(new BorderLayout());
yonghuming=new JLabel("用户名:");
mima=new JLabel("密码 :");
JT1=new JTextField(12);
JT2=new JPasswordField(12);
JT2.setEchoChar('*');
queding=new JButton("确认");
quxiao=new JButton("取消");

j1.add(yonghuming);
j1.add(JT1);
j2.add(mima);
j2.add(JT2);
j3.add(queding);
j3.add(quxiao);

f.getContentPane().add("North",j1);
f.getContentPane().add("Center",j2);
f.getContentPane().add("South",j3);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 150);
f.setVisible(true);
queding.addActionListener(this);
quxiao.addActionListener(this);
JT1.addActionListener(this);
JT2.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{

if(e.getSource()==quxiao)
{
System.exit(0);

}
if(e.getSource()==queding)
{
int num=3;
JTextField JT1=(JTextField)e.getSource();
JPasswordField JT2=(JPasswordField)e.getSource();
if(tools.eqes(JT1.getText(), JT2.getText()))
{
JOptionPane.showMessageDialog(this,"欢迎进入系统~");
System.exit(0);
}
else
{
--num;

if(num==0)
{
JOptionPane.showMessageDialog(this,"用户名或者密码错误!您没有机会了");
System.exit(0);
}

else
{
JOptionPane.showMessageDialog(this,"用户名或者密码错误!您还有"+num+"次机会");
}
}
}
else
{
JOptionPane.showMessageDialog(this,"输入有误~!");
}

}
}

public class test
{
public static void main(String[] s)
{
guiClass g = new guiClass();
g.init();
}}

编译错误 望给与解答

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GuiClass implements ActionListener {
JButton queding;

JButton quxiao;

JLabel yonghuming;

JLabel mima;

JTextField JT1;

JPasswordField JT2;

JFrame f;

public void init() {
f = new JFrame("用户登录");
JPanel j1 = new JPanel();
JPanel j2 = new JPanel();
JPanel j3 = new JPanel();
FlowLayout flow = new FlowLayout();
j1.setLayout(flow);
j2.setLayout(flow);
j3.setLayout(flow);
f.getContentPane().setLayout(new BorderLayout());
yonghuming = new JLabel("用户名:");
mima = new JLabel("密码 :");
JT1 = new JTextField(12);
JT2 = new JPasswordField(12);
JT2.setEchoChar('*');
queding = new JButton("确认");
quxiao = new JButton("取消");

j1.add(yonghuming);
j1.add(JT1);
j2.add(mima);
j2.add(JT2);
j3.add(queding);
j3.add(quxiao);

f.getContentPane().add("North", j1);
f.getContentPane().add("Center", j2);
f.getContentPane().add("South", j3);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(300, 150);
f.setVisible(true);
queding.addActionListener(this);
quxiao.addActionListener(this);
JT1.addActionListener(this);
JT2.addActionListener(this);

}

public void actionPerformed(ActionEvent e) {

if (e.getSource() == quxiao) {
System.exit(0);

}
if (e.getSource() == queding) {
int num = 3;
if (eqes(JT1.getText(), String.valueOf(JT2.getPassword()))) {
JOptionPane.showMessageDialog(f, "欢迎进入系统~");
System.exit(0);
} else {
--num;

if (num == 0) {
JOptionPane.showMessageDialog(f, "用户名或者密码错误!您没有机会了");
System.exit(0);
}

else {
JOptionPane.showMessageDialog(f, "用户名或者密码错误!您还有" + num
+ "次机会");
}
}
} else {
JOptionPane.showMessageDialog(f, "输入有误~!");
}

}

public boolean eqes(String name,String pass){
if("aaa".equals(name) && "123".equals(pass))
return true;
else return false;
}

}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-30
变量 tools 未定义
showMessageDialog 方法参数类型不匹配
第2个回答  2009-11-30
您最好提供下 哪行错误的.