Exception课后题 及JFrame及JDialog窗体练习


//Dialog 窗体练习
/*
class MyJDialog extends JDialog{
    public MyJDialog(MyFrame1 frame) {
        super(frame,"first dialog",true);
        Container container = getContentPane();
        container.add(new JLabel("这是一个对话框"));
        setBounds(120,120,100,100);
    }
}
public class MyFrame1 extends JFrame{
    public void MyFrame1(String title) {
//        JFrame jf = new JFrame(title);
//        Container container = jf.getContentPane();
        Container container = getContentPane();
//        container.setLayout(null);
        JButton jbutton= new JButton("弹出对话框");
        jbutton.setBounds(10,10,100,21);
            jbutton.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                new MyJDialog(MyFrame1.this).setVisible(true);;
            }
        });
        container.add(jbutton);    
        container.setBackground(Color.white);
//        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//        jf.setSize(500,200);
//        jf.setVisible(true);
        this.setVisible(true);
        this.setSize(500,500);
        this.setTitle(title);
    }
    public static void main(String args[]) {
        new MyFrame1().MyFrame1("窗体创建");
    }
}*/
/*public class MyFrame1 extends JFrame{
    public void CreateJFrame(String tile) {
        JFrame jf = new JFrame(tile);
        Container container = jf.getContentPane();
        JLabel jl = new JLabel("this is a JFrame Window");
        jl.setHorizontalAlignment(SwingConstants.CENTER);
        container.add(jl);
        container.setBackground(Color.BLACK);
        jf.setVisible(true);
        jf.setSize(200, 328);
        
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
    }
    public static void main(String args[]) {
        new MyFrame1().CreateJFrame("create a JFrame window");
    }
}
*/
//JFrame窗体
/*public class MyFrame extends JFrame{
    public void CreateJFrame(String tile) {
        JFrame jf = new JFrame(tile);
        Container container = jf.getContentPane();
        JLabel jl = new JLabel("this is a JFrame Window");
        jl.setHorizontalAlignment(SwingConstants.CENTER);
        container.add(jl);
        container.setBackground(Color.WHITE);
        jf.setVisible(true);
        jf.setSize(200, 328);
        jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        
    }
    public static void main(String args[]) {
        new MyFrame
        ().CreateJFrame("create a JFrame window");
    }
}
*/
//异常处理课后练习
/*public class MyException extends Exception{
    public MyException(String ErrorMessage) {
        super(ErrorMessage);
    }
}
public class Student{
    public void speak (int m) throws MyException{
        if(m>1000) {
            throw new MyException("more than 1000");
        }
    }
}
class mainClass{
    public static void main(String args[]) {
        Student stu = new Student();
        try {
            stu.speak(1090);
        } catch (MyException e) {
            // TODO Auto-generated catch block
            System.out.println(e);
        }
    }
}
public class Number{
    public double count(double m1,double m2) {
        return m1*m2;
    }
    public static void main(String args[]) {
        try{
            Number num = new Number();
            System.out.println(num.count(Integer.parseInt("1kjfd"),12));
        }catch(Exception e){
            e.printStackTrace();
        }
    }

}
public class Computer{
    public void f(int m,int n) throws MyException{
        if(m<0 || n<0) {
            throw new MyException("输入为负");
        }
    }
    public static void main(String args[]) {
        Computer com = new Computer();
        try {
            com.f(-21, 21);
        } catch (MyException e) {
            // TODO Auto-generated catch block
            
            System.out.println(e
                    );
        }
    }
}
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值