/**
* @author
*/
public static void main(String[] args) {
final Frame frame =new Frame("QQ登陆界面");
frame.setBounds(300, 300, 800, 600);
//改变窗口的布局
frame.setLayout(null);
//添加菜单栏
MenuBar menuBar = new MenuBar();
frame.setMenuBar(menuBar);
Menu titleMenu = new Menu("文件");
menuBar.add(titleMenu);
Menu fileMenu = new Menu("修改标题");
titleMenu.add(fileMenu);
MenuItem fileMenu2=new MenuItem("退出");
titleMenu.add(fileMenu2);
final MenuItem M1 = new MenuItem("好好学习");
final MenuItem M2 = new MenuItem("天天向上");
MenuItem M3 = new MenuItem("恢复标题");
fileMenu.add(M1);
fileMenu.add(M2);
fileMenu.add(M3);
//创建时间监控
final String name =frame.getTitle();
M1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setTitle(M1.getLabel());
}
});
M1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setTitle(M1.getLabel());
}
});
M2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
frame.setTitle(M2.getLabel());
}
});
@Override
public void keyReleased(KeyEvent e) {
char ch =e.getKeyChar();
switch(ch){
case '0':
frame.setBackground(Color.BLACK);
break;
case '1':
frame.setBackground(Color.BLUE);
break;
case '2':
frame.setBackground(Color.cyan);
break;
case '3':
frame.setBackground(Color.DARK_GRAY);
break;
case '4':
frame.setBackground(Color.gray);
break;
case '5':
frame.setBackground(Color.blue);
break;
case '6':
frame.setBackground(Color.darkGray);
break;
case '7':
frame.setBackground(Color.gray);
break;
case '8':
frame.setBackground(Color.cyan);
break;
case '9':
frame.setBackground(Color.cyan);
break;