//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
);
}
}
}
*/