06:36

Image change with enter postion no

Posted by Mitesh Patel |

 import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;

public class mitesh extends Applet implements ActionListener
{



//  image viewer

    Image mycard;
    Button myButton=new Button("Show Pictures 1,2,3,4,5,6 or 7");
    TextField myTextField=new TextField("1");
    static int choice=0;

    Button b;
    Button c;
    public void init()
    {

       b = new Button("thankyou");
    add(b);
   b.addActionListener(this);

   c = new Button("presented by");
    add(c);
   c.addActionListener(this);

  // image source code
        add(myButton);
        add(myTextField);
        myButton.addActionListener(this);
    }
    public void actionPerformed(ActionEvent event)
    {
          
             if (event.getActionCommand()== "thankyou")
        {
            JOptionPane.showMessageDialog(null, "Thank you for supporting");

        }
        if (event.getActionCommand()== "presented by")
        {
            JOptionPane.showMessageDialog(null, " Justfreeknowledge By Mitesh Patel ");

        }


            // image viewer source code
            String temp;
        Object source=event.getSource();
        if(source.equals(myButton))
        {
          temp=myTextField.getText().trim(); //trim off spaces in textfield
          choice=Integer.parseInt(temp);
          repaint();
          System.out.println(choice);

        }
    }
    public void paint(Graphics g)
    {
            resize(640,640);
      
            System.out.println(choice);
            if(choice ==1)
            {
              mycard=getImage(getCodeBase(), "1.jpg");
              g.drawImage(mycard, 250,100, this);
            }
            if(choice ==2)
            {
              mycard=getImage(getCodeBase(), "2.jpg");
              g.drawImage(mycard, 200,100, this);
            }
            if(choice ==3)
            {
              mycard=getImage(getCodeBase(), "3.jpg");
              g.drawImage(mycard, 200,100, this);
            }
            if(choice ==4)
            {
              mycard=getImage(getCodeBase(), "4.jpg");
              g.drawImage(mycard, 200,100, this);
            }
            if(choice ==5)
            {
              mycard=getImage(getCodeBase(), "5.jpg");
              g.drawImage(mycard, 200,100, this);
            }
            if(choice ==6)
            {
              mycard=getImage(getCodeBase(), "6.jpg");
              g.drawImage(mycard, 200,100, this);
            }
            if(choice ==7)
            {
              mycard=getImage(getCodeBase(), "7.jpg");
              g.drawImage(mycard, 200,100, this);
            }
    }
}





06:25

Shape and With color

Posted by Mitesh Patel |

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

public class  ShapColor extends Applet{
  int x=300,y=100,r=50;

  public void paint(Graphics g){
  g.setColor(Color.red);  //Drawing line color is red
  g.drawLine(3,300,200,10);
  g.setColor(Color.magenta); 
  g.drawString("Line",100,100);

  g.drawOval(x-r,y-r,100,100);
  g.setColor(Color.yellow);  //Fill the yellow color in circle
  g.fillOval( x-r,y-r, 100, 100 );
  g.setColor(Color.magenta);
  g.drawString("Circle",275,100);
 
  g.drawRect(400,50,200,100);
  g.setColor(Color.yellow);  //Fill the yellow color in rectangel
  g.fillRect( 400, 50, 200, 100 );
  g.setColor(Color.magenta);
  g.drawString("Rectangel",450,100);
  }
}

22:42

Private Method

Posted by Mitesh Patel |

/*
in order to call private method of class outside of that class
 *
 * you must have to declare one public method in that class
 * and from that public method we can call private method of class
 *
 * in short
 * class's public method can access class's private method
 */

class MyClass1 {

    private void show() {
        System.out.println("This is private function can not called outside of class");

    }

    public void call() {
      show();
    }
}

class PrivateExample {

    public static void main(String args[]) {

        MyClass1 c = new MyClass1();
        c.call();

    }
}

22:41

Interface

Posted by Mitesh Patel |


interface MyFace {

    void show();

    void sum(int x, int y);

    void print();
}

interface MyFace2
{
    void parth();
}

class FirstClass implements MyFace,MyFace2 {

    public void sum(int x, int y) {
    }

    public void print() {
    }

    void mitesh() {
    }

    public void show() {
    }

    public void parth() {
       
    }
}

class InterfaceExample {

    public static void main(String args[]) {
    }
}

