Skip to main content

Posts

Moving ball in applet

import java.applet.*; import java.awt.*; import java.lang.*; import java.math.*; import java.awt.Color; /*<applet code="ball" height=100 width=100></applet>   */ public class ball extends Applet implements Runnable { int i=0,j=0; Thread t; public void init() { t=new Thread(this); t.start(); } public void run() { int sec=0; setSize(1200,1200); try { while(true) { repaint(); sec+=1; t.sleep(100); } }catch(Exception e) { System.out.println(e); } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { setBackground(Color.black); Dimension d= getSize(); g.setColor(Color.black); g.fillRect(0,0,d.width,d.height); g.setColor(Color.white); g.fillOval(i+10,j+10,100,100); i=i+10; g.setColor(Color.black); } }

Font List in java applet

import java.awt.*; import java.applet.*; /* <applet code="Fontlist" height=1000 width=190 ></applet>*/ public class Fontlist extends Applet {   private String[] availableFonts;   public void init () {     Toolkit t = Toolkit.getDefaultToolkit();     availableFonts = t.getFontList();   }   public void paint(Graphics g) {     for (int i = 0; i < availableFonts.length; i++) {       g.drawString(availableFonts[i], 5, 15*(i+1));     }   } }

User defined exception for negative values entered by the user

import java.io.*; import java.lang.*; class E extends Exception { E(String s) { super(s); } } class excep { public static void main(String args[])throws E { DataInputStream d= new DataInputStream(System.in); System.out.println("Enter a no"); try { int a=Integer.parseInt(d.readLine()); sub(a); } catch(Exception e) { System.out.println(e); } } public static void sub(int x)throws E { if(x<0) throw new E("Invalid"); } }

Program to check whether a number is special or not

import java.io.*; import java.lang.*; class special{ static int r,n,s=0,fact=1,i; public static void main(String args[])throws Exception{ n=Integer.parseInt(args[0]); while(n>0) { r=n%10; fact=1; for(i=1;i<=r;i++) fact=fact*i; s=s+fact; n=n/10; } if(Integer.parseInt(args[0])==s) System.out.println("Special"); else System.out.println("NOT"); } }

Input a natural number >1 and output its prime factors

import java.io.*; import java.lang.*; class p{ static int i,c; static int prim(int n) { c=0; for(i=1;i<=n;i++) if(n%i==0) c=c+1; if(c==2) { System.out.print(n+","); return(1); } else return(0); } public static void main(String args[])throws Exception{ int no=Integer.parseInt(args[0]); while(no>=2) { for(int j=2;j<=no;j++) { if(no%j==0&&prim(j)==1) { no=no/j; break; } } } System.out.print('\b'); } }

Applet Program to create frame in java

import java.applet.*; import java.awt.event.*; import java.awt.*; /*<applet code="frm" height=300 width=700> </applet>*/ public class frm extends Applet //implements ItemListener { public void init() { Label l1=new Label("NAME"); Label l2=new Label("PASSWORD"); Label l3=new Label("QUALIFICATION"); Label l4=new Label("E-MAIL"); Label l5=new Label("GENDER"); TextField t1=new TextField(); TextField t2=new TextField(); TextField t3=new TextField(); TextField t4=new TextField(); CheckboxGroup cbg= new CheckboxGroup(); Checkbox cb1=new Checkbox("Male",cbg,true); Checkbox cb2=new Checkbox("Female",cbg,false); l1.setBounds(20,45,70,20); t1.setBounds(200,45,200,20); l2.setBounds(20,65,70,20); t2.setBounds(200,65,200,20); l3.setBounds(20,85,70,20); t3.setBounds(200,85,200,20); l4.setBounds(20,105,70,20); t4.setBounds(200,105,200,20); l5.setBounds(20,125,70,20); cb1.s...

Html Practical

<html> <head> <title> blog </title> <!--Title is used to identify the contents of a document.It defines a title in the browser--> <base href="http://solvedprograms.blogspot.in" target="_self"> <!-- Base specifies a default url & a default target for all links on a page --> <meta name="keywords" content="html,xml"> <!--The meta element specifies a property and assign a value to it.Mainly used for seo--> <link rel="stylesheet" type="text/css" href="a.css"/> <!--It is used to link other documents to the webpage--> <style type="text\css"> H1{font-size:72px} </style> <!--IT is used to set style of a document--> <script language="javascript"> </script> </head> <body background="" bgcolor="gray" leftmargin="100" topmargin="100...