BASIC 2 HIFI PROGRAM ...
ALL HERE

Monday 22 December 2014

simple animation in java

import javax.swing.*;
import java.awt.*;

public class SimpleAnimation {
int x = 70;
int y = 70;

public static void main(String[] args)
{
SimpleAnimation gui = new SimpleAnimation () ;
gui.go();
}

public void go()
{
JFrame frame = new JFrame() ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

MyDrawPanel drawPanel = new MyDrawPanel() ;

frame.getContentPane().add(drawPanel);
frame.setSize(300,300);
frame.setVisible(true);

for(int i=0;i<=130;i++)
{
x++ ;
y++ ;
drawPanel.repaint();

try
{
Thread.sleep(50);
}
catch(Exception ex) { }
}
}

class MyDrawPanel extends JPanel {

public void paintComponent(Graphics g)
{
g.setColor(Color.green);
g.fillOval(x,y,40,40);
}
}
}

making rectangle in java graphics

import java.awt.*;
import javax.swing.*;

class rect extends JPanel {
public void paintComponent(Graphics g)
{
g.setColor(Color.orange);
for(int i=0;i<=500;i++)
{
g.fillRect(20,i,100,100);
}
}
}

public class rectangle_movement {
public static void main(String[] args)
{
JFrame frame=new JFrame();
frame.getContentPane().add(new rect());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,800);
frame.setVisible(true);
}
}

GENERATE RANDOMCOLOR IN JAVA

import java.awt.*;
import javax.swing.*;

class random_color extends JPanel {

public void paintComponent(Graphics g)
{
g.fillRect(0,0,this.getWidth(),this.getHeight());

int red =(int)(Math.random()*255);
int green=(int)(Math.random()*255);
int blue=(int)(Math.random()*255);
Color randomColor=new Color(red,green,blue) ;
g.setColor(randomColor);
g.fillOval(70,70,100,100);
}
}

public class randomly{
public static void main(String[] args)
{
JFrame frame=new JFrame();
frame.getContentPane().add(new random_color());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,800);
frame.setVisible(true);
}
}

READING PHOTO IN JAVA

import java.awt.*;
import javax.swing.*;

class ph extends JPanel
{
public void paintComponent(Graphics g)
{
Image image=new ImageIcon("honda-bikes-42a (1).jpg").getImage();
g.drawImage(image,3,4,this);
}
}



public class photo {
public static void main(String[] args)
{
JFrame frame=new JFrame();
frame.getContentPane().add(new ph());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,800);
frame.setVisible(true);
}
}

TYPECASTING PROGRAM

class typecasting {
public static void main(String[] args)
{
long y=42;
int x=(int)y;
System.out.println(x);
long m=40002;
short p=(short)m;
System.out.println(p);
float f=9.83f;
int l=(int)f;
System.out.println(l);
}
}

POLYMORPHISM

class animal {
void eat() {
System.out.println("ii ii ii ii");
}
}

class mammal extends animal {
}


public class polymorphism {
public static void main(String[] args)
{
animal man=new mammal();
man.eat();
}

A SIMPLE PARSING PROGRAM

public class parsing {
public static void main(String[] args)
{
String g="5";
int m=Integer.parseInt(g);
System.out.println(m);
}
}