一个窗口包含文本和标签,在文本行中输入一段文字并按“e...
1个回答
2011-07-12
展开全部
port java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class T55 {
public static void main(String[] args) {
JFrame jf = new JFrame();
JPanel jp = new JPanel();
final JLabel jl = new JLabel();
final JTextField jtf = new JTextField();
jf.add(jp);
jp.setLayout(new GridLayout(2,1));
jp.add(jl);
jp.add(jtf);
jtf.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER){
jl.setText(jtf.getText());
}
}
});
jf.setSize(144,144);
jf.setVisible(true);
}
}
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class T55 {
public static void main(String[] args) {
JFrame jf = new JFrame();
JPanel jp = new JPanel();
final JLabel jl = new JLabel();
final JTextField jtf = new JTextField();
jf.add(jp);
jp.setLayout(new GridLayout(2,1));
jp.add(jl);
jp.add(jtf);
jtf.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER){
jl.setText(jtf.getText());
}
}
});
jf.setSize(144,144);
jf.setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询