📄 finalexception.java
字号:
import java.awt.*;
import java.awt.event.*;
public class FinalException
extends Frame
implements ActionListener {
public Button quit = new Button("Quit"), enter = new Button("Go");
public ShortTextField text = new ShortTextField();
public TextArea display = new TextArea(3, 25);
public FinalException() {
super("Exceptions with Finally");
quit.addActionListener(this);
enter.addActionListener(this);
Panel input = new Panel();
input.setLayout(new BorderLayout());
input.add("West", enter);
input.add("Center", text);
input.add("East", quit);
setLayout(new BorderLayout());
add("Center", display);
add("North", input);
validate();
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == quit) {
System.exit(0);
}
if (e.getSource() == enter) {
display.setText("");
display.append("Line before try-catch-finally block\n");
try {
display.append("Line before getShortText()\n");
display.append(text.getShortText() + "\n");
display.append("Line after getShortText()\n");
}
catch (LongStringException se) {
display.append("Exception occured: " + se.getMessage() + "\n");
}
finally {
display.append("Finally block executes\n");
}
display.append("Line after try-catch-finally block\n");
}
}
public static void main(String args[]) {
FinalException fe = new FinalException();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -