import java.awt.*;
import javax.swing.*;class LoginCheck{
private String name;
private String password;
public LoginCheck(String name,String password){
this.name=name;
this.password=password;
}
public boolean validate(){
if("dinglimin".equals(name)&&"123456".equals(password)){
return true;
}
else {
return false;
}
}
}
class TestDemo1{
private JFrame frame=new JFrame("welcome to my test");
private JButton submit=new JButton("登陆");
private JButton reset=new JButton("重置");
private JLabel nameLab=new JLabel("用户名");
private JLabel passLab=new JLabel("密码");
private JLabel infoLab=new JLabel("用户登录系统");
private JTextField nameText=new JTextField();
private JPasswordField passText=new JPasswordField();
public TestDemo1(){
Font fnt=new Font("Serief",Font.BOLD,12);
infoLab.setFont(fnt);
submit.addActionListener(new ActionListener(){
public void actionPerformedI(ActionEvent arg0){
if(arg0.getSource()==submit){
String tname=nameText.getText();
String tpass=new String(passText.getPassword());
LoginCheck log=new LoginCheck(tname,tpass);
if(log.validate()){
infoLab.setText("登陆成功,欢迎光临");
}
else{
infoLab.setText("登录失败,错误用户名或密码");
}
}
if(argo()==reset){
nameText.setText("");
passText.setText("");
infoLab.setText("用户登录系统");
}
}
});
frame.setLayout(null);
nameLab.setBounds(5, 5, 60, 20);
passLab.setBounds(5, 30, 60, 20);
infoLab.setBounds(5, 65, 220, 30);
nameText.setBounds(65, 5, 100, 30);
passText.setBounds(65, 30, 100, 20);
submit.setBounds(165, 5, 60, 20);
reset.setBounds(165, 30, 60, 20);
frame.add(nameLab);
frame.add(passLab);
frame.add(infoLab);
frame.add(nameText);
frame.add(passText);
frame.add(submit);
frame.add(reset);
frame.setSize(280, 130);
frame.setVisible(true);
}
}
public class AwtTest{
public static void main(String args[]){
new TestDemo1();
}
}
出现这样的错误:
Exception in thread "main" java.lang.Error: 无法解析的编译问题:
ActionListener 无法解析为类型
哪位大侠给看看
import javax.swing.*;class LoginCheck{
private String name;
private String password;
public LoginCheck(String name,String password){
this.name=name;
this.password=password;
}
public boolean validate(){
if("dinglimin".equals(name)&&"123456".equals(password)){
return true;
}
else {
return false;
}
}
}
class TestDemo1{
private JFrame frame=new JFrame("welcome to my test");
private JButton submit=new JButton("登陆");
private JButton reset=new JButton("重置");
private JLabel nameLab=new JLabel("用户名");
private JLabel passLab=new JLabel("密码");
private JLabel infoLab=new JLabel("用户登录系统");
private JTextField nameText=new JTextField();
private JPasswordField passText=new JPasswordField();
public TestDemo1(){
Font fnt=new Font("Serief",Font.BOLD,12);
infoLab.setFont(fnt);
submit.addActionListener(new ActionListener(){
public void actionPerformedI(ActionEvent arg0){
if(arg0.getSource()==submit){
String tname=nameText.getText();
String tpass=new String(passText.getPassword());
LoginCheck log=new LoginCheck(tname,tpass);
if(log.validate()){
infoLab.setText("登陆成功,欢迎光临");
}
else{
infoLab.setText("登录失败,错误用户名或密码");
}
}
if(argo()==reset){
nameText.setText("");
passText.setText("");
infoLab.setText("用户登录系统");
}
}
});
frame.setLayout(null);
nameLab.setBounds(5, 5, 60, 20);
passLab.setBounds(5, 30, 60, 20);
infoLab.setBounds(5, 65, 220, 30);
nameText.setBounds(65, 5, 100, 30);
passText.setBounds(65, 30, 100, 20);
submit.setBounds(165, 5, 60, 20);
reset.setBounds(165, 30, 60, 20);
frame.add(nameLab);
frame.add(passLab);
frame.add(infoLab);
frame.add(nameText);
frame.add(passText);
frame.add(submit);
frame.add(reset);
frame.setSize(280, 130);
frame.setVisible(true);
}
}
public class AwtTest{
public static void main(String args[]){
new TestDemo1();
}
}
出现这样的错误:
Exception in thread "main" java.lang.Error: 无法解析的编译问题:
ActionListener 无法解析为类型
哪位大侠给看看
public void actionPerformedI(ActionEvent arg0){ // 是你打错了,还是你代码就这么写的?
}
改成
submit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
}
import java.awt.event.*;结贴吧
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.*;class LoginCheck
{
private String name;
private String password; public LoginCheck(String name,String password)
{
this.name=name;
this.password=password;
} public boolean validate()
{
if("dinglimin".equals(name)&&"123456".equals(password)){
return true;
}
else
{
return false;
}
}
}
class TestDemo1
{
private JFrame frame=new JFrame("welcome to my test");
private JButton submit=new JButton("登陆");
private JButton reset=new JButton("重置");
private JLabel nameLab=new JLabel("用户名");
private JLabel passLab=new JLabel("密码");
private JLabel infoLab=new JLabel("用户登录系统");
private JTextField nameText=new JTextField();
private JPasswordField passText=new JPasswordField(); public TestDemo1()
{
Font fnt=new Font("Serief",Font.BOLD,12);
infoLab.setFont(fnt); submit.addActionListener(new ActionListener()
{
//另外事件响应我们一般用e表示,请楼主见谅
public void actionPerformedI(ActionEvent e)
{
if(e.getSource()==submit)
{
String tname=nameText.getText();
String tpass=new String(passText.getPassword());
LoginCheck log=new LoginCheck(tname,tpass); if(log.validate())
{
infoLab.setText("登陆成功,欢迎光临");
}
else
{
infoLab.setText("登录失败,错误用户名或密码");
} }
/////////楼主这里改改
if(e.getSource()==reset)
{
nameText.setText(""); passText.setText("");
infoLab.setText("用户登录系统");
}
} @Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
});
frame.setLayout(null);
nameLab.setBounds(5, 5, 60, 20);
passLab.setBounds(5, 30, 60, 20);
infoLab.setBounds(5, 65, 220, 30);
nameText.setBounds(65, 5, 100, 30);
passText.setBounds(65, 30, 100, 20);
submit.setBounds(165, 5, 60, 20);
reset.setBounds(165, 30, 60, 20);
frame.add(nameLab);
frame.add(passLab);
frame.add(infoLab);
frame.add(nameText);
frame.add(passText);
frame.add(submit);
frame.add(reset);
frame.setSize(280, 130);
frame.setVisible(true);
}
}
public class AwtTest
{
public static void main(String args[])
{
new TestDemo1();
}
}
if(argo()==reset){
argo()是什么?