Sunday, June 19, 2016

JavaProgram Collection1

public class a
{
public static void main(String []as)
{
System.out.println("Hello World");
}
}abstract class Shape
{
int x,y;
void getdata(int x1,int y1)
{
x=x1;
y=y1;
}
abstract void area();
}
class Rectangle extends Shape
{
void area()
{
int a=x*y;
System.out.println("Area of Rectangle having width"+x+"and Height="+y+"is"+a);
}
}
class Triangle extends Shape
{
void area()
{
int a=(x*y)/2;
System.out.println("Area of Triangle="+a);
}
}
class AbstractDemo
{
public static void main(String arg[])
{
Rectangle r=new Rectangle();
r.getdata(20,10);
r.area();
Triangle t=new Triangle();
t.getdata(30,40);
t.area();
}
}import javax.swing.JOptionPane;
public class activity11
{
public static void main(String args[])
{
int a,b,c,d,x;
a=Integer.parseInt(JOptionPane.showInputDialog("First Number"));
b=Integer.parseInt(JOptionPane.showInputDialog("Second Number"));
d=Integer.parseInt(JOptionPane.showInputDialog("Number Sequence"));
c=0;
System.out.print(a);
System.out.print(" "+b);
 for (x=0;x<=d-2;x++)
 {
 c=a+b;
 System.out.print(" "+c);
 a=b;
 b=c;
 }  
}
}public class add
{
public static void main(String args[])
{
int a=10, b=20,c;
c=a+b;


System.out.println("\n\n result of the sum is..."+ c);


}}import java.io.*;

class animate
{
        public static void main(String args[])
        {
        String msg="Java At RNEC by RVS..";
        Thread t=Thread.currentThread();
        try
        {
                for(;;)
                {
                msg=msg.substring(1,msg.length())+String.valueOf(msg.charAt(0));
                System.out.println(msg);
                t.sleep(100);              
                }
        }
        catch(Exception e)
        {
        e.printStackTrace();
        }

        }
}





import java.io.*;

class  animate1
{
public static void main(String arg[])
{
String msg="I Love Java  at RNEC@RVS....";
Thread t;
try
{
t=Thread.currentThread();
for(;;)
{
System.out.println(msg);
t.sleep(100);
msg=msg.substring(1,msg.length()) + String.valueOf(msg.charAt(0));
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}



import java.io.*;

class animatealt
{
        public static void main(String args[])
        {
        int sta=1,i=0;
        String msg="Java At RNEC by RVS..Java At RNEC by RVS..Java At RNEC by RVS";
        Thread t=Thread.currentThread();
        try
        {
                for(;;i++)
                {
                if(i%10==0)
                {
                        if(sta==0)
                        sta=1;
                        else
                        if(sta==1)
                        sta=0;
                }
                        if(sta==0)
                        {
                        msg=msg.substring(1,msg.length())+String.valueOf(msg.charAt(0));
                        }
                        else
                        {
                        msg=String.valueOf(msg.charAt(msg.length()-1))+msg.substring(0,msg.length()-1);
                        }

                System.out.println(msg);
                t.sleep(100);              
                }
        }
        catch(Exception e)
        {
        e.printStackTrace();
        }

        }
}





import java.io.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class animateapplt extends Applet
{
        String msg="Java At RNEC by RVS..";

        public void init()
        {
        Thread t=Thread.currentThread();
       
        try
        {
                for(;;)
                {
                msg=msg.substring(1,msg.length())+String.valueOf(msg.charAt(0));
                //System.out.println(msg);
                repaint();
                t.sleep(100);              
                }
        }
        catch(Exception e)
        {
        e.printStackTrace();
        }
       
        }

        public void paint(Graphics g)
        {
        Font f=new Font("Time New Roman",Font.BOLD,20);
        g.setFont(f);
        g.setColor(Color.blue);
        g.drawString(msg,100,200);
        }

}

/*


*/






/*
 * 1.1 version.
 */

import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

/*
 * Based on Arthur van Hoff's animation examples, this applet
 * can serve as a template for all animation applets.
 */

public class AnimatorApplet extends Applet
   implements Runnable {
    int frameNumber = -1;
    int delay;
    Thread animatorThread;
    boolean frozen = false;

    public void init() {
        String str;
        int fps = 10;

        //How many milliseconds between frames?
        str = getParameter("fps");
        try {
            if (str != null) {
                fps = Integer.parseInt(str);
            }
        } catch (Exception e) {}
        delay = (fps > 0) ? (1000 / fps) : 100;

addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                if (frozen) {
                    frozen = false;
                    start();
                } else {
                    frozen = true;
                    stop();
                }
            }
       });
    }

    public void start() {
        if (frozen) {
            //Do nothing.  The user has requested that we
            //stop changing the image.
        } else {
            //Start animating!
            if (animatorThread == null) {
                animatorThread = new Thread(this);
            }
            animatorThread.start();
        }
    }

    public void stop() {
        //Stop the animating thread.
        animatorThread = null;
    }

    public void run() {
        //Just to be nice, lower this thread's priority
        //so it can't interfere with other processing going on.
        Thread.currentThread().setPriority(Thread.MIN_PRIORITY);

        //Remember the starting time.
        long startTime = System.currentTimeMillis();

        //Remember which thread we are.
        Thread currentThread = Thread.currentThread();

        //This is the animation loop.
        while (currentThread == animatorThread) {
            //Advance the animation frame.
            frameNumber++;

            //Display it.
            repaint();

            //Delay depending on how far we are behind.
            try {
                startTime += delay;
                Thread.sleep(Math.max(0,
                             startTime-System.currentTimeMillis()));
            } catch (InterruptedException e) {
                break;
            }
        }
    }

    //Draw the current frame of animation.
    public void paint(Graphics g) {
        g.drawString("Frame " + frameNumber, 0, 30);
    }
}
//        PROGRAM TO PRINT THE GREATEST USING APPLET

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

/**/

public class ap3gt extends Applet implements ActionListener
{
        Label l1,l2,l3; TextField t1,t2,t3;  TextArea ta;
        Button b1,b2;   int x,y,z;

        public void init()
        {
          setLayout(null);
          l1=new Label("First Number"); l2=new Label("Second Number");
          l3=new Label("Third Number");
          b1=new Button("Click Me For Result"); b2=new Button("Clear");
          t1=new TextField(); t2=new TextField(); t3=new TextField();
          ta=new TextArea();
          b1.addActionListener(this);  b2.addActionListener(this);
          l1.setBounds(40,40,130,20);  t1.setBounds(200,40,130,20);
          l2.setBounds(40,80,130,20);  t2.setBounds(200,80,130,20);
          l3.setBounds(40,120,130,20); t3.setBounds(200,120,130,20);
          b1.setBounds(40,180,150,20); b2.setBounds(220,180,70,20);
          ta.setBounds(60,240,250,90);
          add(l1);add(l2);add(l3);add(t1);add(t2);add(t3);
          add(b1);add(b2);add(ta);
          }
       public void actionPerformed(ActionEvent ae)
        {
          if(ae.getSource()==b1)
          {
                  ta.setText("");
                  x=Integer.parseInt(t1.getText());
                  y=Integer.parseInt(t2.getText());
                  z=Integer.parseInt(t3.getText());
                  if(x>y) { if(x>z) {
                            ta.append(x+" is the biggest Number"); }
                            else {
                           ta.append(z+" is the biggest Number"); } }
                   else { if(y>z) { ta.append(y+" is the biggest Number"); }
                   else { ta.append(z+" is the biggest Number"); } } }
          else if(ae.getSource()==b2)
          {
                  t1.setText("");
                  t2.setText("");
                  t3.setText("");
          }
  }
}
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;



public class app extends Applet implements AcitonListener

