not - 2006-2-13 23:51:00
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class ko12_1 extends JApplet implements ActionListener
{
String str;
Container ctp=getContentPane();
JLabel lb1=new JLabel("输入");
JLabel lb2=new JLabel("输出");
JTextField tx=new JTextField(5);
JTextField tx2=new JTextField(5);
JButton bn=new JButton("确定");
public void init()
{
ctp.setLayout(new FlowLayout());
ctp.add(lb1);
ctp.add(tx);
ctp.add(lb2);
ctp.add(tx2);
ctp.add(bn);
bn.addActionListener(this);
tx.addActionListener(this);
tx.addKeyListener(new koListener());
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==bn)
{
str=tx.getText();
tx2.setText(str);
}
if(e.getSource()==tx)
{str=tx.getText();
tx2.setText(str);
}
}
class koListener extends KeyAdapter
{
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
str=tx.getText();
tx2.setText(str);
}
public void keyReleased(KeyEvent e)
{
}
}
}
/*
我想在TEXT1 里面输入字母在TEXT2里面就能马上显示出来,结果两个不同步,到底哪里 的问题?
*/
© 2000 - 2024 Rising Corp. Ltd.