An warware: sami girman saka idanu

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!

Shafi posts:

Leave a Comment