CodingnDari java application
/*
* 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 feliks
*/
public class Grafika1 extends Frame {
int x = 100;
int y = 100;
public Grafika1(){
setTitle("Tugas Grafika feliks");
// 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.red);
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 h
g.setColor(Color.white);
int jumlahtitik_h = 1;
while (jumlahtitik_h <=100){
g.fillRect(350+jumlahtitik_h, 200+jumlahtitik_h, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik_h++; }
//mengambar String
g.setColor(Color.BLACK);
g.drawString("Grafik GarIIs Miring",250,450);
g.drawString("By : feliks",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 feliks
*/
public class Grafika1 extends Frame {
int x = 100;
int y = 100;
public Grafika1(){
setTitle("Tugas Grafika feliks");
// 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.red);
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 h
g.setColor(Color.white);
int jumlahtitik_h = 1;
while (jumlahtitik_h <=100){
g.fillRect(350+jumlahtitik_h, 200+jumlahtitik_h, 4, 4); // membuat titik dengan format (x,y,lebar x pixel, lebar y pixel)
jumlahtitik_h++; }
//mengambar String
g.setColor(Color.BLACK);
g.drawString("Grafik GarIIs Miring",250,450);
g.drawString("By : feliks",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);
}
}
Ouputnya
Tidak ada komentar:
Posting Komentar