爱问知识人 爱问教育 医院库

请教三个java程序例子

首页

请教三个java程序例子

1关于事件模型 
2关于异常处理 
3关于图形界面的设计 

请各举一个例子,要程序,谢谢!

提交回答
好评回答
  • 2006-06-19 16:47:43
      java事件例子
    import  t。*;
    import  t。event。*;
    import javax。swing。*;
    public class EventDemo5 extends WindowAdapter implements ActionListener
    {
        JButton b1 = null;
        JButton b2 = null;
        
        public EventDemo5()
        {
            JFrame f = new JFrame("EventDemo5");
            Container contentPane =  tContentPane();
             tLayout(new GridLayout(1,2));
            b1 = new JButton("按我有声音喔");
            b2 = new JButton("按我可开新窗口");
             dActionListener(this);
             dActionListener(this);
             d(b1);
             d(b2);
             ck();
             ow();
             dWindowListener(this);
        }
        public void actionPerformed(ActionEvent e)
        {
            if( tSource()==b1)//getSource判断哪个按钮被按下了。
       tDefaultToolkit()。beep(); if( tSource()==b2) { JFrame newF = new JFrame("新窗口"); tSize(200,200); ow(); } } public void windowClosing(WindowEvent e) { System。
      exit(0); } public static void main(String args[]) { new EventDemo5(); } } 自定义异常处理例子: class MyException extends Exception { private int detail; MyException(int a) { detail = a; } public String toString() { return "MyException[" + detail + "]"; } } class ExceptionDemo { static void compute(int a) throws MyException { intln("Called compute(" + a + ")"); if(a > 10) throw new MyException(a); intln("Normal exit"); } public static void main(String args[]) { try { compute(1); compute(20); } catch (MyException e) { intln("Caught " + e); } } } 。
      

    x***

    2006-06-19 16:47:43

类似问题

换一换

相关推荐

正在加载...
最新资料 推荐信息 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 176-195
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):