User Tools

Site Tools


watermellon
Watermellon.java
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class Watermellon extends JComponent
{
    private Color lightGreen = new Color (0, 255,128);
    private Color darkGreen = new Color (0, 128, 64);
    public void paintComponent(Graphics g)
    {
        Graphics2D g2 = (Graphics2D)g;
        Point2D center = new Point2D.Double(150.0, 150.0);
        Point2D corner = new Point2D.Double(50.0, 100);
 
        Ellipse2D.Double oval = new Ellipse2D.Double();
        oval.setFrameFromCenter( center, corner );
        g2.setColor(darkGreen);
        g2.fill(oval);
 
        corner = new Point2D.Double(50.0, 110.0);
        oval.setFrameFromCenter( center, corner );
        g2.setColor(lightGreen);
        g2.fill(oval);
 
        corner = new Point2D.Double(50.0, 120.0);
        oval.setFrameFromCenter( center, corner );
        g2.setColor(darkGreen);
        g2.fill(oval);
 
        corner = new Point2D.Double(50.0, 130.0);
        oval.setFrameFromCenter( center, corner );
        g2.setColor(lightGreen);
        g2.fill(oval);
 
        corner = new Point2D.Double(50.0, 140.0);
        oval.setFrameFromCenter( center, corner );
        g2.setColor(darkGreen);
        g2.fill(oval);
    }
 
}
WatermellonViewer.java
import javax.swing.JFrame;
 
public class WatermellonViewer
{
 
    public static void main ( String[] args )
    {
        JFrame frame = new JFrame();
        frame.setSize(400,300);
        frame.setTitle("Watermellon");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
        Watermellon w= new Watermellon();
        frame.add (w);
 
        frame.setVisible(true);
    }
}
watermellon.txt · Last modified: 2018/08/21 00:12 by cthiel

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki