你代码你没有new throws

解决方案 »

  1.   

    throw new UserException("用户自定义异常");
      

  2.   

    if(source == c1)
         throw new H1();
      

  3.   

    麻烦你先看书ok, Thinking in Java, 3rd ed的 Creating Windows & Applets或者 http://java.sun.com/docs/books/tutorial/uiswing/index.htmlCreating a GUI with JFC/Swing 
      

  4.   

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Test
    {
    public static void main(String args[])
    {
    MyFrame frame =new MyFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
    }
     
    }
    class MyFrame extends JFrame
    {
    public MyFrame()
    {
    Container con=getContentPane();
    MyPanel panel=new MyPanel();
    con.add(panel);
        


    setTitle("MyExceptionFrame");
    setSize(WIDTH,HEIGHT);
    }
    private final int WIDTH=200;
    private final int HEIGHT=200;
    }
    class MyPanel extends JPanel
    {
    public MyPanel()
    {
    setLayout(new BorderLayout());
    JButton button=new JButton("Exception");
    add(button,BorderLayout.NORTH);
    textField=new JTextField("No Exception");
    add(textField,BorderLayout.CENTER);
    button.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent event)
    {
    try
    {
     int i=10/0;
    }
    catch(Exception err)
    {
    textField.setText(err.toString());
    }
       
    }
    });
    }
    private JTextField textField;
    } 我想这样的代码更加简单,更能适合初学者。