Java Programming tutorial, GUI, Graphical User Interface. this tutorial is teaching. How to use Java graphics repaint Method to repaint the graphics every 60 seconds.
//BKGround.java class below followed by GraphicsTut.java
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.*;
import javax.swing.ImageIcon;
public class BKGround extends JPanel{
Image image;
Image image2;
int x1,y1,x2,y2;
public BKGround(){
ImageIcon I = new ImageIcon("image/Abstract-background-1.png");
image = I.getImage();
ImageIcon I2 = new ImageIcon("image/madBoySprite.png");
image2 = I2.getImage();;
}
public void paint(Graphics g){
x1 = 100;
y1 = 100;
x2 = 200;
y2 = 200;
ImageIcon i = new ImageIcon("image/Abstract-background-1.png");
image = i.getImage();
g.drawImage(image, 0, 0, null);
g.setColor(Color.BLACK);
g.drawRect(40, 40, 30, 30);
g.setColor(Color.RED);
g.drawOval(80, 80, 30, 30);
g.fillArc(140, 140, 30, 30, 180, 10);
g.drawLine(100, 300, 350, 400);
g.setFont(new Font("Arial",Font.BOLD,34));
g.drawString("Paint this!", 150, 100);
ImageIcon i2 = new ImageIcon("image/charcustomsheet.gif");
image2 = i2.getImage();
//g.drawImage(image2, 100, 200, null);
g.drawImage(image2, x1, y1, x2, y2, 40, 60, 80, 120,Color.GREEN, null);
g.drawImage(image2, 250, 250, 50, 50, null);
repaint();
}
}
// GraphicsTut.java class code below
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
public class GraphicsTut extends JFrame{
Image image;
Image image2;
int x1,y1,x2,y2;
BKGround bkg = new BKGround();
public GraphicsTut(){
this.setTitle("Remember g for Graphics");
this.setSize(450,350);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
this.add(bkg);
}
public static void main(String[] args){
new GraphicsTut();
}
}
On this page of the site you can watch the video online Java programming part 96 Graphics : Java Graphics Repaint Method with a duration of hours minute second in good quality, which was uploaded by the user Redemptie 07 July 2012, share the link with friends and acquaintances, this video has already been watched 7,913 times on youtube and it was liked by 13 viewers. Enjoy your viewing!