A cikin duniyar da ta ci gaba da fasaha ta yau, akwai na'urori marasa adadi masu girman allo, kudurori, da ma'auni daban-daban. A matsayinka na mai haษaka Java, sau da yawa kana buฦatar ฦirฦira aikace-aikacen da suka dace da irin wannan nau'in allo. Kuma a nan ne fahimtar yadda ake samun bayanan girman allo ya zama mahimmanci. A cikin wannan labarin, za mu bincika yadda za a tunkari wannan ฦalubale da zurfafa zurfafa cikin ษakunan karatu na Java waษanda ke sa ya yiwu.
Samun girman allo muhimmin al'amari ne na tsara shirye-shirye masu dacewa da gani a Java. Ta hanyar tantance girman allo, zaku iya tabbatar da cewa aikace-aikacenku zai dace kuma ya nuna daidai akan nau'ikan na'urori da yawa, walau wayoyin hannu, kwamfutar hannu ko kwamfutocin tebur.
Don ฦayyade girman allo a Java, za mu yi amfani da java.awt kunshin, wanda ke ba da azuzuwan da yawa don ฦirฦirar abubuwan haษin haษin mai amfani da sarrafa abubuwan da suka faru. More musamman, za mu yi amfani da Zane-zane Muhalli, Na'urar Graphics, Da kuma Yanayin Nuni azuzuwan don samun dama da sarrafa bayanan girman allo.
Anan ga bayanin mataki-mataki na lambar Java don samun girman allo:
import java.awt.*; public class GetScreenSize { public static void main(String[] args) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); for (GraphicsDevice device : gs) { DisplayMode dm = device.getDisplayMode(); int screenWidth = dm.getWidth(); int screenHeight = dm.getHeight(); System.out.println("Screen width: " + screenWidth + " pixels"); System.out.println("Screen height: " + screenHeight + " pixels"); } } }
GraphicsMuhalli aji
The Zane-zane Muhalli aji wani muhimmin bangare ne na java.awt kunshin. Yana ba da ayyuka masu mahimmanci don samun bayanai game da yanayin zane-zane, kamar samuwan rubutu, da sarrafa yadda ake yin zane-zane akan na'urorin nuni.
A cikin lambar mu, mun ฦirฦiri a Zane-zane Muhalli misali ta amfani da samunLocalGraphicsMuhalli hanya. Wannan hanyar tana mayar da tunani zuwa yanayin zane na gida, yana ba da dama ga albarkatun zane iri-iri.
GraphicsNa'urar aji
A cikin kunshin Java AWT, da Na'urar Graphics aji yana wakiltar na'urar zane kamar allo ko firinta. Yana iya zama kayan aiki mai mahimmanci don aikace-aikacen allo mai cikakken allo, samun samuwan saitunan zane, da ฦari. A cikin yanayin mu, muna amfani da wannan ajin don samun bayanan da ake buฦata game da allon da muke son nuna aikace-aikacen Java a cikinsa.
Muna samun tsararru na Na'urar Graphics abubuwa ta hanyar kiran samun na'urorin allo Hanyar akan yanayin yanayin mu misali. Wannan jeri yana wakiltar duk na'urorin allo da ke cikin muhalli.
Yanayin nuni da girman allo
kowane Na'urar Graphics abu yana wakiltar na'urar allo, kuma zamu iya dawo da ita Yanayin Nuni ta hanyar kiran samunDisplayMode hanya. Da Yanayin Nuni ajin ya ฦunshi mahimman halayen da ake buฦata don yin zane-zane, kamar faษin allo, tsayin allo, ฦimar wartsakewa, da zurfin zurfafa.
Bayan mun samu Yanayin Nuni abu ga kowane graphics na'urar, za mu iya cire girman allo ta kiran da getWidth() da kuma getHeight() hanyoyin. Waษannan hanyoyin suna dawo da girman allo, waษanda za a iya amfani da su don ฦirฦirar abubuwan da suka dace da girman UI.
A ฦarshe, samun girman allo abu ne mai mahimmanci amma mai sauฦi na haษaka aikace-aikacen Java wanda ke tabbatar da dacewa da na'urori daban-daban da ฦudurin allo. Ta hanyar yin amfani da fakitin AWT mai ฦarfi da GraphicsMuhalinsa, Na'urar Graphics, da azuzuwan DisplayMode, zaku iya gina aikace-aikacen da ke dacewa da girman allo cikin hikima da ฦirฦirar ฦwarewar mai amfani mara nauyi a cikin na'urori.