新手:渴求接下来的一步..
程序如下:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Xuliehao extends Applet implements ActionListener
{
Label lb=new Label( "请输入序列号:\n ");
TextField txt1=new TextField(5);
TextField txt2=new TextField(5);
TextField txt3=new TextField(5);
Button btn=new Button( "确定 ");
public void init()
{
add(lb);
add(txt1);
add(txt2);
add(txt3);
add(btn);
btn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(txt1.getText().equals( "cenji ")&&txt2.getText().equals( "ngaig ")&&txt3.getText().equals( "uoyou "))
JOptionPane.showMessageDialog(null, "欢迎使用**** ");
else
JOptionPane.showMessageDialog(null, "序列号错误 ");
}
}
要求在一个文本框里只能输入5个字符,超过部分就跳到下一个文本框,怎么办????如何添加..
------解决方案--------------------package Jan;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.KeyListener;
import javax.swing.*;
public class Xuliehao extends Applet implements ActionListener,KeyListener
{
Label lb=new Label( "请输入序列号:\n ");
TextField txt1=new TextField(5);
TextField txt2=new TextField(5);
TextField txt3=new TextField(5);
Button btn=new Button( "确定 ");
public void init()
{
add(lb);
add(txt1);
add(txt2);
add(txt3);
add(btn);
btn.addActionListener(this);
txt1.addKeyListener(this);
}
public void keyTyped(KeyEvent e){
//txt2 get focus 具体方法不记得了 -_-!
};
public void keyPressed(KeyEvent e){};
public void keyReleased(KeyEvent e){};
public void actionPerformed(ActionEvent e)
{
if(txt1.getText().equals( "cenji ")&&txt2.getText().equals( "ngaig ")&&txt3.getText().equals( "uoyou "))
JOptionPane.showMessageDialog(null, "欢迎使用**** ");
else
JOptionPane.showMessageDialog(null, "序列号错误 ");
}
}