TUGAS GRAFIKA KOMPUTER
Codingnya
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grafika1;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Videl
*/
public class Grafika1 extends Frame {
int x = 100;
int y = 100;
public Grafika1(){
setTitle("Tugas Grafika Videl");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("File");
mb.add(menu);
MenuItem mi = new MenuItem("Exit");
WindowListener l = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
};
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
x = ev.getX();
y = ev.getY();
repaint();
}
};
addMouseListener(mouseListener);
}
@Override
public void paint(Graphics g) {
//mengambar garis miring b
g.setColor(Color.BLUE);
int jumlahtitik = 1;
while (jumlahtitik <=100){
g.fillRect(200+jumlahtitik, 200+jumlahtitik, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik++; }
//mengambar garis miring a
g.setColor(Color.blue);
int jumlahtitik_a = 1;
while (jumlahtitik_a <=100){
g.fillRect(200-jumlahtitik_a, 200+jumlahtitik_a, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik_a++; }
//mengambar garis datar c
g.setColor(Color.blue);
int jumlahtitik_b = 1;
while (jumlahtitik_b <=200){
g.fillRect(100+jumlahtitik_b, 300, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik_b++; }
//mengambar String
g.setColor(Color.BLACK);
g.drawString("Grafik GarIIs Miring",250,450);
g.drawString("By : Aryanti",550,510);
g.setFont(new Font("Courier",Font.BOLD,20));
g.drawString("Tugas Grafika Komputer",250,150);
//(640, 530);
g.drawLine(225,453,345,453);
g.drawLine(227,455,345,455);
g.drawLine(232,440,232,470);
g.drawLine(234,440,234,475);
g.drawLine(220,440,245,465);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Frame frame = new Grafika1();
frame.setSize(640, 530);
frame.setVisible(true);
}
}
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package grafika1;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author Videl
*/
public class Grafika1 extends Frame {
int x = 100;
int y = 100;
public Grafika1(){
setTitle("Tugas Grafika Videl");
// create menu
MenuBar mb = new MenuBar();
setMenuBar(mb);
Menu menu = new Menu("File");
mb.add(menu);
MenuItem mi = new MenuItem("Exit");
WindowListener l = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent ev) {
System.exit(0);
}
};
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent ev) {
x = ev.getX();
y = ev.getY();
repaint();
}
};
addMouseListener(mouseListener);
}
@Override
public void paint(Graphics g) {
//mengambar garis miring b
g.setColor(Color.BLUE);
int jumlahtitik = 1;
while (jumlahtitik <=100){
g.fillRect(200+jumlahtitik, 200+jumlahtitik, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik++; }
//mengambar garis miring a
g.setColor(Color.blue);
int jumlahtitik_a = 1;
while (jumlahtitik_a <=100){
g.fillRect(200-jumlahtitik_a, 200+jumlahtitik_a, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik_a++; }
//mengambar garis datar c
g.setColor(Color.blue);
int jumlahtitik_b = 1;
while (jumlahtitik_b <=200){
g.fillRect(100+jumlahtitik_b, 300, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik_b++; }
//mengambar String
g.setColor(Color.BLACK);
g.drawString("Grafik GarIIs Miring",250,450);
g.drawString("By : Aryanti",550,510);
g.setFont(new Font("Courier",Font.BOLD,20));
g.drawString("Tugas Grafika Komputer",250,150);
//(640, 530);
g.drawLine(225,453,345,453);
g.drawLine(227,455,345,455);
g.drawLine(232,440,232,470);
g.drawLine(234,440,234,475);
g.drawLine(220,440,245,465);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Frame frame = new Grafika1();
frame.setSize(640, 530);
frame.setVisible(true);
}
}
Tidak ada komentar:
Posting Komentar