Senin, 15 Desember 2014

Contoh Program java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Retno_UAS;

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

/**
 *
 * @author Retno#02
 */

public class Retno_UAS extends JApplet
{
public static void pause()
{
    try {
        Thread.sleep(10);
        } catch(InterruptedException e) {
          }
}

public static void main(String args[])
{
    JApplet example = new Retno_UAS();
    JFrame frame = new JFrame("Retno AP");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(example);
    frame.setSize(new Dimension(300,300));     
    frame.setVisible(true);
}

/**
     * @param args the command line arguments
     */

  public void paint (Graphics page)
  {
 int width = getWidth();  
 int height = getHeight();

//Changes background color to a blueish color
page.setColor(new Color (140,214,225));
page.fillRect(0,0,width,height);
for(int i = 0; i <= 4; i++)
{
    for (int j = 0; j <= 100; j++)
    {
        page.setColor(Color.BLACK);
        page.fillOval(100,55 + j,100,100); 
        pause();
        page.setColor(new Color (140,214,225));
        page.fillOval(100,55 + j,100,100); 
    }
    for (int k = 100; k >= 0; k--)
    {
        page.setColor(Color.BLUE);
        page.fillOval(100,55 + k,100,100); 
        pause();
        if (k != 0)
        {
            page.setColor(new Color (140,214,225)); 
            page.fillOval(100,55 + k,100,100);
        }
    }
}
 }
 }

Tidak ada komentar:

Posting Komentar