Java harshe ne mai ฦarfi da ake amfani da shi wajen haษaka nau'ikan aikace-aikace daban-daban, daga aikace-aikacen hannu zuwa tsarin sikelin kasuwanci. ฦaya daga cikin ษawainiya na gama gari don masu haษakawa shine tantance girman allo na na'ura ko saka idanu inda aikace-aikacen ke aiwatarwa, wanda zai iya rinjayar abubuwa kamar ฦirar UI da UX. Akwai hanyoyi da yawa don cim ma wannan a Java. A cikin wannan bayanin, mun zurfafa cikin hanya mai sauฦi kuma wacce aka fi amfani da ita.
Bayan duban bayanin bayanin, zamu tattauna zurfinsa, bayanin mataki-mataki na lambar. Za a kuma ba da haske kan muhimman ayyuka da ษakunan karatu da ke cikin wannan matsala. Manufar ita ce a ba ku kyakkyawar fahimtar yadda Java ke hulษa da tsarin ku don samo cikakkun bayanai.
Wannan ita ce maganin matsalarmu:
import java.awt.*; public class Main { public static void main(String[] args) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); double width = screenSize.getWidth(); double height = screenSize.getHeight(); System.out.println("Screen Width: "+ width); System.out.println("Screen Height: "+ height); } }
Lambar mu tana farawa ta hanyar shigo da kunshin java.awt.*, babban ษakin karatu wanda ke samar da mahimman APIs don ฦirฦirar mu'amalar mai amfani da hoto.
Toolkit.getDefaultToolkit().getScreenSize()
Toolkit babban aji ne hade a cikin kunshin java.awt. Wannan ajin yana da hanyar mai suna getDefaultToolkit(). Kamar yadda sunan ke nunawa, yana ษauko tsoffin kayan aikin kayan aiki. Tare da kowane Toolkit, za mu iya kiran hanyar getScreenSize(). Yana dawo da wani abu Dimension mai riฦe da faษin allo da tsayinsa. A fasaha, yana ษaukar girman girman abin dubawa na farko, wanda yawanci ya isa idan kuna aiki tare da tsarin kulawa guda ษaya.
Za mu iya cire nisa da tsayin allon ta hanyar kiran hanyoyin getWidth () da kuma getHeight() na abin Dimension. ฦimar da aka samu suna cikin pixels kuma suna wakiltar girman allo. Wannan bayanin yana da amfani don saita girman ษangaren ษangaren UI mai ฦarfi ko kuma idan abubuwan haษin gwiwa sun daidaita bisa waษannan ฦimar.
System.out.println ("Nisa allo:"+ nisa);
Bayan samun faษi da tsayi, lokaci yayi da za a buga waษannan ฦimar. Ana amfani da aikin na gargajiya System.out.println() anan. Muna buga faษin allo ta amfani da haษar kirtani don haษa ainihin "Nisa allo:" tare da ฦimar faษin.
Hakazalika, muna buga tsayi a cikin layi na gaba. Na'ura wasan bidiyo zai ษauki waษannan sakamakon, yana nuna girman allon PC ษin ku lokacin da kuke gudanar da wannan shirin.
Tare da ilimin da aka samu a nan, ya kamata ku iya yin amfani da ikon Java don yin hulษa tare da saitunan tsarin - ba kawai girman mai saka idanu ba. Lallai, daular Java tana da ma'ana da ban sha'awa, tana cike da ษimbin fasali da ayyuka cikakke don tunkarar ษawainiya da yawa. Daga ฦirar UI zuwa samun takamaiman bayanan tsarin, Java yana da abubuwa da yawa don bayarwa. Happy codeing!