بعض الشرح باللغة العربية
هذا الكود البسيط والفيد جدا أثناء تصميم الواجهات الرسومية في الجافا . فعند تصميم الواجهة على جهاز معين بقياسات ثابتة مثلا 800*600 فاننا عندما نشغل البرنامج على جهاز آخر ذو دقة شاشة عالية فاننا نجد انا البرنامج غير منسق بشكل جيد لذلك نجد انه من الجيد جدا ان نضع النافذة في وسط الشاشة .
للقيام بهذا العمل الجميل يمكننا استخدام الكود التالي الذي يقوم بوضع ال Frame في وسط الشاشة وبابعاد تكون بنسبة 50% من الشاشة وهو كما يلي وسوف اقوم ايضا بوضع تعليمة جميلة لوضع ايقونة للبرنامج مثل اي برنامج آخر
Some explain in Engish
This is a very simple and usefull code when you design GUIs. example you design your software in 800*600 screen and run it in high res screen your program will be like a postage stamp so we need a code to put the Frame in the cetnter of the screen by 50% od its size, I also put a code to put small ICON to be viewed in the task bar like other programs.
CLASS 1 (eadokingSimpleFrame.java)
import java.awt.Dimension;
import java.awt.Image;
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 Simple Frame");
// 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);
/* if we use this insted of the last one then
* we tell the windows to position the frame
*/
//setLocationByPlatform(true);
//this instruction will put an ICON in task bar
Image img = kit.getImage("d:\\eadokingICON.png");
setIconImage(img);
//set the frame vtrisible
without it we can't c the frame
setVisible(true);
//when we press (x) close then program terminated
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
CLASS 2 (eadokingMainFrame.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 Simple Frame");
// 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);
/* if we use this insted of the last one then
* we tell the windows to position the frame
*/
//setLocationByPlatform(true);
//set the frame vtrisible : ) without it we can't c the frame
setVisible(true);
//when we press (x) close then program terminated
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
انشاء الله بكون وضحت المعلومات بشكل واضح واي سؤال او استفسار انا جاهز مع تحيات عيدووو Eadoking
Hope everything is clear and uderstood , any question am ready, with regards. 3edoOo (Eadoking)





RT @eadoking Frame in the center of the screen and 50% of it with icon in TaskBar | Ead AlDoukanje Eadoking Official … http://bit.ly/gPsl4
RT @eadoking Frame in the center of the screen and 50% of it with icon in TaskBar | Ead AlDoukanje Eadoking Official … http://bit.ly/gPsl4