22:40

Fibonacci

Posted by Mitesh Patel |


class FiboExample {

    public static void main(String args[]) {

        int first = 0 , second = 1 ,third;
        int i;
        for(i=1;i<=15;i++)
        {
            System.out.println(" " + second);
            third = first + second;
            first = second;
            second = third;
        }

    }
}

22:40

Add Array

Posted by Mitesh Patel |


import java.util.Scanner;

class AddArray {

    public static void main(String args[]) {

        int row, col;
        int a[][] = new int[3][3];
        int b[][] = new int[3][3];
        System.out.println("Enter Array A");
        //scan data for a
        for (row = 0; row < 3; row++) {
            for (col = 0; col < 3; col++) {
                a[row][col] = new Scanner(System.in).nextInt();
            }
        }
        System.out.println("Enter Array B");

        //scan data for b
        for (row = 0; row < 3; row++) {
            for (col = 0; col < 3; col++) {
                b[row][col] = new Scanner(System.in).nextInt();
            }
        }

        System.out.println("View Array A");

        for (row = 0; row < 3; row++) {
            for (col = 0; col < 3; col++) {
                System.out.print(a[row][col] + "\t");
            }
            System.out.println("");


        }
        System.out.println("View Array B");

        for (row = 0; row < 3; row++) {
            for (col = 0; col < 3; col++) {
                System.out.print(b[row][col] + "\t");
            }
            System.out.println("");


        }

        System.out.println("Sum");

        for (row = 0; row < 3; row++) {
            for (col = 0; col < 3; col++) {
                System.out.print(a[row][col] + b[row][col] + "\t");
            }
            System.out.println("");


        }

    }
}

22:39

Abstract class

Posted by Mitesh Patel |

/*
abstract class
 */

abstract class Vahicle {

    void number_of_tyres() {
    }
}

//child class
class car extends Vahicle {

    void number_of_tyres() {

        System.out.println("Tyres = 4");

    }
}

class Truck extends Vahicle {

    void number_of_tyres() {
        System.out.println("Tyres = 8");
    }
}

class scooter extends Vahicle {

    void number_of_tyres() {
        System.out.println("Tyres = 2");
    }
}

class AbstractClass {

    public static void main(String args[]) {

        Vahicle a = new scooter();
        a.number_of_tyres();

        a = new Truck();
        a.number_of_tyres();

    }
}

22:38

Prime Number

Posted by Mitesh Patel |


class PrimeNumberExample {

    void prime(int num) {

        int i;
        int flag = 0;

        for (i = 2; i < num; i++) {
            if (num % i == 0) {
                flag = 1; //flag= 1 not prime
            }
        }


        if (flag == 0) {
            System.out.println("prime = " + num);

        }
    }

    public static void main(String args[]) {

        int i;
        PrimeNumberExample x = new PrimeNumberExample();
        for (i = 1; i <= 100; i++) {
            x.prime(i);
        }

    }
}

22:37

Double Array

Posted by Mitesh Patel |


import java.util.Scanner;

class TwoDArray {

    public static void main(String args[]) {

        int Row, Col;

        int a[][] = new int[3][3];

        for (Row = 0; Row < 3; Row++) {
            for (Col = 0; Col < 3; Col++) {

                a[Row][Col] = new Scanner(System.in).nextInt();

            }
        }



        //print data

        for (Row = 0; Row < 3; Row++) {
            for (Col = 0; Col < 3; Col++) {

                System.out.print("\t" + a[Col][Row]);

            }
            System.out.print("\n");
        }


    }
}

22:36

Palindrome

Posted by Mitesh Patel |


class Palindrome {

    public static void main(String args[]) {

        int i;
        Palindrome x = new Palindrome();
        for (i = 1; i <= 100; i++) {
            x.pali(i);
        }
    }

    void pali(int number) {

        int i;
        int copy = number;
        int rem, rev = 0;

        for (i = 0; number != 0; i++) {
            rem = number % 10;
            rev = rev * 10 + rem;
            number = number / 10;
        }


        if (copy == rev) {
            System.out.println("Pali = " + copy);
        }

    }
}

22:35

Method Overloading

Posted by Mitesh Patel |

/*
method overloading means
 *
 *
 * u can declare multiple functions/methods with the same name
 *
 * that functions must have different number/type of arguments
 */

class OverloadExample {

    public void show() // First function
    {
        System.out.println("function with no argument");
    }

    public void show(int x) // second function
    {
        System.out.println("function with one argument");
    }

    public void show(int x, int y) // second function
    {
        System.out.println("function with two argument");
    }
}

class MethodOverloading {

    public static void main(String args[]) {
        OverloadExample part= new OverloadExample();
        part.show();
        part.show(25);
        part.show(25, 75);

        OverloadExample mitesh = new OverloadExample();
        mitesh.show();
    }
}

22:33

Inheritance

Posted by Mitesh Patel |

/*
 inheritance example java
 */

class First
{
    void show()
    {
        System.out.println("This is parent class method");
    }
}

class Second extends First
{

}

class JavaInheritanceExample {

    public static void main(String args[])
    {
        Second mitesh = new Second();
        mitesh.show();
    }

}

22:31

Nesting Method

Posted by Mitesh Patel |


class MyClass {

    void show() {
        System.out.println("Just Free Knowledge");
    }

    void call() {

        show(); // call show method

    }
}

class FunctionNesting {

    public static void main(String args[]) {

        MyClass x = new MyClass();
        x.call();

    }
}

22:29

Array

Posted by Mitesh Patel |


import java.util.*;

class ArrayExample{

    public static void main(String args[]) {
        int a[] = new int[5];
        int i;
        int sum = 0;

        for(i=0;i<a.length;i++)
        {
            a[i]  = new Scanner(System.in).nextInt();
            sum = sum + a[i];
        }

       
        System.out.println("Avg = " + (sum/5));




    }
}

22:28

command line arguments

Posted by Mitesh Patel |

/*
java program to show how to get value from use
with the use of "command line arguments"
*/

class CLA
{
    public static void main(String args[])
    {
        int x = Integer.valueOf(args[0]);
        int y = Integer.valueOf(args[1]);
       
        System.out.println("The sum of values = " + (x+y));
       
    }
}

22:25

Looping

Posted by Mitesh Patel |

/*
Here avilable For loop ,while loop and do while loop
 */


class JavaLoopExample {

    public static void main(String args[]) {
        int i;

        System.out.println("For Example");
        for (i = 1; i <= 10; i++) {
            System.out.println(i);
        }
        i = 1;

        System.out.println("While  Example");


        while (i <= 10) {
            System.out.println(i);
            i++;
        }

        i = 1;

        System.out.println("Do While  Example");

        do {
            System.out.println(i);
            i++;
        } while (i <= 10);

    }
}

22:18

Multiple Class

Posted by Mitesh Patel |

/*
java program with multiple classes

and also it shows how to create object of class
*/

class First
{
    public void show()
    {
        System.out.println("Well come to just free knowledge");
    }
}


class MultipleExample
{
    public static void main(String args[])
    {
        First parth = new First();
        parth.show();
    }
}

22:17

Simple Class

Posted by Mitesh Patel |

class MyFloatVariableExample {

    public static void main(String args[]) {

        float x = 10.5f;

        System.out.println("The value of float variables = " + x);

    }
}

22:15

ODD and EVEN

Posted by Mitesh Patel |


class Odd_Even_Finder {

    public static void main(String args[]) {

        int x = Integer.valueOf(args[0]);

        if (x % 2 == 0) {

            System.out.println("EVEN");

        } else {
            System.out.println("ODD");
        }

    }

}

22:14

Max and Min Number

Posted by Mitesh Patel |


class MaxMin {

    public static void main(String args[]) {

        int x = Integer.valueOf(args[0]);
        int y = Integer.valueOf(args[1]);


        if (x < y) {
            System.out.println("Y is max" + y);
        } else {
            System.out.println("X is max" + x);
        }

    }
}

22:13

My First Java

Posted by Mitesh Patel |


class MyFirstJava
{
    public static void main(String args[])
    {
        System.out.print("Welcome to java programming");
       
        System.out.print("justfreeknowledge");
       
       
    }
}

21:47

Java Project Free

Posted by Mitesh Patel |

1.Black Jack Project

Project Show

Project Code

2.The Graphics Applet


Project Show

Project Code

3.The Spiral Graphic Program


Project Show

Project Code

4.The Chess Game


Project Show

Project Code

5.The Mod Converter



Project Show

Project Code

6.Naughts and Crosses Game


Project Show


Subscribe