{import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.io.*;
import java.lang.*;

/*


*/

public class appcal extends Applet implements ActionListener
{

Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12,b13,b14;

TextField t1;

String str,str1,str3;
int n1,n2,n3;
String str2=0 + "";

public void init()
{
setLayout(null);
t1 = new TextField(20);

b0 = new Button("0");
b1 = new Button("1");
b2 = new Button("2");
b3 = new Button("3");
b4 = new Button("4");
b5 = new Button("5");
b6 = new Button("6");
b7 = new Button("7");
b8 = new Button("8");
b9 = new Button("9");
b10 = new Button("+");
b11 = new Button("-");
b12 = new Button("*");
b13 = new Button("/");
b14 = new Button("=");


add(t1);
add(b0);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(b6);
add(b7);
add(b8);
add(b9);
add(b10);
add(b11);
add(b12);
add(b13);
add(b14);


b0.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);


t1.setBounds(100,100,200,30);

b1.setBounds(100,150,50,50);
b2.setBounds(150,150,50,50);
b3.setBounds(200,150,50,50);
b4.setBounds(250,150,50,50);

b5.setBounds(100,200,50,50);
b6.setBounds(150,200,50,50);
b7.setBounds(200,200,50,50);
b8.setBounds(250,200,50,50);

b9.setBounds(100,250,50,50);
b0.setBounds(150,250,50,50);
b10.setBounds(200,250,50,50);
b11.setBounds(250,250,50,50);

b12.setBounds(100,300,50,50);
b13.setBounds(150,300,50,50);
b14.setBounds(200,300,50,50);
/*b2.setBounds(250,300,50,50);

b2.setBounds(150,150,50,50);


*/}

public void actionPerformed(ActionEvent e)

{

str1 = e.getActionCommand();

if(str1.equals("0"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("1"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("2"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("3"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("4"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("5"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("6"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("7"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("8"))
{
str2 = str2 + str1;
t1.setText(str2);
}
if(str1.equals("9"))
{
str2 = str2 + str1;
t1.setText(str2);
}

if(str1.equals("+"))
{
str = 0 +"";
str = t1.getText();
n1 = Integer.parseInt(str);
str3 = str1;
str2 = "";
}
if(str1.equals("-"))
{
n1 = Integer.parseInt(str2);
str3 = str1;
str2 = "";
}
if(str1.equals("*"))
{
n1 = Integer.parseInt(str2);
str3 = str1;
str2 = "";
}
if(str1.equals("/"))
{
n1 = Integer.parseInt(str2);
str3 = str1;
str2 = "";
}

if(str1.equals("="))
{
str2 = t1.getText();
n2 = Integer.parseInt(str2);

if(str3.equals("+"))
{
n3 = n1 + n2;
}
if(str3.equals("-"))
{
n3 = n1 + n2;
}
if(str3.equals("*"))
{
n3 = n1 + n2;
}
if(str3.equals("/"))
{
n3 = n1 + n2;
}
str3 = n3 + "";
t1.setText(str3);
}


}
}/*
 * @(#)Applet.java 1.70 01/12/03
 *
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package java.applet;

import java.awt.*;
import java.awt.image.ColorModel;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Hashtable;
import java.util.Locale;
import javax.accessibility.*;

/**
 * An applet is a small program that is intended not to be run on
 * its own, but rather to be embedded inside another application.
 *
 * The Applet class must be the superclass of any
 * applet that is to be embedded in a Web page or viewed by the Java
 * Applet Viewer. The Applet class provides a standard
 * interface between applets and their environment.
 *
 * @author      Arthur van Hoff
 * @author      Chris Warth
 * @version     1.70, 12/03/01
 * @since       JDK1.0
 */
public class Applet extends Panel {
   
    /**
     * Creates a new Applet object
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @see java.awt.GraphicsEnvironment#isHeadless
     * @since 1.4
     */
    public Applet() throws HeadlessException {
        if (GraphicsEnvironment.isHeadless()) {
            throw new HeadlessException();
        }
    }
   
    /**
     * Applets can be serialized but the following conventions MUST be followed:
     *
     * Before Serialization:
     * An applet must be in STOPPED state.
     *
     * After Deserialization:
     * The applet will be restored in STOPPED state (and most clients will
     * likely move it into RUNNING state).
     * The stub field will be restored by the reader.
     */
    transient private AppletStub stub;

    /* version ID for serialized form. */
    private static final long serialVersionUID = -5836846270535785031L;

    /**
     * Read an applet from an object input stream.
     * @exception HeadlessException if
     * GraphicsEnvironment.isHeadless() returns
     * true
     * @serial
     * @see java.awt.GraphicsEnvironment#isHeadless
     * @since 1.4
     */
    private void readObject(ObjectInputStream s)
        throws ClassNotFoundException, IOException, HeadlessException {
        if (GraphicsEnvironment.isHeadless()) {
            throw new HeadlessException();
        }
        s.defaultReadObject();
    }

    /**
     * Sets this applet's stub. This is done automatically by the system.
     *
     * @param   stub   the new stub.
     */
    public final void setStub(AppletStub stub) {
this.stub = (AppletStub)stub;
    }

    /**
     * Determines if this applet is active. An applet is marked active
     * just before its start method is called. It becomes
     * inactive just before its stop method is called.
     *
     * @return  true if the applet is active;
     *          false otherwise.
     * @see     java.applet.Applet#start()
     * @see     java.applet.Applet#stop()
     */
    public boolean isActive() {
if (stub != null) {
   return stub.isActive();
} else { // If stub field not filled in, applet never active
   return false;
}
    }

    /**
     * Returns an absolute URL naming the directory of the document in which
     * the applet is embedded.  For example, suppose an applet is contained
     * within the document:
     *

     *    http://java.sun.com/products/jdk/1.2/index.html
     *
     * The document base is:
     *

     *    http://java.sun.com/products/jdk/1.2/
     *
     *
     * @return  the {@link java.net.URL} of the document that contains this
     *          applet.
     * @see     java.applet.Applet#getCodeBase()
     */
    public URL getDocumentBase() {
return stub.getDocumentBase();
    }

    /**
     * Gets the base URL. This is the URL of the applet itself.
     *
     * @return  the {@link java.net.URL} of
     *          this applet.
     * @see     java.applet.Applet#getDocumentBase()
     */
    public URL getCodeBase() {
return stub.getCodeBase();
    }

    /**
     * Returns the value of the named parameter in the HTML tag. For
     * example, if this applet is specified as
     *

     * <applet code="Clock" width=50 height=50>
     * <param name=Color value="blue">
     * </applet>
     *
     *
     * then a call to getParameter("Color") returns the
     * value "blue".
     *
     * The name argument is case insensitive.
     *
     * @param   name   a parameter name.
     * @return  the value of the named parameter,
     *          or null if not set.
     */
     public String getParameter(String name) {
return stub.getParameter(name);
     }

    /**
     * Determines this applet's context, which allows the applet to
     * query and affect the environment in which it runs.
     *
     * This environment of an applet represents the document that
     * contains the applet.
     *
     * @return  the applet's context.
     */
    public AppletContext getAppletContext() {
return stub.getAppletContext();
    }

    /**
     * Requests that this applet be resized.
     *
     * @param   width    the new requested width for the applet.
     * @param   height   the new requested height for the applet.
     */
    public void resize(int width, int height) {
Dimension d = size();
if ((d.width != width) || (d.height != height)) {
   super.resize(width, height);
   if (stub != null) {
stub.appletResize(width, height);
   }
}
    }

    /**
     * Requests that this applet be resized.
     *
     * @param   d   an object giving the new width and height.
     */
    public void resize(Dimension d) {
resize(d.width, d.height);
    }

    /**
     * Requests that the argument string be displayed in the
     * "status window". Many browsers and applet viewers
     * provide such a window, where the application can inform users of
     * its current state.
     *
     * @param   msg   a string to display in the status window.
     */
    public void showStatus(String msg) {
getAppletContext().showStatus(msg);
    }

    /**
     * Returns an Image object that can then be painted on
     * the screen. The url that is passed as an argument
     * must specify an absolute URL.
     *
     * This method always returns immediately, whether or not the image
     * exists. When this applet attempts to draw the image on the screen,
     * the data will be loaded. The graphics primitives that draw the
     * image will incrementally paint on the screen.
     *
     * @param   url   an absolute URL giving the location of the image.
     * @return  the image at the specified URL.
     * @see     java.awt.Image
     */
    public Image getImage(URL url) {
return getAppletContext().getImage(url);
    }

    /**
     * Returns an Image object that can then be painted on
     * the screen. The url argument must specify an absolute
     * URL. The name argument is a specifier that is
     * relative to the url argument.
     *
     * This method always returns immediately, whether or not the image
     * exists. When this applet attempts to draw the image on the screen,
     * the data will be loaded. The graphics primitives that draw the
     * image will incrementally paint on the screen.
     *
     * @param   url    an absolute URL giving the base location of the image.
     * @param   name   the location of the image, relative to the
     *                 url argument.
     * @return  the image at the specified URL.
     * @see     java.awt.Image
     */
    public Image getImage(URL url, String name) {
try {
   return getImage(new URL(url, name));
} catch (MalformedURLException e) {
   return null;
}
    }

    /**
     * Get an audio clip from the given URL.
     *
     * @param url points to the audio clip
     * @return the audio clip at the specified URL.
     *
     * @since       1.2
     */
    public final static AudioClip newAudioClip(URL url) {
        return new sun.applet.AppletAudioClip(url);
    }

    /**
     * Returns the AudioClip object specified by the
     * URL argument.
     *
     * This method always returns immediately, whether or not the audio
     * clip exists. When this applet attempts to play the audio clip, the
     * data will be loaded.
     *
     * @param   url  an absolute URL giving the location of the audio clip.
     * @return  the audio clip at the specified URL.
     * @see     java.applet.AudioClip
     */
    public AudioClip getAudioClip(URL url) {
return getAppletContext().getAudioClip(url);
    }

    /**
     * Returns the AudioClip object specified by the
     * URL and name arguments.
     *
     * This method always returns immediately, whether or not the audio
     * clip exists. When this applet attempts to play the audio clip, the
     * data will be loaded.
     *
     * @param   url    an absolute URL giving the base location of the
     *                 audio clip.
     * @param   name   the location of the audio clip, relative to the
     *                 url argument.
     * @return  the audio clip at the specified URL.
     * @see     java.applet.AudioClip
     */
    public AudioClip getAudioClip(URL url, String name) {
try {
   return getAudioClip(new URL(url, name));
} catch (MalformedURLException e) {
   return null;
}
    }

    /**
     * Returns information about this applet. An applet should override
     * this method to return a String containing information
     * about the author, version, and copyright of the applet.
     *
     * The implementation of this method provided by the
     * Applet class returns null.
     *
     * @return  a string containing information about the author, version, and
     *          copyright of the applet.
     */
    public String getAppletInfo() {
return null;
    }

    /**
     * Gets the Locale for the applet, if it has been set.
     * If no Locale has been set, then the default Locale
     * is returned.
     *
     * @return  the Locale for the applet
     * @since   JDK1.1
     */

    public Locale getLocale() {
      Locale locale = super.getLocale();
      if (locale == null) {
return Locale.getDefault();
      }
      return locale;
    }

    /**
     * Returns information about the parameters that are understood by
     * this applet. An applet should override this method to return an
     * array of Strings describing these parameters.
     *
     * Each element of the array should be a set of three
     * Strings containing the name, the type, and a
     * description. For example:
     *

     * String pinfo[][] = {
     * {"fps",    "1-10",    "frames per second"},
     * {"repeat", "boolean", "repeat image loop"},
     * {"imgs",   "url",     "images directory"}
     * };
     *
     *
     * The implementation of this method provided by the
     * Applet class returns null.
     *
     * @return  an array describing the parameters this applet looks for.
     */
    public String[][] getParameterInfo() {
return null;
    }

    /**
     * Plays the audio clip at the specified absolute URL. Nothing
     * happens if the audio clip cannot be found.
     *
     * @param   url   an absolute URL giving the location of the audio clip.
     */
    public void play(URL url) {
AudioClip clip = getAudioClip(url);
if (clip != null) {
   clip.play();
}
    }

    /**
     * Plays the audio clip given the URL and a specifier that is
     * relative to it. Nothing happens if the audio clip cannot be found.
     *
     * @param   url    an absolute URL giving the base location of the
     *                 audio clip.
     * @param   name   the location of the audio clip, relative to the
     *                 url argument.
     */
    public void play(URL url, String name) {
AudioClip clip = getAudioClip(url, name);
if (clip != null) {
   clip.play();
}
    }

    /**
     * Called by the browser or applet viewer to inform
     * this applet that it has been loaded into the system. It is always
     * called before the first time that the start method is
     * called.
     *
     * A subclass of Applet should override this method if
     * it has initialization to perform. For example, an applet with
     * threads would use the init method to create the
     * threads and the destroy method to kill them.
     *
     * The implementation of this method provided by the
     * Applet class does nothing.
     *
     * @see     java.applet.Applet#destroy()
     * @see     java.applet.Applet#start()
     * @see     java.applet.Applet#stop()
     */
    public void init() {
    }

    /**
     * Called by the browser or applet viewer to inform
     * this applet that it should start its execution. It is called after
     * the init method and each time the applet is revisited
     * in a Web page.
     *
     * A subclass of Applet should override this method if
     * it has any operation that it wants to perform each time the Web
     * page containing it is visited. For example, an applet with
     * animation might want to use the start method to
     * resume animation, and the stop method to suspend the
     * animation.
     *
     * The implementation of this method provided by the
     * Applet class does nothing.
     *
     * @see     java.applet.Applet#destroy()
     * @see     java.applet.Applet#init()
     * @see     java.applet.Applet#stop()
     */
    public void start() {
    }

    /**
     * Called by the browser or applet viewer to inform
     * this applet that it should stop its execution. It is called when
     * the Web page that contains this applet has been replaced by
     * another page, and also just before the applet is to be destroyed.
     *
     * A subclass of Applet should override this method if
     * it has any operation that it wants to perform each time the Web
     * page containing it is no longer visible. For example, an applet
     * with animation might want to use the start method to
     * resume animation, and the stop method to suspend the
     * animation.
     *
     * The implementation of this method provided by the
     * Applet class does nothing.
     *
     * @see     java.applet.Applet#destroy()
     * @see     java.applet.Applet#init()
     */
    public void stop() {
    }

    /**
     * Called by the browser or applet viewer to inform
     * this applet that it is being reclaimed and that it should destroy
     * any resources that it has allocated. The stop method
     * will always be called before destroy.
     *
     * A subclass of Applet should override this method if
     * it has any operation that it wants to perform before it is
     * destroyed. For example, an applet with threads would use the
     * init method to create the threads and the
     * destroy method to kill them.
     *
     * The implementation of this method provided by the
     * Applet class does nothing.
     *
     * @see     java.applet.Applet#init()
     * @see     java.applet.Applet#start()
     * @see     java.applet.Applet#stop()
     */
    public void destroy() {
    }

    //
    // Accessibility support
    //

    AccessibleContext accessibleContext = null;

    /**
     * Gets the AccessibleContext associated with this Applet.
     * For applets, the AccessibleContext takes the form of an
     * AccessibleApplet.
     * A new AccessibleApplet instance is created if necessary.
     *
     * @return an AccessibleApplet that serves as the
     *         AccessibleContext of this Applet
     */
    public AccessibleContext getAccessibleContext() {
        if (accessibleContext == null) {
            accessibleContext = new AccessibleApplet();
        }
        return accessibleContext;
    }

    /**
     * This class implements accessibility support for the
     * Applet class.  It provides an implementation of the
     * Java Accessibility API appropriate to applet user-interface elements.
     */
    protected class AccessibleApplet extends AccessibleAWTPanel {

        /**
         * Get the role of this object.
         *
         * @return an instance of AccessibleRole describing the role of the
         * object
         */
        public AccessibleRole getAccessibleRole() {
            return AccessibleRole.FRAME;
        }

        /**
         * Get the state of this object.
         *
         * @return an instance of AccessibleStateSet containing the current
         * state set of the object
         * @see AccessibleState
         */
        public AccessibleStateSet getAccessibleStateSet() {
            AccessibleStateSet states = super.getAccessibleStateSet();
            states.add(AccessibleState.ACTIVE);
            return states;
        }

    }
}
/*
 * @(#)AppletContext.java 1.27 01/12/03
 *
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package java.applet;

import java.awt.Image;
import java.awt.Graphics;
import java.awt.image.ColorModel;
import java.net.URL;
import java.util.Enumeration;
import java.io.InputStream;
import java.io.IOException;
import java.util.Iterator;

/**
 * This interface corresponds to an applet's environment: the
 * document containing the applet and the other applets in the same
 * document.
 *
 * The methods in this interface can be used by an applet to obtain
 * information about its environment.
 *
 * @author Arthur van Hoff
 * @version     1.27, 12/03/01
 * @since       JDK1.0
 */
public interface AppletContext {
    /**
     * Creates an audio clip.
     *
     * @param   url   an absolute URL giving the location of the audio clip.
     * @return  the audio clip at the specified URL.
     */
    AudioClip getAudioClip(URL url);

    /**
     * Returns an Image object that can then be painted on
     * the screen. The url argument that is
     * passed as an argument must specify an absolute URL.
     *
     * This method always returns immediately, whether or not the image
     * exists. When the applet attempts to draw the image on the screen,
     * the data will be loaded. The graphics primitives that draw the
     * image will incrementally paint on the screen.
     *
     * @param   url   an absolute URL giving the location of the image.
     * @return  the image at the specified URL.
     * @see     java.awt.Image
     */
    Image getImage(URL url);

    /**
     * Finds and returns the applet in the document represented by this
     * applet context with the given name. The name can be set in the
     * HTML tag by setting the name attribute.
     *
     * @param   name   an applet name.
     * @return  the applet with the given name, or null if
     *          not found.
     */
    Applet getApplet(String name);

    /**
     * Finds all the applets in the document represented by this applet
     * context.
     *
     * @return  an enumeration of all applets in the document represented by
     *          this applet context.
     */
    Enumeration getApplets();

    /**
     * Replaces the Web page currently being viewed with the given URL.
     * This method may be ignored by applet contexts that are not
     * browsers.
     *
     * @param   url   an absolute URL giving the location of the document.
     */
    void showDocument(URL url);

    /**
     * Requests that the browser or applet viewer show the Web page
     * indicated by the url argument. The
     * target argument indicates in which HTML frame the
     * document is to be displayed.
     * The target argument is interpreted as follows:
     *
     *

     * "_self"  Show in the window and frame that
     *                                   contain the applet.
     * "_parent"Show in the applet's parent frame. If
     *                                   the applet's frame has no parent frame,
     *                                   acts the same as "_self".
     * "_top"   Show in the top-level frame of the applet's
     *                                   window. If the applet's frame is the
     *                                   top-level frame, acts the same as "_self".
     * "_blank" Show in a new, unnamed
     *                                   top-level window.
     * nameShow in the frame or window named name. If
     *                        a target named name does not already exist, a
     *                        new top-level window with the specified name is created,
     *                        and the document is shown there.
     *
     *
     * An applet viewer or browser is free to ignore showDocument.
     *
     * @param   url   an absolute URL giving the location of the document.
     * @param   target   a String indicating where to display
     *                   the page.
     */
    public void showDocument(URL url, String target);

    /**
     * Requests that the argument string be displayed in the
     * "status window". Many browsers and applet viewers
     * provide such a window, where the application can inform users of
     * its current state.
     *
     * @param   status   a string to display in the status window.
     */
    void showStatus(String status);

    /**
     * Associates the specified stream with the specified key in this
     * applet context. If the applet context previously contained a mapping
     * for this key, the old value is replaced.
     *
     * For security reasons, mapping of streams and keys exists for each
     * codebase. In other words, applet from one codebase cannot access
     * the streams created by an applet from a different codebase
     *
     * @param key key with which the specified value is to be associated.
     * @param stream stream to be associated with the specified key. If this
     *               parameter is null, the specified key is removed 
     *               in this applet context.
     * @throws IOException if the stream size exceeds a certain
     *         size limit. Size limit is decided by the implementor of this
     *         interface.
     * @since JDK1.4
     */
    public void setStream(String key, InputStream stream)throws IOException;

    /**
     * Returns the stream to which specified key is associated within this
     * applet context. Returns null if the applet context contains
     * no stream for this key.
     *
     * For security reasons, mapping of streams and keys exists for each
     * codebase. In other words, applet from one codebase cannot access
     * the streams created by an applet from a different codebase
     *
     * @return the stream to which this applet context maps the key
     * @param key key whose associated stream is to be returned.
     * @since JDK1.4
     */
    public InputStream getStream(String key);

    /**
     * Finds all the keys of the streams in this applet context.
     *
     * For security reasons, mapping of streams and keys exists for each
     * codebase. In other words, applet from one codebase cannot access
     * the streams created by an applet from a different codebase
     *
     * @return  an Iterator of all the names of the streams in this applet
     *          context.
     * @since JDK1.4
     */
    public Iterator getStreamKeys();
}
import java.applet.*;
import java.awt.*;
/*


*/
public class AppletParam extends Applet
{
   public void paint(Graphics g)
   {
     g.drawString(getParameter("p1"),50,50);
   }
}   import java.applet.*;
import java.awt.*;
/*


*/
public class AppletParam1 extends Applet
{
Image img;
public void init()
{
img=getImage(getCodeBase(),getParameter("p1"));
}

   public void paint(Graphics g)
   {
     g.drawImage(img,50,50,this);
   }
}import javax.swing.*;
import java.applet.*;
import java.net.URL;

//Loads and holds a bunch of audio files whose locations are specified
//relative to a fixed base URL.
class AppletSoundList extends java.util.Hashtable {
    JApplet applet;
    URL baseURL;

    public AppletSoundList(JApplet applet, URL baseURL) {
        super(5); //Initialize Hashtable with capacity of 5 entries.
        this.applet = applet;
        this.baseURL = baseURL;
    }

    public void startLoading(String relativeURL) {
        new AppletSoundLoader(applet, this,
                              baseURL, relativeURL);
    }

    public AudioClip getClip(String relativeURL) {
        return (AudioClip)get(relativeURL);
    }

    public void putClip(AudioClip clip, String relativeURL) {
        put(relativeURL, clip);
    }
}
import javax.swing.*;
import java.applet.*;
import java.net.URL;

class AppletSoundLoader extends Thread {
    JApplet applet;
    AppletSoundList soundList;
    URL baseURL;
    String relativeURL;

    public AppletSoundLoader(JApplet applet,
                             AppletSoundList soundList,
                             URL baseURL,
                             String relativeURL) {
        this.applet = applet;
        this.soundList = soundList;
        this.baseURL = baseURL;
        this.relativeURL = relativeURL;
        setPriority(MIN_PRIORITY);
        start();
    }

    public void run() {
        AudioClip audioClip = applet.getAudioClip(baseURL, relativeURL);
        soundList.putClip(audioClip, relativeURL);
    }
}
/*
 * @(#)AppletStub.java 1.22 01/12/03
 *
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package java.applet;

import java.net.URL;

/**
 * When an applet is first created, an applet stub is attached to it
 * using the applet's setStub method. This stub
 * serves as the interface between the applet and the browser
 * environment or applet viewer environment in which the application
 * is running.
 *
 * @author Arthur van Hoff
 * @version     1.22, 12/03/01
 * @see         java.applet.Applet#setStub(java.applet.AppletStub)
 * @since       JDK1.0
 */
public interface AppletStub {
    /**
     * Determines if the applet is active. An applet is active just
     * before its start method is called. It becomes
     * inactive just before its stop method is called.
     *
     * @return  true if the applet is active;
     *          false otherwise.
     */
    boolean isActive();

    /**
     * Returns an absolute URL naming the directory of the document in which
     * the applet is embedded.  For example, suppose an applet is contained
     * within the document:
     *

     *    http://java.sun.com/products/jdk/1.2/index.html
     *
     * The document base is:
     *

     *    http://java.sun.com/products/jdk/1.2/
     *
     *
     * @return  the {@link java.net.URL} of the document that contains this
     *          applet.
     * @see     java.applet.AppletStub#getCodeBase()
     */
    URL getDocumentBase();

    /**
     * Gets the base URL.
     *
     * @return  the URL of the applet.
     */
    URL getCodeBase();

    /**
     * Returns the value of the named parameter in the HTML tag. For
     * example, if an applet is specified as
     *

     * <applet code="Clock" width=50 height=50>
     * <param name=Color value="blue">
     * </applet>
     *
     *
     * then a call to getParameter("Color") returns the
     * value "blue".
     *
     * @param   name   a parameter name.
     * @return  the value of the named parameter,
     * or null if not set.
     */
    String getParameter(String name);

    /**
     * Gets a handler to the applet's context.
     *
     * @return  the applet's context.
     */
    AppletContext getAppletContext();

    /**
     * Called when the applet wants to be resized.
     *
     * @param   width    the new requested width for the applet.
     * @param   height   the new requested height for the applet.
     */
    void appletResize(int width, int height);
}
import java.awt.*;
import java.applet.*;

public class applt extends java.applet.Applet
{

public void init()
{
    resize(250,250);
}

public void paint(Graphics g)
{
Font myfont=new Font("Times new roman",Font.BOLD + Font.ITALIC,25);
g.setFont(myfont);
g.drawRect(100,100,300,450);
g.setColor(Color.orange);
g.fillRect(100,100,30,50);
g.setColor(Color.red);
g.drawString("hello world",120,120);
g.drawRect(100,100,300,450);
g.setColor(Color.green);
g.fillRect(150,150,30,50);

}
}
   













/*
TITLE
Write a program that works a simple calculator. Use Grid Layout to arrange button
for the digits and for the +,-,/,%. Add  a text field to diaplay the result.
*/

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

//event listener interface for event handling

class actlstn implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
       
                int no=0,val,prev;
                String txt;
Button bt;
bt=(Button)e.getSource();
                txt=bt.getLabel();

                if(txt.equals("C"))
{
                appltcal.t.setText("");
}
                else
                if(txt.equals("+"))
{
                        if(appltcal.sta==0)
                        {
                        appltcal.pval=Integer.parseInt(appltcal.t.getText());
                        appltcal.t.setText("");
                        appltcal.sta=1;
                        }
                        else
                        {
                        no=appltcal.pval;
                        no+=Integer.parseInt(appltcal.t.getText());
                        appltcal.t.setText(String.valueOf(no));
                        appltcal.sta=0;
                        }
                }                      

         }
}
public class  appltcal extends Applet
{
        static int sta,pval;
        static TextField t;
        Button a,m,d,s,r,b;
        Panel p;
public void init()
{      
                t=new TextField("000000");
                a=new Button("+");
                s=new Button("-");
                d=new Button("/");
                m=new Button("*");
                r=new Button("%");
                b=new Button("C");
                //adding listener
                actlstn lstn=new actlstn();
                a.addActionListener(lstn);
                s.addActionListener(lstn);
                d.addActionListener(lstn);
                m.addActionListener(lstn);
                r.addActionListener(lstn);
               b.addActionListener(lstn);            
                //setting panel and layout
                p=new Panel();
                p.setLayout(new GridLayout(3,2));
                p.add(t);
                p.add(a);
                p.add(s);
                p.add(d);
                p.add(m);
                p.add(r);
                p.add(b);            
                //adding pane
                add(p);
                setSize(300,400);
                setVisible(true);
     }
public void paint(Graphics g)
{
                showStatus("Calculator...");
}

}




//applet code

/*


*/
import java.awt.*;
import java.applet.*;

public class appltdraw extends java.applet.Applet
{

public void init()
{
    resize(250,250);
}

public void paint(Graphics g)
{
//orange rect
g.drawRect(100,100,300,450);
g.setColor(Color.orange);
g.fillRect(100,100,30,50);
//red line
g.setColor(Color.red);
g.drawLine(0,0,120,120);
//blue rect
g.setColor(Color.blue);
g.drawRect(100,100,30,50);
g.setColor(Color.green);
g.fillRect(150,150,30,50);
//gray oval
g.setColor(Color.gray);
g.drawOval(0,0,50,100);
}
}

/*


*/

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

class actlstn implements ActionListener
{
        public void actionPerformed(ActionEvent e)
        {
        int ctr=1,no=0,fact=1;
        Button bt;
        bt=(Button)e.getSource();
        if((bt.getLabel()).equals("compute"))
        {
        no=Integer.parseInt(appltfact.t1.getText());
        while(ctr<=no)

        {
        fact*=ctr;
        ctr++;
        }
        appltfact.t2.setText(String.valueOf(fact));
        }
        System.out.println("....");
        }
}
public class appltfact extends Applet
{
        static TextField t1,t2;
        Label l1,l2;
        Button b;
        public void init()
        {
        l1=new Label("enter an integer.");
        l2=new Label("fatorial val:");
        t1=new TextField();
        t2=new TextField(" ");
        b=new Button("compute");
        add(l1);
        add(t1);
        add(l2);
        add(t2);
        b.addActionListener(new actlstn());
        add(b);
        setSize(300,400);
        setVisible(true);
        }
      public void paint(Graphics g)
      {
      showStatus("computing Factorial value...");
      }
}

/*


*/
import java.applet.*;
import java.awt.Graphics;
import java.awt.TextField;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.Panel;

class mmlstn implements MouseMotionListener
{
public void mouseDragged(MouseEvent m)
{
}
public void mouseMoved(MouseEvent m)
{
int x,y;
x=m.getX();
y=m.getY();
appltmouse.t.setText(String.valueOf(x)+" , "+String.valueOf(y));
}

}

public class appltmouse extends Applet
{
static TextField t;
public void init()
{
t=new TextField("........");
Panel p=new Panel();
p.add(t);
add(p);
//mouse event deligation
addMouseMotionListener(new mmlstn());
setSize(300,400);
setVisible(true);
}
public void paint(Graphics g)
{
g.drawRect(20,20,200,150);
}
}
/*


*/


import java.applet.*;
import java.awt.Graphics;
import java.awt.TextField;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseEvent;
import java.awt.Panel;

public class appltmouse1 extends Applet implements MouseMotionListener
{
static TextField t;
int x,y;
public void mouseDragged(MouseEvent m)
{
}
public void mouseMoved(MouseEvent m)
{
x=m.getX();
y=m.getY();
appltmouse.t.setText(String.valueOf(x)+" , "+String.valueOf(y));
repaint();
}
public void init()
{
t=new TextField("........");
Panel p=new Panel();
p.add(t);
add(p);
//mouse event deligation
addMouseMotionListener(this);
setSize(300,400);
setVisible(true);
}
public void paint(Graphics g)
{
g.drawRect(20,20,100,200);
g.drawString(t.getText(),x,y);
}
}
/*


*/


import java.io.*;
class area
{
int x;
double y;

void cal(double pi,int ra)
{
y = pi*ra*ra;
System.out.println("Circle area is\t:"+y);
}
void cal(int len)
{
x = len*len;
System.out.println("Squre area is\t:"+x);
}
void cal(int len,int br)
{
x = len*br;
System.out.println("Rectangle area is\t:"+x);
}
}
class area1
{
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
System.out.print("choose any one \t 1.CIRCLE \t 2.SQURE \t 3.RECTANGLE\t:");
int a = Integer.parseInt(in.readLine());
area A = new area();
if(a==1)
{
System.out.print("Enter the radius\t:");
int b = Integer.parseInt(in.readLine());
A.cal(3.14,b);
}
else if(a==2)
{
System.out.print("Enter the length\t:");
int c = Integer.parseInt(in.readLine());
A.cal(c);
}
else
{
System.out.print("Enter the length\t:");
int d = Integer.parseInt(in.readLine());
System.out.print("Enter the breath\t:");
int e = Integer.parseInt(in.readLine());
A.cal(d,e);
}
}
}import java.io.*;
import java.lang.*;
class areae extends Exception
{
areae(String msg1)
{
super(msg1);
}
}
class area
{
int x;
double y;

void cal(double pi,int ra)
{
y = pi*ra*ra;
System.out.println("Circle area is\t:"+y);
}
void cal(int len)
{
x = len*len;
System.out.println("Squre area is\t:"+x);
}
void cal(int len,int br)
{
x = len*br;
System.out.println("Rectangle area is\t:"+x);
}
}
class area11
{
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
System.out.print("choose any one \t 1.CIRCLE \t 2.SQURE \t 3.RECTANGLE\t:");
try
{
int a = Integer.parseInt(in.readLine());
area A = new area();
if(a>=4 || a== 0)
throw new areae("Your Choice is Wrong");
if(a==1)
{
System.out.print("Enter the radius\t:");
int b = Integer.parseInt(in.readLine());
A.cal(3.14,b);
}
else if(a==2)
{
System.out.print("Enter the length\t:");
int c = Integer.parseInt(in.readLine());
if(c<=0)
throw new areae("Your length is worng");
A.cal(c);
}
else if(a==3)
{
System.out.print("Enter the length\t:");
int d = Integer.parseInt(in.readLine());
System.out.print("Enter the breath\t:");
int e = Integer.parseInt(in.readLine());
if(dthrow new areae("Your Breath is high");
A.cal(d,e);
}
}
catch (areae x)
{
System.out.println(x.getMessage());
}
}
}public class arith
{
public static void main(float a,float b)
{
float add,sub,mul,div;
add = a+b;



System.out.println("\n\n result of the sum is... " + add);




}}class Aritmatika{
    public static void main(String[] args) {
     
    int a = 20;
    int b = 10;
   
    System.out.println("Penggunaan Operator Aritmatika ");
    System.out.println("Nilai awal a adalah : "+a);
    System.out.println("Nilai awal b adalah : "+b);
    System.out.println("Hasil dari a + b = " +(a + b));
    System.out.println("Hasil dari a - b = " +(a - b));
    System.out.println("Hasil dari a / b = " +(a / b));
    System.out.println("Hasil dari a * b = " +(a * b));
    System.out.println("Hasil dari a % b = " +(a % b));
    }
}

class Array2D {
    public static void main(String[] args) {
   
    int[][] arrx;              // Cara 1 Array 2 Dimensi
    arrx = new int[3][3];
   
    arrx[0][0] = 1;
    arrx[0][1] = 2;
    arrx[0][2] = 3;
   
    arrx[1][0] = 4;
    arrx[1][1] = 5;
    arrx[1][2] = 6;
   
    arrx[2][0] = 7;
    arrx[2][1] = 8;
    arrx[2][2] = 9;
   
    System.out.println("Nilai arrx[0] : " + arrx[0][0]);
    System.out.println("Nilai arrx[0] : " + arrx[0][1]);
    System.out.println("Nilai arrx[0] : " + arrx[0][2]);
    System.out.println("Nilai arrx[1] : " + arrx[1][0]);
    System.out.println("Nilai arrx[1] : " + arrx[1][1]);
    System.out.println("Nilai arrx[1] : " + arrx[1][2]);
    System.out.println("Nilai arrx[2] : " + arrx[2][0]);
    System.out.println("Nilai arrx[2] : " + arrx[2][1]);
    System.out.println("Nilai arrx[2] : " + arrx[2][2]);
       
    int[][] arry = {{10,20,30},{40,50,60},{70,80,90}}  ;      // Cara 2 Array 2 Dimensi dgn ukuran 3 * 3 = 9
       
    System.out.println("Nilai arry[0] : " + arry[0][0]);
    System.out.println("Nilai arry[0] : " + arry[0][1]);
    System.out.println("Nilai arry[0] : " + arry[0][2]);
    System.out.println("Nilai arry[1] : " + arry[1][0]);
    System.out.println("Nilai arry[1] : " + arry[1][1]);
    System.out.println("Nilai arry[1] : " + arry[1][2]);
    System.out.println("Nilai arry[2] : " + arry[2][0]);
    System.out.println("Nilai arry[2] : " + arry[2][1]);
    System.out.println("Nilai arry[2] : " + arry[2][2]);
   
   
   }
}class Array
{
public static void main(String arg[])
{
try
{
//int arr[]=new int[]{10,20,30,50,60};
int arr[]={10,20,30,40};
/*arr=new int[5];
arr[0]=10;
arr[1]=20;
arr[2]=30;
arr[3]=40;
arr[4]=50;*/
for(int i =0 ;i<=arr.length;i++)
System.out.print(arr[i]+"\t");
}
catch(Exception e)
{
System.out.println("error is ="+e);
}
}
}import java.io.*;
class Array1
{
public static void main(String arg[])
{
try
{
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br= new BufferedReader(r);
int arr[];
arr=new int[5];
int total=0;
for(int j=0;j<=4;j++)
{

System.out.print("enter  no"+j +"=");
arr[j]= Integer.parseInt(br.readLine());
}
for(int i =0 ;i{
total=total+arr[i];
System.out.print(arr[i]+"\t");
}
int avg=total/5;
System.out.println("total     = "+total +"      avg="+avg);
}
catch(Exception e)
{
System.out.println("error is ="+e);
}
}
}class Array2D
{
public static void main(String arg[])
{
int arr[][]=new int[2][];
arr[0]=new int[]{10,20};
arr[1]=new int[]{60,70,80,90};
for(int i=0;i{
for(int j=0;j {
System.out.print(arr[i][j]+"\t");
}
System.out.println();
   }
}
}import java.io.*;
import java.lang.*;
class arraye
{
public static void main(String args[])throws IOException
{
int a[] = new int [5];
int b;
DataInputStream in = new DataInputStream (System.in);
try
{
for(int i=0;i<5 i="" p="">{
System.out.print("choose the array location");
b = Integer.parseInt(in.readLine());
System.out.print("Enter the value");
a[b] = Integer.parseInt(in.readLine());
}
 a[3] /= (a[1]+a[0])/(a[2]-a[4]);
System.out.println("C is :"+a[3]);
}
catch(ArithmeticException x)
{
System.out.println(" IT CAN'T DIVISIBLE BY ZERO");
}
catch(ArrayIndexOutOfBoundsException x)
{
System.out.println(" IT IS EXCEEDED THE LIMIT");
}
catch(ArrayStoreException x)
{
System.out.println(" THE VALUE CAN BE ENTER WRONG FORMAT");
}
}
}/*

- Arrays is a container object that holds fixed no. of values of the same datatype.
- Length of an array is defined when the array is created and remains fixed.
- Each item in the array is called as an element.
- Each element can be accessed by its index number. The index number starts from '0'.

*/

public class arrays
{
public static void main(String[] args)
{
int[] anArray;
//Declares an array of 10 integers

anArray = new int[5];
//Allocates the variable anArray with 4 integers

anArray[0] = 100;
anArray[1] = 200;
anArray[3] = 400;
anArray[2] = 300;
anArray[4] = 500;
//Defines the value at each index of the array

for(int i=0; i<=4; i++)
{
System.out.println("Element at index " + i + " = " + anArray[i]);
}
}
}/*

- 2D arrays are arrays where each element of the array is itself an array
- Visualize it as a matrix or a determinant

*/

import java.io.*;

class arrays2D
{
public static void main(String[] args)
{
String[][] names = {{"Dr.", "Mr."},
{"Anish", "Vivek"},
{"Shrinivasan", "Menon"}};

System.out.println("All possible combinations");
for(int i=0; i<=2; i++)
{
for(int y=0; y<=1; y++)
{
System.out.println("Row: " + i + "Column: " + y + " = " + names[i][y]);
}
}
}
}class ArrayMultiD {
    public static void main(String[] args) {
   
    int[][][] arr3 = {{{10,20,30},{40,50,60}},
                      {{11,21,31},{41,51,61}},
                      {{12,22,32},{42,52,62}}};      // ukuran 3 * 6 = 18
                                 
    System.out.println("Nilai arr3[0] : " + arr3[0][0][0]);
    System.out.println("Nilai arr3[0] : " + arr3[0][0][1]);
    System.out.println("Nilai arr3[0] : " + arr3[0][0][2]);
    System.out.println("Nilai arr3[0] : " + arr3[0][1][0]);
    System.out.println("Nilai arr3[0] : " + arr3[0][1][1]);
    System.out.println("Nilai arr3[0] : " + arr3[0][1][2]);
   
    System.out.println("Nilai arr3[1] : " + arr3[1][0][0]);
    System.out.println("Nilai arr3[1] : " + arr3[1][0][1]);
    System.out.println("Nilai arr3[1] : " + arr3[1][0][2]);
    System.out.println("Nilai arr3[1] : " + arr3[1][1][0]);
    System.out.println("Nilai arr3[1] : " + arr3[1][1][1]);
    System.out.println("Nilai arr3[1] : " + arr3[1][1][2]);
   
    System.out.println("Nilai arr3[2] : " + arr3[2][0][0]);
    System.out.println("Nilai arr3[2] : " + arr3[2][0][1]);
    System.out.println("Nilai arr3[2] : " + arr3[2][0][2]);
    System.out.println("Nilai arr3[2] : " + arr3[2][1][0]);
    System.out.println("Nilai arr3[2] : " + arr3[2][1][1]);
    System.out.println("Nilai arr3[2] : " + arr3[2][1][2]);
   }
}class SingleArray {
    public static void main(String[] args) {
   
    int [] x;                  // Cara 1
    x = new int[3];
    x[0] = 20 ;
    x[1] = 10 ;
    x[2] = 30;
    System.out.println("Nilai x[0] : " + x[0]);
    System.out.println("Nilai x[1] : " + x[1]);
    System.out.println("Nilai x[2] : " + x[2]);


    int [] y = new int[3];      // Cara 2
    y[0] = 20 ;
    y[1] = 10 ;
    y[2] = 30;
    System.out.println("Nilai y[0] : " + y[0]);
    System.out.println("Nilai y[1] : " + y[1]);
    System.out.println("Nilai y[2] : " + y[2]);

   
    int[] z = {20,10,30};           // Cara 3 tdk menggunakan new
    System.out.println("Nilai z[0] : " + z[0]);
    System.out.println("Nilai z[1] : " + z[1]);
    System.out.println("Nilai z[2] : " + z[2]);
    }
}class assertDemo
{
 void sqr(int num)
   {
   assert num>0:"-ve no. not allowed";
    int s=num*num;
     System.out.println("Sqr of "+num+"is" +s);
    }
   public static void main(String arg[])
    {
      assertDemo ad=new assertDemo();
       ad.sqr(10);
       ad.sqr(-8);
      }
 }class AssertTest
{
void sq(int n)
{
assert n>0:"Squiare is not allowed for (-)ve";
int s=n*n;
System.out.println("Square of"+n+" is "+s);
}
public static void main(String s[])
{
AssertTest a=new AssertTest();
a.sq(5);
a.sq(-2);
}
}class Assignment {
    public static void main(String[] args) {
   
    int var = 10;
    int a,b,c;
    a = b = c = 100;
   
    int d,e,f;
    f = 200;
    e = f;
    d = e;
   
    System.out.println("Nilai var : " + var);
    System.out.println("Nilai a   : " + a);
    System.out.println("Nilai b   : " + b);
    System.out.println("Nilai c   : " + c);
    System.out.println("Nilai f   : " + f);
    System.out.println("Nilai e   : " + e);
    System.out.println("Nilai d   : " + d);
   
    int z;
    char Teks1 = 'a';   // dalam Unicode karakter 'a' direpresentasikan dengan angka 97
    z = Teks1 * 100;     // z = 97 * 10;
    System.out.println("Nilai Teks1 : " + Teks1);
    System.out.println("Nilai z     : " + z);

    }
}
/*
 * @(#)AudioClip.java 1.16 01/12/03
 *
 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package java.applet;

/**
 * The AudioClip interface is a simple abstraction for
 * playing a sound clip. Multiple AudioClip items can be
 * playing at the same time, and the resulting sound is mixed
 * together to produce a composite.
 *
 * @author Arthur van Hoff
 * @version     1.16, 12/03/01
 * @since       JDK1.0
 */
public interface AudioClip {
    /**
     * Starts playing this audio clip. Each time this method is called,
     * the clip is restarted from the beginning.
     */
    void play();

    /**
     * Starts playing this audio clip in a loop.
     */
    void loop();

    /**
     * Stops playing this audio clip.
     */
    void stop();
}
import javax.swing.JOptionPane;

public class Average5Subjects
{
        public static void main(String[] args)
        {
    double Average;
    double sMath,sJava,sSociology,sHumanities,sPhysics;
    sMath=Double.parseDouble(JOptionPane.showInputDialog("Input Grade in Math "));
    sJava=Double.parseDouble(JOptionPane.showInputDialog("Input Grade in Java "));
    sSociology=Double.parseDouble(JOptionPane.showInputDialog("Input Grade in Operating System "));
    sHumanities=Double.parseDouble(JOptionPane.showInputDialog("Input Grade in Fil "));
    sPhysics=Double.parseDouble(JOptionPane.showInputDialog("Input Grade in Physics "));
    Average=((sMath + sJava + sSociology+sHumanities+sPhysics)/5);
    JOptionPane.showMessageDialog(null,"Average is " + Average);
    }
}
import java.io.*;

class BacaFile {
    public static void main(String[] args){
        if(args.length==0) {
            System.out.println("Anda harus memasukkan nama file sebagai parameternya.");
            return;
        }

        String data;
        FileReader fin=null;

        try{
            fin = new FileReader(args[0]);

            //bungkus objek FileReader dengan objek BufferedReader
            BufferedReader br = new BufferedReader(fin);

            do{
                data = br.readLine();
                System.out.println(data);
            }while(data!=null);

        }catch(FileNotFoundException e) {
            System.out.println("File : " + args[0] + " tidak ditemukan.");
        }catch(IOException e) {
            System.out.println("Eksepsi tidak diketahui : " + e);
        }finally {
            //tutup file
            if(fin!=null) {
                try{
                    fin.close();
                }catch(IOException err) {
                    System.out.println("Eksepsi tidak diketahui : " + err);
                }
            }
        }
    }
}public class bala {
  public static void main (String args[]) {
    System.out.print("\n Hello, New World!");
  }
}//Program 6
//Program that vanishes the balls when more than 1 ball collide
//submitted by tarveenkaurbhatia (R.I.C.A)
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import javax.swing.*;
/*


*/
public class ballVanish extends Applet implements Runnable,ActionListener
{
  Thread t,t1;
boolean flag,setclr;
Graphics g;
int i=1;
  int x1=0,y1=0,x2=0,y2=0,dia=40;
  int deltaX=1,deltaY=2,deltaX1=2,deltaY1=2;
  int xbound,ybound;
  Button start,stop,add;

  public void init()
{
start = new Button("Start");
stop = new Button("Stop");
add= new Button("ADD");
            add(start);
add(stop);
add(add);
            start.addActionListener(this);
stop.addActionListener(this);
add.addActionListener(this);
            setBackground(Color.gray);

   }//end of init()

public void actionPerformed(ActionEvent ae)
{
Graphics g=getGraphics();
if(ae.getSource() == start)
{
t=new Thread(this);
flag=true;
t.start();

}
if(ae.getSource() == add)
{
i=2;
repaint();
t1=new Thread(this);
flag=true;
t1.start();
}

if(ae.getSource() == stop)
{
flag=false;
}
}//end of actionPerformed()



   public void run()
   {


  int width = getSize().width;
     int height = getSize().height;
     xbound=width-dia;
   ybound=height-dia;



while(flag)
{
  try
  {

              x1+=deltaX ;
 y1+=deltaY;

if(i==2)
{
x2+=deltaX1;
y2+=deltaY1;
}


  Thread.sleep(5);
  if(x1 > xbound || x1< 0)
deltaX = - deltaX;
  if(y1> ybound || y1 < 0)
     deltaY= -deltaY;

  if(x2 > xbound || x2< 0)
deltaX1 = - deltaX1;
if(y2> ybound || y2 < 0)
      deltaY1= -deltaY1;




}
    catch(InterruptedException ie)
      {
System.out.println("Error:"+ie);
  }

 repaint();
 if(i==2)
 {
  int x=(x2-x1)*(x2-x1);
  int y=(y2-y1)*(y2-y1);
  int d=dia*dia;
  if((x+y)<=d)
     setclr=true;
              }


}//end of while

    }//end of run()
     public void paint(Graphics g)
   {
if(i==1)
{
      g.setColor(Color.RED);
  g.fillOval(x1,y1,dia,dia);
}
 else
  {
  g.setColor(Color.RED);
  g.fillOval(x1,y1,dia,dia);
  g.setColor(Color.black);
  g.fillOval(x2,y2,dia,dia);

      }
      if(setclr)
      {

  flag=false;
  g.setColor(Color.gray);
  g.fillOval(x1,y1,dia,dia);
  g.fillOval(x2,y2,dia,dia);

}
}//end of paint()

}//End of class ballVanishimport java.io.*;

class bank
{
String name;
int accno;
String type;
int balance;

bank(int accno1,String name1,String type1)
{

accno = accno1;
name = name1;
type = type1;
}
void deposit(int accno1,int amt)
{
if(accno == accno1)
balance +=amt;
}
void withdraw(int accno1,int amt)
{
if(accno == accno1)
{
if(balance>=amt)
balance -=amt;
else
System.out.println("YOU CAN NOT WITH DRAW");
}
}
void display(int accno1)
{
if(accno == accno1)
System.out.println("Name  :"+name+"          balance       :"+balance) ;
}
}

class banka
{
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int accno1,i;
String name1,type1;
bank [] B = new bank [10];
for(i=0;i<3 i="" p="">{
 accno1 = Integer.parseInt(in.readLine());
 name1 = in.readLine();
 type1 = in.readLine();
B[i] = new bank (accno1,name1,type1);
}
System.out.println("enter the acc no");
int an1 = Integer.parseInt(in.readLine());
int y=1;
do{
System.out.println("1.deposit    2.with draw    3.balance");
 int cho = Integer.parseInt(in.readLine());
System.out.println("enter the amount");
int amt1 = Integer.parseInt(in.readLine());

for( i=0;i<3 i="" p="">{
if (cho == 1)
{

B[i].deposit(an1,amt1);
}
else if (cho == 2)
{
B[i].withdraw(an1,amt1);
}
else
{
B[i].display(an1);
}

}
System.out.println("transaction   1");
y = Integer.parseInt(in.readLine());

}while (y==1);
}
}import java.rmi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BankClient extends JFrame implements ActionListener,ItemListener
{
static MyRemote1  obj;
 JTextField t1,t2;
 JButton b1;
 JLabel l1,l2,l3;
 JPanel p1,p2,p3,mp;
 JComboBox cb;
 int bal=0,amt=0;
 public BankClient()
  {
 t1=new JTextField(20);
      t2=new JTextField(20);
      b1=new JButton("Do");
      b1.addActionListener(this);
      l1=new JLabel("Amount");
      l2=new JLabel("Mode");
      l3=new JLabel("Balance");
      cb=new JComboBox();
       cb.addItem("Deposit");
       cb.addItem("Withdraw");
       cb.addItemListener(this);
      p1=new JPanel();
      p1.add(l1);
      p1.add(t1);
      p2=new JPanel();
      p2.add(l2);
      p2.add(cb);
      p2.add(b1);
      p3=new JPanel();
      p3.add(l3);
      p3.add(t2);
      mp=new JPanel(new GridLayout(3,1));
     mp.add(p1);
     mp.add(p2);
     mp.add(p3);
     Container ct=getContentPane();
     ct.setLayout(new FlowLayout());
     ct.add(mp);
     setTitle("Demo");
     setSize(400,400);
      setVisible(true);
    }
    int l;
        public void itemStateChanged(ItemEvent ie)
    {
l=cb.getSelectedIndex();
}
  public void actionPerformed(ActionEvent ae)
  {
    if(l==0)
      {
  try
  {
   amt=Integer.parseInt(t1.getText());
   obj.deposit(amt);
bal=obj.getbalance();
t2.setText(""+bal);
}
catch(Exception e)
{
}
}
if(l==1)
      {
  try
  {
   amt=Integer.parseInt(t1.getText());
   obj.withdraw(amt);
bal=obj.getbalance();
t2.setText(""+bal);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,"Balance is not enough.");
}

}
}
 public static void main(String args[])
 {
   try
   {
   obj=(MyRemote1)Naming.lookup("rmi://localhost:1099/OBJ2");
   System.out.println("Calling remote methods");
    new BankClient();
   }catch(Exception e)
     {
       System.out.println("Error in lookup"+e);
       }
       }
}import java.io.*;
class Bank1Exception extends Exception
{
   int num=0;
     Bank1Exception()
      {
       System.out.println("Default of myexception"+num);
      }
      Bank1Exception(int n)
      {
        num=n;
        System.out.println("Entered amount is="+num);
       }
      public String toString()
      {
       return"Balance is not Enough"+num;
      }
 }
     class BankException
      {
 int bal=1000;
       void wid(int num)throws Bank1Exception
        {

            if(bal-num<500 p="">            {
              throw new Bank1Exception(num);
            }
            else
            {
             bal=bal-num;
             System.out.println("Balance  is "+bal);
            }
    }
        void dep(int num)
         {
 bal=bal+num;
  System.out.println("Balance  is "+bal);
        }
       int getbal()
        {
return(bal);
}
      public static void main(String arg[])
       {
        BankException ce=new BankException();
         try{
char aa='y';
 while(aa=='y' || aa=='Y')
{

InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
System.out.println(" Enter 1 for Deposit\n Enter 2 for Witdraw \n Enter 3 for Balance Enqu ");
String str1=br.readLine();
int ch=Integer.parseInt(str1);
System.out.println("Enter Amount ");
String str2=br.readLine();
int num=Integer.parseInt(str2);
switch(ch)
 {
  case 1:
     ce.dep(num);
     break;
  case 2:
     ce.wid(num);
     break;
  case 3:
     int x=ce.getbal();
      System.out.println(" Amount is "+x);
      break;
  default:System.out.println("Enter  correct Choice ");
   }
   System.out.println("Want to Cont. enter y");
   aa=(char)br.read();

   }
           }catch(Bank1Exception me)
            {
             System.out.println("Caught inside main"+me);
             me.printStackTrace();
            }
           catch(Exception e)
            {
System.out.println("Error is "+e);
  }
           }

  }
import java.io.*;
class BankingDemo
{
int total_amount=500;
void deposit(int amount)
{
total_amount=total_amount+amount;
System.out.println("Total_amount is "+total_amount);
}
void withdrawn(int amount) throws BankingException
{
int am=total_amount-amount;
if(am<500 p=""> {
throw new BankingException(amount);
}
else
{
System.out.println(amount+" is withdrawn from "+total_amount);
total_amount=total_amount-amount;
}
}
int getbalance()
{
return total_amount;
}
public static void main(String s[]) throws BankingException
{
BankingDemo obj=new BankingDemo();
char c;
try
{
do
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("1. For Deposit\n2.For WithDrawn \n3. For Balance");
System.out.println("Enter Your Choice");
int ch=Integer.parseInt(br.readLine());
switch(ch)
{
case 1:
System.out.println("Enter the amount");
int amt=Integer.parseInt(br.readLine());
obj.deposit(amt);
break;
case 2:
System.out.println("Enter the to be WithDrawn");
int wh=Integer.parseInt(br.readLine());
obj.withdrawn(wh);
break;
case 3:
int balance=obj.getbalance();
System.out.println("Total amount balance is "+balance);
break;
default :
System.out.println("Your choice is wrong");
}
System.out.println("Do u want to continue(y/n)");
c=(char)br.read();
}while(c=='y' || c=='Y');
}catch(Exception e)
{
System.out.println("Invalid exception"+e);
}
}
}
class BankingException extends Exception
{
int n;
BankingException()
{
n=0;
System.out.println("Default constructor");
}
BankingException(int n)
{
this.n=n;
//System.out.println("Parametarize constructor");
}
public String toString()
{
return "U can't withdrawn"+n;
}
}import java.rmi.*;
import java.rmi.server.*;
public class BankServer extends UnicastRemoteObject implements MyRemote1
{
public BankServer(String nm)throws RemoteException
{
 try
 {
    Naming.bind(nm,this);
   System.out.println("Object binded here.......");
   }catch(Exception e)
     {
      System.out.println("Error in binding"+e);
      }
  }
      int bal=0;
      public void deposit(int amt) throws RemoteException
      {
      bal=bal+amt;
       }
      public void withdraw(int amt) throws RemoteException
            {
if(bal-amt<500 p=""> {
throw new RemoteException();
   }else
   {
bal=bal-amt;
     }
  }
      public int getbalance() throws RemoteException
            {
            return (bal);
      }

      public static void main(String arg[])throws RemoteException
      {
       new BankServer("OBJ2");
       System.out.println("Server started here");
       }
       }class Bitwise{
    public static void main(String[] args) {
    int x,y;
         
    x = ~100;
    System.out.println("Nilai negasi x : "+x);

    x = 17 & 30;
    System.out.println("Nilai and : "+x);

    x = 17 | 30;
    System.out.println("Nilai or : "+x);

    x = 17 ^ 30;
    System.out.println("Nilai xor : "+x);

    x = 111;
    y = x >> 1;
    System.out.println("Nilai geser kanan : "+x);

    x = -111;
    y = x >> 1;
    System.out.println("Nilai geser kanan neg : "+x);

    x = 111;
    y = x >>> 1;
    System.out.println("Nilai geser kanan 1 bit 0 : "+x);

    x = -111;
    y = x >>> 1;
    System.out.println("Nilai geser kanan 1 bit 0 neg : "+x);

    x = 111;
    y = x << 1;
    System.out.println("Nilai geser kiri : "+x);

    x = 1000;
    y =  x << 1;
    System.out.println("Nilai geser kiri : "+x);
    }
}/*
    public java.awt.BorderLayout();
    public java.awt.BorderLayout(int,int);
*/    

import java.applet.* ;
import java.awt.*;
//

 public class  border extends Applet
   {

     public void init()
     {
       Button north,south,east,west,center;

       setLayout(new BorderLayout());
       north=new Button("NORTH");
       south=new Button("SOUTH");
       east=new Button("EAST");
       west=new Button("WEST");
       center=new Button("CENTER");

       add(north,BorderLayout.NORTH);
       add(south,BorderLayout.SOUTH);
       add(east,BorderLayout.EAST);
       add(west,BorderLayout.WEST);
       add(center,BorderLayout.CENTER);
      }                                
 }      
           
   

import java.awt.*;
import java.awt.event.*;
public class Bound extends Frame implements ActionListener,WindowListener
{
Label l1,l2,l3;
    TextField t1,t2,t3;              // declaration
    Button b1,b2,b3,b4;
    Panel p1,p2,p3,p4,mainpanel;
  public Bound()
  {
         l1=new Label("Num1");
         l2=new Label("Num2");           // construction
         l3=new Label("Result");
         t1=new TextField(20);
         t2=new TextField(20);
         t3=new TextField(20);
         b1=new Button("     +     ");
         b1.addActionListener(this);
         b2=new Button("     -     ");
         b2.addActionListener(this);
         b3=new Button("     *     ");
         b3.addActionListener(this);
         b4=new Button("     /     ");
         b4.addActionListener(this);
          p1=new Panel();
         p2=new Panel();
         p3=new Panel();
         p4=new Panel();
         mainpanel=new Panel(new GridLayout(8,1));
         //l1.setBounds(20,30,60,20);
         //l2.setBounds(20,70,60,20);
         //t1.setBounds(100,30,60,20);
         //t2.setBounds(100,70,60,20);

         p1.add(l1);
         p1.add(t1);                      // adding component
         p2.add(l2);
         p2.add(t2);
         p3.add(l3);
         p3.add(t3);
         p4.add(b1);
         p4.add(b2);
         p4.add(b3);
         p4.add(b4);
         mainpanel.add(p1);
         mainpanel.add(p2);
         mainpanel.add(p3);
         mainpanel.add(p4);
         add(mainpanel);
         setTitle("Text Label demo");
         addWindowListener(this);
    setSize(600,600);
    setVisible(true);
    setResizable(false);
  }

      public void windowActivated(WindowEvent e)
      {
 }
      public void windowClosed(WindowEvent e)
      {
 }
 public void windowClosing(WindowEvent e)
 {
 System.exit(0);
 }
 public void windowDeactivated(WindowEvent e)
      {
 }
 public void windowDeiconified(WindowEvent e)
 {
 }
 public void windowIconified(WindowEvent e)
 {
 }
 public void windowOpened(WindowEvent e)
      {
 }
      /*public void keyPressed(KeyEvent ke)
      {
}
public void keyTyped(KeyEvent ke)
      {
}
public void keyReleased(KeyEvent ke)*/
public void actionPerformed(ActionEvent ae)
      {
  try
  {
  if(ae.getSource()==b1)
  {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
  int z=x+y;
  t3.setText(""+z);
  }


  if(ae.getSource()==b2)
   {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
      int z=x-y;
  t3.setText(""+z);
  }
if(ae.getSource()==b3)
  {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
  int z=x*y;
  t3.setText(""+z);
  }
              if(ae.getSource()==b4)
  {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
  int z=x/y;
  t3.setText(""+z);
  }
  }

  catch(Exception e)
  {
}
}

  public static void main(String args[])
  {
   new Bound();
  }
}import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* */
public class Boundapp extends Applet
{
Label l1,l2;
    TextField t1,t2;              // declaration
  public  void init()
  {
         l1=new Label("Num");
         l2=new Label("Square");           // construction
         t1=new TextField(20);
         t2=new TextField(20);
         setLayout(null);
         l1.setBounds(20,30,60,20);
         l2.setBounds(20,70,60,20);
         t1.setBounds(100,30,60,20);
         t2.setBounds(100,70,60,20);
         add(l1);
         add(t1);                      // adding component
         add(l2);
         add(t2);
      }

}// To create a button //
/*  public java.awt.Button();
    public java.awt.Button(java.lang.String);
  */
import java.applet.Applet;
import java.awt.*;
//

public class butt extends Applet {
   public void init() {
     Button b1,b2;
     b1=new Button("Welcome");
     add(b1);
     b2=new Button();
     add(b2);
    }
  }


/**
  This is a simple calculator program can any one take and use.

  */
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.*;
import java.awt.event.*;
//
public class Calculator extends JApplet {
   public void init() {
      CalculatorPanel calc=new CalculatorPanel();
      getContentPane().add(calc);
      }
   }

   class CalculatorPanel extends JPanel implements ActionListener {
      JButton
n1,n2,n3,n4,n5,n6,n7,n8,n9,n0,plus,minus,mul,div,dot,equal;
      static JTextField result=new JTextField("0",45);
      static String lastCommand=null;
      JOptionPane p=new JOptionPane();
      double preRes=0,secVal=0,res;

      private static void assign(String no)
        {
         if((result.getText()).equals("0"))
            result.setText(no);
          else if(lastCommand=="=")
           {
            result.setText(no);
            lastCommand=null;
           }
          else
            result.setText(result.getText()+no);
         }

      public CalculatorPanel() {
         setLayout(new BorderLayout());
         result.setEditable(false);
         result.setSize(300,200);
         add(result,BorderLayout.NORTH);
         JPanel panel=new JPanel();
         panel.setLayout(new GridLayout(4,4));

         n7=new JButton("7");
         panel.add(n7);
         n7.addActionListener(this);
         n8=new JButton("8");
         panel.add(n8);
         n8.addActionListener(this);
         n9=new JButton("9");
         panel.add(n9);
         n9.addActionListener(this);
         div=new JButton("/");
         panel.add(div);
         div.addActionListener(this);

         n4=new JButton("4");
         panel.add(n4);
         n4.addActionListener(this);
         n5=new JButton("5");
         panel.add(n5);
         n5.addActionListener(this);
         n6=new JButton("6");
         panel.add(n6);
         n6.addActionListener(this);
         mul=new JButton("*");
         panel.add(mul);
         mul.addActionListener(this);

         n1=new JButton("1");
         panel.add(n1);
         n1.addActionListener(this);
         n2=new JButton("2");
         panel.add(n2);
         n2.addActionListener(this);
         n3=new JButton("3");
         panel.add(n3);
         n3.addActionListener(this);
         minus=new JButton("-");
         panel.add(minus);
         minus.addActionListener(this);

         dot=new JButton(".");
         panel.add(dot);
         dot.addActionListener(this);
         n0=new JButton("0");
         panel.add(n0);
         n0.addActionListener(this);
         equal=new JButton("=");
         panel.add(equal);
         equal.addActionListener(this);
         plus=new JButton("+");
         panel.add(plus);
         plus.addActionListener(this);
         add(panel,BorderLayout.CENTER);
      }
      public void actionPerformed(ActionEvent ae)
         {
      if(ae.getSource()==n1) assign("1");
      else if(ae.getSource()==n2) assign("2");
      else if(ae.getSource()==n3) assign("3");
      else if(ae.getSource()==n4) assign("4");
      else if(ae.getSource()==n5) assign("5");
      else if(ae.getSource()==n6) assign("6");
      else if(ae.getSource()==n7) assign("7");
      else if(ae.getSource()==n8) assign("8");
      else if(ae.getSource()==n9) assign("9");
      else if(ae.getSource()==n0) assign("0");
      else if(ae.getSource()==dot)
            {
             if(((result.getText()).indexOf("."))==-1)
                result.setText(result.getText()+".");
           }
      else if(ae.getSource()==minus)
             {
             preRes=Double.parseDouble(result.getText());
             lastCommand="-";
             result.setText("0");
             }
      else if(ae.getSource()==div)
             {
             preRes=Double.parseDouble(result.getText());
             lastCommand="/";
             result.setText("0");
             }
      else if(ae.getSource()==equal)
             {
             secVal=Double.parseDouble(result.getText());
             if(lastCommand.equals("/"))
                  res=preRes/secVal;
             else if(lastCommand.equals("*"))
                  res=preRes*secVal;
             else if(lastCommand.equals("-"))
                  res=preRes-secVal;
             else if(lastCommand.equals("+"))
                  res=preRes+secVal;
             result.setText(" "+res);
             lastCommand="=";
             }
      else if(ae.getSource()==mul)
             {
              preRes=Double.parseDouble(result.getText());
              lastCommand="*";
              result.setText("0");
              }
      else if(ae.getSource()==plus)
              {
              preRes=Double.parseDouble(result.getText());
              lastCommand="+";
              result.setText("0");
              }

       }
 }import java.awt.*;
import java.awt.event.*;
public class Calc extends Frame implements ActionListener,WindowListener
{
Label l1,l2,l3;
    TextField t1,t2,t3;              // declaration
    Button b1,b2,b3,b4;
    public Calc()
  {
         l1=new Label("Num1");
         l2=new Label("Num2");           // construction
         l3=new Label("Result");
         t1=new TextField(20);
         t2=new TextField(20);
         t3=new TextField(20);
         b1=new Button("     +     ");
         b1.addActionListener(this);
         b2=new Button("     -     ");
         b2.addActionListener(this);
         b3=new Button("     *     ");
         b3.addActionListener(this);
         b4=new Button("     /     ");
         b4.addActionListener(this);

         add(b1);
         setTitle("Text Label demo");
         addWindowListener(this);
    setSize(600,600);
    setVisible(true);
    setResizable(false);
  }

      public void windowActivated(WindowEvent e)
      {
 }
      public void windowClosed(WindowEvent e)
      {
 }
 public void windowClosing(WindowEvent e)
 {
 System.exit(0);
 }
 public void windowDeactivated(WindowEvent e)
      {
 }
 public void windowDeiconified(WindowEvent e)
 {
 }
 public void windowIconified(WindowEvent e)
 {
 }
 public void windowOpened(WindowEvent e)
      {
 }
      /*public void keyPressed(KeyEvent ke)
      {
}
public void keyTyped(KeyEvent ke)
      {
}
public void keyReleased(KeyEvent ke)*/
public void actionPerformed(ActionEvent ae)
      {
  try
  {
  if(ae.getSource()==b1)
  {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
  int z=x+y;
  t3.setText(""+z);
  }


  if(ae.getSource()==b2)
   {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
      int z=x-y;
  t3.setText(""+z);
  }
if(ae.getSource()==b3)
  {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
  int z=x*y;
  t3.setText(""+z);
  }
              if(ae.getSource()==b4)
  {
  int x=Integer.parseInt(t1.getText());
  int y=Integer.parseInt(t2.getText());
  int z=x/y;
  t3.setText(""+z);
  }
  }

  catch(Exception e)
  {
}
}

  public static void main(String args[])
  {
   new Bound();
  }
}import java.awt.*;
import java.awt.event.*;
public class Calculator extends Frame implements WindowListener
{

    TextField t1;              // declaration
    Panel p1,p2,npanel,spanel,epanel,wpanel,cenpanel,mainp;
    Button numbut[]=new Button[12];
    Button membut[]=new Button[4];
    Button oprbut[]=new Button[8];

    String numLabel[]={"1","2","3","4","5","6","7","8","9","0"};
    String memLabel[]={"MC","MR","MS","M+"};
    String oprLabel[]={"/","sqrt","*","%","-","1/x","+","="};

    public Calculator()
  {
          t1=new TextField(20);
          npanel=new Panel();
          spanel=new Panel();
          epanel=new Panel();
          wpanel=new Panel();
          cenpanel=new Panel();
          p1= new Panel();
          p2= new Panel();
          mainp=new Panel(new BorderLayout());
          for(int i=0;i          {
 numbut[i]=new Button(numLabel[i]);
 cenpanel.add(numbut[i]);
 //numbut[i].addActionListener(this);
 }
 for(int i=0;i  {
 membut[i]=new Button(memLabel[i]);
 wpanel.add(membut[i]);
//  membut[i].addActionListener(this);
 }
 for(int i=0;i  {
 oprbut[i]=new Button(oprLabel[i]);
 epanel.add(oprbut[i]);
//  oprbut[i].addActionListener(this);
     }
     p1.add(t1);
     npanel.add(p1);
          mainp.add(npanel,BorderLayout.NORTH);
          mainp.add(spanel,BorderLayout.SOUTH);
          mainp.add(epanel,BorderLayout.EAST);
          mainp.add(wpanel,BorderLayout.WEST);
          mainp.add(cenpanel);
          add(mainp);
         setTitle("Text Label demo");
         addWindowListener(this);
    setSize(600,600);
    setVisible(true);
    setResizable(false);
  }

      public void windowActivated(WindowEvent e)
      {
 }
      public void windowClosed(WindowEvent e)
      {
 }
 public void windowClosing(WindowEvent e)
 {
 System.exit(0);
 }
 public void windowDeactivated(WindowEvent e)
      {
 }
 public void windowDeiconified(WindowEvent e)
 {
 }
 public void windowIconified(WindowEvent e)
 {
 }
 public void windowOpened(WindowEvent e)
      {
 }


  public static void main(String args[])
  {
   new Calculator();
  }
}import java.awt.*;
import java.awt.event.*;
public class Calculator1 extends Frame
{
TextField t1,t2;
Panel p,p1,p2,cpanel,wpanel,epanel,mainp;
Button numbut[]=new Button[12];
Button membut[]=new Button[4];
Button oprbut[]=new Button[8];
Button b,ce,c;
String numLabel[]={"7","8","9","4","5","6","1","2","3","0","+/-","."};
String memLabel[]={"MC","MR","MS","M+"};
String oprLabel[]={"/","sqrt","*","%","-","1/x","+","="};
public Calculator1()
{
p1=new Panel();
p2=new Panel();
p=new Panel(new GridLayout(2,1));
cpanel=new Panel(new GridLayout(4,3));
wpanel=new Panel(new GridLayout(4,1));
epanel=new Panel(new GridLayout(4,2));
for(int i=0;i  {
 numbut[i]=new Button(numLabel[i]);
 cpanel.add(numbut[i]);
//  numbut[i].addActionListener(this);
     }
            for(int i=0;i  {
 membut[i]=new Button(memLabel[i]);
 wpanel.add(membut[i]);
//  membut[i].addActionListener(this);
     }
for(int i=0;i  {
 oprbut[i]=new Button(oprLabel[i]);
 epanel.add(oprbut[i]);
   //  membut[i].addActionListener(this);
 }
   t1=new TextField(20);

   t2=new TextField(2);
           t2.setEditable(false);
   b=new Button("Backspace");
   ce=new Button("CE");
   c=new Button("C");
   p1.add(t1);
            p2.add(t2);
            p2.add(b);
            p2.add(ce);
            p2.add(c);
    p.add(p1);
    p.add(p2);
    mainp=new Panel(new BorderLayout());
    add(p,BorderLayout.NORTH);
    add(cpanel,BorderLayout.CENTER);
    add(wpanel,BorderLayout.WEST);
    add(epanel,BorderLayout.EAST);
  setTitle("Demo Page");
  setSize(200,250);
  setVisible(true);
  setResizable(false);


  }
  public static void main(String arg[])
   {
   new Calculator1();
    }
}









/*

- Displays Time and Date and other related things.

*/

import java.io.*;

class calendar
{
public static void main(String[] args)
{
Date d = new Date();
d.
}
}// To create a checkbox //

/*
    public java.awt.Checkbox();
    public java.awt.Checkbox(java.lang.String);
    public java.awt.Checkbox(java.lang.String,java.awt.CheckboxGroup,boolean);
    public java.awt.Checkbox(java.lang.String,boolean);
    public java.awt.Checkbox(java.lang.String,boolean,java.awt.CheckboxGroup);
*/
import java.applet.Applet;
import java.awt.*;
//

public class check extends Applet
 {
  public void init()
   {
   
       Checkbox c1=new Checkbox();
       Checkbox c2=new Checkbox("java");
       Checkbox c3=new Checkbox("cobol",null,true);
       Checkbox c4=new Checkbox("ALGO",false);
       Checkbox c5=new Checkbox("CA",false,null);

   
      add(c1);
      add(c2);
      add(c3);
      add(c4);
      add(c5);
    }
  }
import java.awt.*;
import java.applet.*;
public class circle extends Applet
{
 public void paint(Graphics g)
  {
   g.drawOval(10,10,220,140);
   g.setColor(Color.blue);
   g.fillOval(60,20,110,110);
   }
   }
  /*
 

  */
class Buku {
    String pengarang;
    String judul;

    void Isi(String isi1,String isi2) {
        judul     = isi1;
        pengarang = isi2;
    }

    void CetakKeLayar() {
if(judul==null && pengarang==null) return;      

System.out.println("Judul : " + judul +
                            ", pengarang : " + pengarang);
    }
}

class Karangan {

    public static void main(String[] args) {
       Buku a,b,c,d;
       a = b = c = d = new Buku();
     
       a.Isi("Pemrograman Java","Asep Herman Suyanto");
       a.CetakKeLayar();
       b.Isi(null,null);
       b.CetakKeLayar();
       c.Isi(null,"Johan Prasetyo Hendriyanto");
       c.CetakKeLayar();
       d.Isi("Pemrograman Web",null);
       d.CetakKeLayar();
    }
}import java.net.*;
import java.io.*;
class client
{
public static DatagramSocket ds;
public static byte buffer[]=new byte[1024];
public static void Myclient() throws Exception
{
while(true)
{
DatagramPacket p=new DatagramPacket(buffer,buffer.length);
ds.receive(p);
System.out.println(new String(p.getData(),0,p.getLength()));
}
}
public static void main(String args[])throws Exception
{
System.out.println("client for quit process ctrl-c");
ds=new DatagramSocket(777);
Myclient();
}
}import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class ClientSocketGUI extends Frame implements ActionListener
{
Label l1,l2;
TextField t1;
Button b1;
TextArea ta;
Socket s;
DataInputStream remote;
PrintStream ps;
public ClientSocketGUI()
{
l1=new Label("Enter message");
l2=new Label("Message received");
t1=new TextField(50);
ta=new TextArea();
b1=new Button("Send");
b1.addActionListener(this);

Panel p1=new Panel();
p1.add(l1);
p1.add(t1);
p1.add(b1);
Panel p2=new Panel();
p2.add(l2);
p2.add(ta);
Panel mainPanel=new Panel();
mainPanel.add(p1);
mainPanel.add(p2);
add(mainPanel);

setTitle("Client");
setSize(600,400);
setVisible(true);
try
{
s=new Socket("localhost",2000);
remote=new DataInputStream(s.getInputStream());
ps=new PrintStream(s.getOutputStream());
}catch(Exception e)
  {
  System.out.println("Error in Client side in connection"+e);
  }
}
public void actionPerformed(ActionEvent ae)
{
try{

String remotedata=remote.readLine();
ta.append(remotedata+"\n");
String localdata=t1.getText();
ps.println(localdata);
            }catch(Exception e)
{
System.out.println("Error in client side"+e);
}
}
public static void main(String arg[])
{
new ClientSocketGUI();
 }
 }
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class ClientSocketGUI2 extends Frame implements ActionListener,Runnable
{
Label l1,l2;
TextField t1;
Button b1;
TextArea ta;
Socket s;
DataInputStream remote;
PrintStream ps;
Thread th;
public ClientSocketGUI2()
{
l1=new Label("Enter message");
l2=new Label("Message received");
t1=new TextField(50);
ta=new TextArea();
b1=new Button("Send");
b1.addActionListener(this);

Panel p1=new Panel();
p1.add(l1);
p1.add(t1);
p1.add(b1);
Panel p2=new Panel();
p2.add(l2);
p2.add(ta);
Panel mainPanel=new Panel();
mainPanel.add(p1);
mainPanel.add(p2);
add(mainPanel);

setTitle("Client");
setSize(600,400);
setVisible(true);
try
{
s=new Socket("LocalHost",2000);
remote=new DataInputStream(s.getInputStream());
ps=new PrintStream(s.getOutputStream());
th=new Thread(this);
th.start();
}catch(Exception e)
  {
  System.out.println("Error in Client side in connection"+e);
  }
}
public void run()
{
try{
while(true)
{
String remotedata=remote.readLine();
ta.append(remotedata+"\n");
}
}catch(Exception e)
  {
  System.out.println("Error in Client side in connection"+e);
  }
}
public void actionPerformed(ActionEvent ae)
{
try{

String localdata=t1.getText();
ps.println(localdata);
            }catch(Exception e)
{
System.out.println("Error in client side"+e);
}
}
public static void main(String arg[])
{
new ClientSocketGUI2();
 }
 }

// Program for slink Clustering

import java.util.*;
import java.io.*;

public class clink {
  private File namefile = null;
  private File datafile = null;
  private int k=-1;
  private ArrayList clusterlist = new ArrayList(); // to store the clusters. Each cluster is a list of IDs of the tuples
  private ArrayList attrlist = new ArrayList(); // to store the attributes
  private ArrayList valuelist = new ArrayList(); // to store all the tuples (cases). Each tuple is a list of attrvalues.
  private ArrayList origvalues=new ArrayList();

  public clink() {
  }

public static void main(String[] args)throws Exception {
    try {
      // load the file specified by filename.
      System.out.print("Enter the input file name: ");
      BufferedReader lineReader = new BufferedReader(new InputStreamReader(
          System.in));
      String fileitemname = lineReader.readLine();
      clink sl = new clink();
      if (sl.loadFiles(fileitemname) == false) {
        return;
      }

      // handle the inputted 'K'.
      while (true) {
        System.out.print("Input 'K' (int): ");
        try {
          int k = Integer.parseInt(lineReader.readLine());
sl.setK(k);
         break;
        }
        catch (NumberFormatException ee) {
          System.out.println("Format error! Please input an integer!!!");
        }
      }

      // handle the method of choosing seeds.
 
      sl.clustering();
      String outputFilename = "";
     do {
        System.out.print("Please specify the output filename: ");
        outputFilename = lineReader.readLine();
      }
      while (!sl.output(outputFilename));

    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  //To check filename and load data from file

  public boolean loadFiles(String fileitemname) {
    // validate if the files exist.
    this.namefile = new File("./" + fileitemname + ".names");
    if (!this.namefile.exists()) {
      System.out.println("The file .names doesn't exist!");
      return false;
    }
    this.datafile = new File("./" + fileitemname + ".data");
    if (!this.datafile.exists()) {
      System.out.println("The file .data doesn't exist!");
      return false;
    }

    this.loadName();
    this.loadData();
    return true;
  }

 // Load attr from the '.names' file.
 
 
protected boolean loadName() {
    try {
      BufferedReader reader = new BufferedReader(new FileReader(this.namefile));
      String line = "";
      int ind = 0;
      while ( (line = reader.readLine()) != null) {
        ind = line.indexOf('|');
        if (ind >= 0) {
          line = line.trim().substring(0, ind).trim();
        }
        if (line.equals("")) {
          continue;
        }

        ind = line.indexOf(':');

        if (ind >= 0) {
          // read attribute names into the "attrlist".
          String name = line.substring(0, ind);
          this.attrlist.add(name);
        }
      } // while readLine()

      return true;

    }
    catch (IOException ex) {
      System.out.println("File I/O error. Please verify the .names file");
      return false;
    }
  }

    // Load data from the '.data' file.
 
  protected void loadData() {
    try {
      BufferedReader reader = new BufferedReader(new FileReader(this.datafile));
      String line = "";
      int ind = 0;
      while ( (line = reader.readLine()) != null) {
        // remove the annotation
       // ind = line.indexOf('|');
       // if (ind >= 0) {
         // line = line.trim().substring(0, ind).trim();
       // }
        if (line.equals("")) {
          continue;
        }

        ArrayList tuple = new ArrayList();
        ind = line.indexOf(',');
        while (ind > 0) {
          String attrvalue = line.substring(0, ind);
          tuple.add(new Double(attrvalue));

          line = line.substring(ind + 1).trim();
         
          ind = line.indexOf(',');
        } // while
this.valuelist.add(tuple);
        this.origvalues.add(tuple);

      } // while readLine()
    }
    catch (Exception ex) {
      System.out.println("File I/O error. Please verify the .data file");
      }
  }

No comments:

Post a Comment

உப்பு மாங்காய்

சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...