Window with a tiles image drawing on java frame

window with tiles image java tips Window with a tiles image drawing on java frame

بعض الشرح باللغة العربية

هذا الكود البسيط والجميل ومهمته وضع اي صورة بشكل متكرر على كامل نافذة البرنامج, الكود يستخدم تقنية رسم الصورة على النافذة وليست وضع الصورة على مكون ثم تكرير المكون Component. مبدا الطريقة وهو بداية رسم الصورة الاساسية على الزاوية العليا اليسرى ثم نسخ المساحة بشكل متكرر حتى نقوم بتغطية النافذة بشكل كامل, وهكذا والكود موجود في الاسفل مع التوضيع لكل تعليمية او اي تابع مستخدم. والطريقة للحصول على الصورة بسيطة جدا حيث المسار ممكن ان يكون على القرص الصلب c,d,e … وممكن ان يكون على موقع ويب http://…

Some explain in Engish

This is a very simple and nice code and its function is to make the image tiles on your Form. The code use Draw Function in Graphics2D library in JAVA not a component like JLabel and tiles it . The way we do this is to draw the image on the TOP-LEFT corner and then we copy the area of image till we fill all form. The image may be on HARDDISK Driver such as c:\ d:\ … or on website like http:\\eadoking.com\logos\eadoking.com_logo.png

CLASS 1 (EadokingImagePanel.java)

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.net.URL;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
/**
*
* @author  Eadoking
* @website http://eadoking.com
* @email   eadoking@yahoo.com
* @email   info@eadoking.com
* @mobile  +963 932728084
*/
public class EadokingImagePanel extends JPanel {
private Image image = null;
public EadokingImagePanel() {
// the image path may be URL on network sich as
// String fileURL = "http://virtual-linux-server/eadoking_website_local/eadoking.com_logo.png";
// or it could be direct path from hard disk like
// d:\eadoking.com_logo.png WE PUT THEN
// d:\\eadoking.com_logo.png : \\ cuz first \ is an escape character
String filePATH = "http://localhost/eadoking.com_logo.png";
try {
// URL because netword path
// File if on harddisk sucj as d:\img
image = ImageIO.read(new URL(filePATH));
} catch (IOException ex) {
ex.printStackTrace();
}
}
@Override
public void paintComponent(Graphics g) {
// cast the Graphics to Graphics2D
Graphics2D g2d = (Graphics2D) g;
// if image = null means if image not found or something wrong when load it
// if that happens then do nothing (return)
if (image == null) {
return;
}
// get the image height and width
int imageWidth = image.getWidth(this);
int imageHeight = image.getHeight(this);
// draw the image in the top left corner
g2d.drawImage(image, 0, 0, this);
// repeat drawing image
for (int i = 0; i * imageWidth < = getWidth(); i++) {
for (int j = 0; j * imageHeight <= getHeight(); j++) {
if (i + j > 0) {
g.copyArea(0, 0, imageWidth, imageHeight, i * imageWidth, j * imageHeight);
}
}
}f
}
}

