1. 在IDE中输入以下代码,观察运行结果,并说明该段程序的作用。
import java.awt.event.*;
import javax.swing.*;
public class ButtonExample extends JPanel {
static JFrame myFrame;
JLabel label;
public ButtonExample(){
label = new JLabel ("Hello World!");
JButton hello = new JButton("Hello");
// set shortcut key
hello.setMnemonic('h');
//Set the ToolTip for the hello button
hello.setToolTipText("Press Alt+H to test shortcut key");
hello.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println("Hello World!");
label.setText("Hello World!");
}
});
JButton bye = new JButton("Bye");
bye.setMnemonic('b');
//Set the ToolTip for the bye button
bye.setToolTipText("Press Alt+B to test shortcut key");
bye.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println("By