📄 exceptiontest.java
字号:
import java.awt.*;
import java.lang.*;
import java.awt.event.*;
public class ExceptionTest extends Frame implements ActionListener
{
private TextArea ta;
public static void main(String args[])
{
ExceptionTest test=new ExceptionTest();
Button b1=new Button("安全 ");
Button b2=new Button("危险");
b1.addActionListener(test);
b2.addActionListener(test);
test.setLayout(new GridLayout(3,1));
test.add(b1);
test.add(b2);
test.ta=new TextArea(null,10,20,TextArea.SCROLLBARS_VERTICAL_ONLY);
test.add(test.ta);
test.setSize(300,200);
test.setVisible(true);
}
private void CheckButton(String Label)throws TextException
{
if(Label.compareTo("危险")==0)
throw(new TextException());
}
public void actionPerformed(ActionEvent e)
{
try
{
CheckButton(((Button)e.getSource()).getLabel());
ta.append("Safe\n");
}
catch(TextException ex)
{
ta.append(ex.getMessage()+"\n");
}
}
}
class TextException extends Exception
{
public String getMessage()
{
return("This is a test exception.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -