Find us on Google+ Kill the code: awt
Showing posts with label awt. Show all posts
Showing posts with label awt. Show all posts

Sunday, 28 October 2012

Change Background Color using Jslider in Java

This program changes the background color using the three Jslider Red, Green and Blue. it also directly change to three basic color Red, Green, Blue using JpopupMenu using right click.

Here I attach one screenshot of it.




Saturday, 25 February 2012

Moving Circle in JAVA

An applet program to move circle in JAVA

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

/*
  <applet code="moving_circle" width=300 height=100>
  </applet>
*/

public class moving_circle extends Applet implements Runnable
{
    int x=0;
    Thread t;
    Image buffer;
    Graphics bufferg;

    public void init()
    {
        t=new Thread(this);
        t.start();
        Dimension d=getSize();
        buffer=createImage(d.width,d.height);
    }
    public void run()
    {
        try
        {
            while(true)
            {
               repaint();
               Thread.sleep(500);
            }
        }
        catch(Exception e)
        {
        }
    }

    public void update(Graphics g)
    {
        paint(g);
    }

    public void paint(Graphics g)
    {
        if(bufferg==null)
            bufferg=buffer.getGraphics();

        Dimension d=getSize();
        bufferg.setColor(Color.black);
        bufferg.fillRect(0,0,d.width,d.height);
        bufferg.setColor(Color.white);
        bufferg.fillOval(x,d.height/4,50,50);

        g.drawImage(buffer,0,0,this);
        x+=5;
        if(x+50>d.width)
            x=0;
    }
}