代码如下
package test;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MnemonicTest {
public static void main(String[] args) {
new MyDialog("对话框例子");
}
}
class MyDialog extends JDialog implements ActionListener {
MyDialog(String text) {
super();
setTitle(text);
init();
}
private void init() {
setLayout(null);
setSize(600, 400);
setLocationRelativeTo(null);
setResizable(false);
setVisible(true);
JButton button = new JButton("按键(R)");
button.setMnemonic('R');
button.addActionListener(this);
button.setBounds(200, 100, 80, 40);
getContentPane().add(button);
show();
}
@Override
public void actionPerformed(ActionEvent e) {
Color cyan = Color.cyan;
getContentPane().setBackground(cyan);
}
}
怎么在助记符激活时屏蔽其他应用的快捷键?