简答题:本题的功能是监听键盘键的敲击,并显示在窗口中。 import javax,.swing.*; importjava.aw

  • 题目分类:Java
  • 题目类型:简答题
  • 号外号外:注册会员即送体验阅读点!
题目内容:
本题的功能是监听键盘键的敲击,并显示在窗口中。
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);
}
});
}
}
参考答案:【答案仅供学习,请勿对照自行用药等】
答案解析:

本题的功能是求1~100的自然数的累加,并打印输出 计算结果。 public class javal{public st

本题的功能是求1~100的自然数的累加,并打印输出 计算结果。 public class javal{public static void main(St

查看答案

本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes

本题中,主窗口有一个按钮“打开对话框”和一个文本域,单击按钮“打开对话框”后会弹出一个对话框,对话框上有两个按钮“Yes"和“N0”,单击对话框上的“Yes”和

查看答案

Just as music is a universal language,________.

Just as music is a universal language,________. A.so it is a mirror of the time

查看答案

Where are they probably talking?

Where are they probably talking?A.In a classroom. B.At an airport. C.In a restau

查看答案

It is necessary for parents to drive theirchildren to school

It is necessary for parents to drive theirchildren to school.A.Right B.Wrong C.D

查看答案