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();

    }
}

Subscribe