-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdivision.java
60 lines (58 loc) · 1.81 KB
/
division.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class divi extends JFrame implements ActionListener{
JTextField t1,t2,t3;
JLabel l1,l2,l3;
JButton b1;
JPanel p;
divi(){
setTitle("division");
p=new JPanel(new GridLayout(3,2));
l1=new JLabel("num1:");
t1=new JTextField(10);
l2=new JLabel("num2:");
t2=new JTextField(10);
l3=new JLabel("result:");
t3=new JTextField(10);
b1=new JButton("divide");
b1.addActionListener(this);
Font f=new Font("seoge UI",Font.PLAIN,22);
p.setFont(f);
p.setBackground(Color.pink);
add(p);
p.add(l1);p.add(t1);p.add(l2);p.add(t2);p.add(l3);p.add(t3);add(b1,BorderLayout.SOUTH);
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1){
try{
int a=Integer.parseInt(t1.getText());
int b=Integer.parseInt(t2.getText());
int c;
c=a/b;
t3.setText(""+c);
}
catch(NumberFormatException ex){
t3.setText("-");
JOptionPane.showMessageDialog(this,"number format");
}
catch(ArithmeticException ex){
t3.setText("-");
JOptionPane.showMessageDialog(this,"arithmetic format");
}
catch(Exception ex){
t3.setText("-");
JOptionPane.showMessageDialog(this,"exception");
}
}
}
}
class division{
public static void main(String[] args){
new divi();
}
}