电话:0731-83595998
导航
首页 > 在线问答 > 计算机 > 计算机题库2
题目内容

本题的功能是监听键盘键的敲击,并显示在窗口中。 import javax,.swing.*; importjava.awt.*; , import java.awt.event.*; public class java3 extends JFrame. extends KeyListener { private String linel=""line2="" private String line3="" private JTextAr

提问人:陈俭龙发布时间:2020-06-24
本题的功能是监听键盘键的敲击,并显示在窗口中。 import javax,.swing.*; importjava.awt.*; , import java.awt.event.*; public class java3 extends JFrame. extends KeyListener { private String linel=""line2="" private String line3="" private JTextArea textArea; public java3 { super("java3"); textArea=new JTextArea(10,15); textArea.setText("Press any key on the key- board…"); textArea.setEnabled(false); addKeyListener(this); getContentPane.add(textArea); setSize(350,100); show; } public void keyPressed(KeyEvent e) { linel="Key pressed:"+e.getKeyText(e. getKeyCode); setLines2and3(e); } public void keyReleased(KeyEvent e) { linel="Key released:"+e.getKeyText(e. getKeyCode); setLines2and3(e): } public void keyTyped(KeyEvent e) { Linel="Key typed:"+e.getKeychar; setLines2and3(e); } private void setLines2and3(KeyEvent e) { line2="This key is"+(e.isActionKey?"" :"not")+"an action key"; String temp=e.getKeyModifiersText(e.get- Modifiers); hne3="Modifier keys pressed:"+(temp.e- quals("")?"none":temp); textArea.setText(linel+"\n"+line2+"\n" +line3+"\n"); } public static void main(String args[]) { java3 app=new java3; addWindowListener(new Windowadapted { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }本题的功能是监听键盘键的敲击,并显示在窗口中。 import javax,.swing.*; importjava.awt.*; , import java.awt.event.*; public class java3 extends JFrame. extends KeyListener { private String linel=""line2="" private String line3="" private JTextArea textArea; public java3 { super("java3"); textArea=new JTextArea(10,15); textArea.setText("Press any key on the key- board…"); textArea.setEnabled(false); addKeyListener(this); getContentPane.add(textArea); setSize(350,100); show; } public void keyPressed(KeyEvent e) { linel="Key pressed:"+e.getKeyText(e. getKeyCode); setLines2and3(e); } public void keyReleased(KeyEvent e) { linel="Key released:"+e.getKeyText(e. getKeyCode); setLines2and3(e): } public void keyTyped(KeyEvent e) { Linel="Key typed:"+e.getKeychar; setLines2and3(e); } private void setLines2and3(KeyEvent e) { line2="This key is"+(e.isActionKey?"" :"not")+"an action key"; String temp=e.getKeyModifiersText(e.get- Modifiers); hne3="Modifier keys pressed:"+(temp.e- quals("")?"none":temp); textArea.setText(linel+"\n"+line2+"\n" +line3+"\n"); } public static void main(String args[]) { java3 app=new java3; addWindowListener(new Windowadapted { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
题目答案

一对一服务

咨询老师
网友评论(共0条评论)

请自觉遵守互联网相关政策法规,评论内容只代表网友观点!

最新评论

点击加载更多评论>>

免费咨询,如何快速提升学历!

立即报名

已经有28179人提升了学历

题库-找答案

已有大量题库

马上做题
相关试题

继续查找其他问题的答案?

长理培训客户端 资讯,试题,视频一手掌握

去 App Store 免费下载 iOS 客户端