Java – Applet – Throw Exceptions (Custom Exceptions) 2 sayi toplama
Haz 06
Java programlama applet, custom, exception, Java programlama, throw, toplama Yorum Yok
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
public class SayiTopla extends JApplet
{
private int sayi1;
private int sayi2;
public void init()
{
String ilk;
String ikinci;
ilk = JOptionPane.showInputDialog(“ilk sayiyi gir” );
sayi1 = Integer.parseInt(ilk);
ikinci = JOptionPane.showInputDialog(“ikinci sayiyi gir” );
sayi2 = Integer.parseInt(ikinci);
}
public static int Topla (int sayi1, int sayi2)
throws Exception
{
int toplam = sayi1+sayi2;
if(toplam >0)
{
return toplam;
}
else
{
throw new Exception(“Toplam sifirdan kucuk!!”);
}
}
public void paint( Graphics g )
{
super.paint( g ); // call superclass version of method paint
try
{
JOptionPane.showMessageDialog(null,String.format(“Toplam is %d\n”,Topla(sayi1,sayi2)));
g.drawString(“HOW ARE U”,25,25);
}
// draw rectangle starting from (15, 10) that is 270
// pixels wide and 20 pixels tal
catch(Exception exception)
{
JOptionPane.showMessageDialog(null,exception.toString());
}
// draw results as a String at (25, 25)
} // end method paint
}


Facebook
RSS
Web Tasarım, Hosting