📄 awtexample.java
字号:
/*
* AWTExample.java
*
* Created on January 22, 2009, 10:50 AM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author mekala
*/
import java.awt.*;
import java.awt.event.*;
public class AWTExample extends Frame {
private Button copyButton;
private Button cutButton;
private Button pasteButton;
private Button exitButton;
/**
* Public no-arg constructor
*/
public AWTExample() {
super("Simple AWT Example");
setSize(450, 250);
addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
}
);
ActionListener buttonListener = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
String action = ae.getActionCommand();
if (action.equals("Exit")) {
dispose();
System.out.println("Exiting.");
System.exit(0);
} else {
System.out.println(action);
}
}
};
// Toolbar Panel
Panel toolbarPanel = new Panel();
toolbarPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
copyButton = new Button("Copy");
copyButton.addActionListener(buttonListener);
toolbarPanel.add(copyButton);
cutButton = new Button("Cut");
cutButton.addActionListener(buttonListener);
toolbarPanel.add(cutButton);
pasteButton = new Button("Paste");
pasteButton.addActionListener(buttonListener);
toolbarPanel.add(pasteButton);
add(toolbarPanel, BorderLayout.NORTH);
// Bottom Panel
Panel bottomPanel = new Panel();
exitButton = new Button("Exit");
exitButton.addActionListener(buttonListener);
bottomPanel.add(exitButton);
add(bottomPanel, BorderLayout.SOUTH);
}
/**
* Sole entry point to the class and application.
* @param args Array of String arguments.
*/
public static void main(String[] args) {
AWTExample mainFrame = new AWTExample();
mainFrame.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -