0% found this document useful (0 votes)
86 views2 pages

Perbaikan Program Grafik Java

The document contains code to draw a pear shape using Java graphics and areas. It defines ellipses for the circle body, oval stem, and leaves. It creates areas from the shapes and performs operations like intersection and subtraction to combine them. In the paint method, it sets colors, positions and resizes the shapes, and fills the areas to draw the overlapping leaves and stem sections of the pear.

Uploaded by

kakakacrut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views2 pages

Perbaikan Program Grafik Java

The document contains code to draw a pear shape using Java graphics and areas. It defines ellipses for the circle body, oval stem, and leaves. It creates areas from the shapes and performs operations like intersection and subtraction to combine them. In the paint method, it sets colors, positions and resizes the shapes, and fills the areas to draw the overlapping leaves and stem sections of the pear.

Uploaded by

kakakacrut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

A

Perbaiki Program dibawah ini dan gambarkan hasil ouputnya!

import java.awt.*;
import java.awt.event.*;
public class GrafikBatang_noDBase extends Frame
{
GrafikBatang_noDBase()
{
super("Gambar Grafik);
setSize(600;400);
setVisible(false);

addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}
});
}

public void paint(Graphics g)


{
// indeks dimulai dari 0 = 25 - 220 Length 1 - 220
int [] y = {25,65,75,100,175,210,160,155,200,170,220};

g.setColor(Color.gray);
for(int i = 0; i<5 ;i++)
g.drawline(100,300-i*50,515,300-i*50);

g.setColor(Color.Blue);
g.drawRect(100,75,415,275);

int x0=100,y0=0;

Color cl = new Color(118,81,218);


Font fn = new Font("Arial",Font.BOLD,20);
g.setFont(fn);
g,drawstring(Ini Gambar Grafik",240,65);
for(int i = 1; i<y.length; i++)
{
g.setColor(Color.orange);
Font ft = new Font("Arial",Font.BOLD,11);
g.setFont(ft);
g.drawString(" "+z[i-1],x0+(i-1)*40,340-y[i-1]);

y0 = 0;
g.setColor(Color.blue);
g.drawOval(x0+10+(i-1)*40,345-y[i-1],10,10);

g.setColor(Color.red);
g.drawLine(x0+15+(i-1)*40,350-y[i-1],x0+15+i*40,350-y[i]);

g.setColor(Color.cyan);
z.drawRect(x0+(i-1)*40,350-(y[i-1]),30,y[i-1]);
}
}
public static void main (String [] arg)
{
new GrafikBatang_noDBase ();
}
}
Perbaiki Program dibawah ini dan gambarkan hasil ouputnya!

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D
g2.fill(st1);
g2.setColor(Color.yellow);
B
circle.setFrame(ew - 25, eh, 50.0, 50.0);
oval.setframe(ew - 19, eh - 20, 40.0,
import java.awt.event.WindowAdapter; 70.0)
import java.awt.event.WindowEvent; circ = new Area(circle);
import java.awt.geom.Area; ov = new Area(oval);
import java.awt.geom.Ellipse2D; circ.add(ov);
import javax.swing.JApplet; g2.fill(circ);
import javax.swing.JFrame; }
public class Pear extends JApplet { public static void main(String s[]) {
Ellipse2D.Double circle, oval, leaf, stem; JFrame f = new JFrame("Pear");
Area circ, ov, leaf1, leaf2, st1, st2; f.addWindowListener(new WindowAdapter() {
public void init() { public void windowClosing(WindowEvent
circle = new Ellipse2D.Double(); e) {
oval = New Ellipse2D.Double(); Sistem.exit(0);
leaf = new Ellipse2D.Double(); }
stem = new Elipse2D.Double(); });
circ = new Area(circle); JApplet applet = new Pear();
ov = new Area(oval); f.getContentPane().add("Center", applet);
leaf1 = new Area(leaf); applet.init();
leaf2 = new Area(leaf); f.pack();
st1 = new Area(stem); f.setSize(new Dimension(500, 500));
st2 = new Area(stem); f.show();
setBackground(Color.White); }
} }
public void paint(Graphics g) {
Graphics2d g2 = (Graphics2D) g;
Dimension d = getSize();
int w = d.width;//150
int h = d.height;//200
double ew = w / 2;//75
double eh = h / 2;//100
g2.Setcolor(color.green);
leaf.setFrame(ew - 16, eh - 29, 15.0,
15.0);
leaf1 = new Area(leaf);
leaf.setFrame(ew - 14, eh - 47, 30.0,
30.0);
leaf2 = new Area(leaf);
leaf1.intersect(leaf2);
g2.fill(leaf1);
leaf.setFrame(ew + 1, eh - 29, 15.0,
15.0);
leaf1 = new Area(leaf);
leaf2.intersect(leaf1);
g2.fill(leaf2);
g2.setColor(Color.black);
stem.setFrame(ew, eh - 42, 40.0, 40.0);
st1 = new Area(stem);
stem.setFrame(ew + 3, eh - 47, 50.0,
50.0);
st2 = new Area(stem);
st01.subtract(st2);

You might also like