import java.awt.event.*; import java.awt.*; class ExceptionGui extends Frame implements ActionListener,WindowListener,TextListener { int numerator,denominator,result; Button b; TextField tf1,tf2; Label l1,l2,l3; public ExceptionGui() { setLayout(new FlowLayout()); setSize(300,250); Button b=new Button("enter"); Label l1=new Label("enter numerator"); Label l2=new Label("enter denominator"); Label l3=new Label(); TextField tf1=new TextField(15); TextField tf2=new TextField(15); add(l1);add(tf1); add(l2);add(tf2); add(b);add(l3); b.addActionListener(this); tf1.addTextListener(this); tf2.addTextListener(this); addWindowListener(this); setVisible(true); } public void textValueChanged(TextEvent te) { if(te.getSource()==tf1) //got an Exception over here { String x=tf1.getText(); numerator=Integer.parseInt(x); } else { String y=tf2.getText(); denominator=Integer.parseInt(y); } } public void actionPerformed(ActionEvent ae) { result=numerator/denominator; l3.setText(String.valueOf(result)); } public void windowOpened(java.awt.event.WindowEvent we){} public void windowClosing(java.awt.event.WindowEvent we){ System.exit(0); } public void windowClosed(java.awt.event.WindowEvent we){} public void windowIconified(java.awt.event.WindowEvent we){} public void windowDeiconified(java.awt.event.WindowEvent we){} public void windowActivated(java.awt.event.WindowEvent we){} public void windowDeactivated(java.awt.event.WindowEvent we){} } class Exception { public static void main(String args[]) { ExceptionGui ex=new ExceptionGui(); } }