CLASS 2 (EadokingSimpleFrame.java)

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
/**
*
* @author  Eadoking
* @website http://eadoking.com
* @email   eadoking@yahoo.com
* @email   info@eadoking.com
* @mobile  +963 932728084
*
*
*/
public class EadokingSimpleFrame extends JFrame {
public EadokingSimpleFrame() {
setTitle("Eadoking Window with tiled Image");
// this code get the Default Toolkit
Toolkit kit = Toolkit.getDefaultToolkit();
// get the screen resolution
Dimension d = kit.getScreenSize();
// this is the screen width and height
int screenWidth = d.width;
int screenHeight = d.height;
// set the frame size 50% of the screen (desktop)
setSize(screenWidth / 2, screenHeight / 2);
//this simple instruction put the frame in the center of the screen
setLocationRelativeTo(null);
// creat new object of the ImagePanel
EadokingImagePanel imgPanel = new EadokingImagePanel();
//add the panel to the frame to be shown
add(imgPanel);
//set the frame vtrisible icon smile Window with a tiles image drawing on java frame  without it we can't c the frame
setVisible(true);
//when we press (x) close then program terminated
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

CLASS 3 (EadokingMainProgram.java)

import java.awt.EventQueue;
/**
*
* @author  Eadoking
* @website http://eadoking.com
* @email   eadoking@yahoo.com
* @email   info@eadoking.com
* @mobile  +963 932728084
*/
public class EadokingMainProgram {
public static void main(String[] args) {
Runnable r= new Runnable() {
public void run() {
EadokingSimpleFrame frame=new EadokingSimpleFrame();
}
};
EventQueue.invokeLater(r);
}
}

انشاء الله بكون وضحت المعلومات بشكل واضح واي سؤال او استفسار انا جاهز مع تحيات عيدووو Eadoking

Hope everything is clear and uderstood , any question am ready, with regards. 3edoOo (Eadoking)

Tags: , , , , , , , , , ,

About eadoking

Ead AlDoukanje - EADOKING - 3edoOo ( عيد الدكنجي Studied Informatics Engineering at Tishreen University ( Software Engineering Department ) Work as freelancer Web Developer / Software Developer You can contact me to me@eadoking.com mobile : ( +963 ) 0932728084 Programming Skills : Java, C# , C++ , Java Server Pages (JSP ) with SERVLETS, PHP ,HTML , CSS ,JAVA SCRIPT with Ajax , ASP.NET , Web Services .

Stay in touch

subscribe with us using social media or email to stay updated
you can also contact us if you need some request or any thing to ,
http://me.eadoking.com/contact-me

Discuss: “Window with a tiles image drawing on java frame”

  1. October 5, 2009 at 7:49 pm #

    Very cute :-) ))),

    Posted by Lohand
  2. October 5, 2009 at 4:49 pm #

    Very cute :-) ))),

    Posted by Lohand
  3. October 5, 2009 at 7:02 pm #

    Perfect work!,

    Posted by Fiesien
  4. October 5, 2009 at 4:02 pm #

    Perfect work!,

    Posted by Fiesien
  5. October 5, 2009 at 4:33 pm #

    Great site. Keep doing.,

    Posted by Mirigothien
  6. October 5, 2009 at 1:33 pm #

    Great site. Keep doing.,

    Posted by Mirigothien
  7. October 5, 2009 at 3:54 pm #

    Great work,webmaster,nice design!,

    Posted by lilikindsli
  8. October 5, 2009 at 12:54 pm #

    Great work,webmaster,nice design!,

    Posted by lilikindsli
  9. October 5, 2009 at 3:38 pm #

    I bookmarked this link. Thank you for good job!,

    Posted by lilikindsli
  10. October 5, 2009 at 12:38 pm #

    I bookmarked this link. Thank you for good job!,

    Posted by lilikindsli
  11. October 5, 2009 at 6:18 am #

    dilandinga: v5lqNY I bookmarked this link. Thank you for good job!

    welcome bro and wait all new stuff :D

    Posted by eadoking
  12. October 5, 2009 at 3:18 am #

    dilandinga: v5lqNY I bookmarked this link. Thank you for good job!

    welcome bro and wait all new stuff :D

    Posted by eadoking
  13. October 4, 2009 at 11:15 pm #

    v5lqNY I bookmarked this link. Thank you for good job!

    Posted by dilandinga
  14. October 4, 2009 at 8:15 pm #

    v5lqNY I bookmarked this link. Thank you for good job!

    Posted by dilandinga
  15. October 3, 2009 at 9:25 pm #

    Samoys: lot about you

    for more about me go to about-me or contact me or

    hope u like this code

    Posted by eadoking
  16. October 3, 2009 at 6:25 pm #

    Samoys: lot about you

    for more about me go to about-me or contact me or
    hope u like this code

    Posted by eadoking
  17. October 3, 2009 at 8:46 pm #

    lot about you

    Posted by Samoys
  18. October 3, 2009 at 5:46 pm #

    lot about you

    Posted by Samoys
  19. October 3, 2009 at 6:22 pm #

    RT @eadoking Window with a tiles image drawing on java frame | Ead AlDoukanje Eadoking Official Website : Your Way to… http://bit.ly/HCd90

    Posted by Eid AlDoukanji -3edo
  20. October 3, 2009 at 4:22 pm #

    RT @eadoking Window with a tiles image drawing on java frame | Ead AlDoukanje Eadoking Official Website : Your Way to… http://bit.ly/HCd90

    Posted by Eid AlDoukanji -3edo

Trackbacks/Pingbacks

  1. Ead AlDoukanje -3edo - October 3, 2009

    RT @eadoking Window with a tiles image drawing on java frame | Ead AlDoukanje Eadoking Official Website : Your Way to… http://bit.ly/HCd90

Leave a Reply


*