Java – Applet – Throw Exceptions (Custom Exceptions)Çember, daire , çap hesaplama

Yorum Yok

import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.awt.Graphics;
import java.lang.Math;


public class Cember extends JApplet
{
 final double PI=Math.PI;
 private double r;
 private double diameter;
 private double circumference;
 private double area;
 
 public double RadiusExcept(double r) throws Exception
 {
  if (r<0)
  {
   throw new Exception (“Radius can’t be less than zero”);
  }
  else
  return r;
 }
 public void init()
 {
 
  String radius = JOptionPane.showInputDialog(“Enter radius value”);
  r=Double.parseDouble(radius);
  
 }
 public void paint (Graphics sinan)
 {
  super.paint(sinan);
  try{
   r= RadiusExcept(r);
   diameter = r*2;
   circumference = r*2*PI;
   area = r*r*PI;
   sinan.drawSt1ring (String.format(” Radius : %.2f\n Diameter : %.2f\n Circumference : %.2f\n Area : %.2f\n”,r,diameter,circumference,area),25,25);
   sinan.drawOval(50,50,200,200);
  }
  catch(Exception ex)
  {
    JOptionPane.showMessageDialog(null,ex.toString());
    
    
  }
  

 }
 
}

Cevapla