A cikin duniyar haษaka software, samun girman allo na na'ura muhimmin al'amari ne, ba kawai don daidaita mu'amalar masu amfani ba har ma don ฦirฦirar aikace-aikacen amsawa da daidaitawa. ฦaya daga cikin shahararrun yaren shirye-shiryen da ke ba masu haษaka damar cimma wannan shine Java. A cikin wannan labarin, za mu bincika yadda ake samun girman allo a Java, samar da bayanin mataki-mataki na lambar, da kuma tattauna ษakunan karatu da ayyuka masu alaฦa da ke cikin wannan tsari.
Samun Girman allo ta amfani da Java
Java yana ba da aji mai suna Toolkit wanda nasa ne java.awt kunshin. Wannan ajin yana ba da hanyoyi da yawa waษanda ke taimakawa masu haษaka aiki tare da aikace-aikacen GUI. Daya daga cikin wadannan hanyoyin shine GetScreenSize(), wanda ke mayar da girman allo a matsayin misali na girma aji.
import java.awt.Dimension; import java.awt.Toolkit; public class Main { public static void main(String[] args) { // Obtain the screen size Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // Get the width and height int width = screenSize.width; int height = screenSize.height; System.out.println("Screen Width: " + width); System.out.println("Screen Height: " + height); } }
Bayanin mataki-mataki na Code
Lambar da ke sama tana nuna yadda ake samun girman allo ta amfani da Java. Bari mu karya shi mataki-mataki:
1. Na farko, muna shigo da darussan da ake bukata daga java.awt kunshin - girma da kuma Toolkit.
2. A cikin babban hanya, muna kira da samunDefaultToolkit() Hanyar Toolkit aji don samun misali na tsoffin kayan aiki, wanda ke ba da dama ga hanyoyin amfani daban-daban.
3. Sa'an nan, mu kira da GetScreenSize() hanya akan misalin kayan aiki, wanda ke dawo da a girma abu mai wakiltar girman allo. An adana nisa da tsayin allo azaman kaddarorin girma abu.
4. A ฦarshe, muna dawo da nisa da tsawo daga girma abu kuma buga ฦimar zuwa na'ura wasan bidiyo.
Toolkit Class a cikin Java.awt Kunshin
The Toolkit class a cikin java.awt kunshin wani muhimmin abu ne na Kayan aikin Tagar Abstract (AWT) a Java. Wannan ajin yana ba da hanyoyin yin hulษa tare da tsarin taga na asali. Baya ga samun girman allo, da Toolkit aji kuma yana ba da hanyoyi don:
- Samun hoto
- ฦirฦirar siginar al'ada
- Samun ฦudurin allo
- ฦara mai magana
Waษannan hanyoyin suna ba masu haษakawa damar ฦirฦirar mafi kyawun mu'amalar mai amfani waษanda ke gauraya da tsarin aiki ba tare da matsala ba.
Class Dimension in Java.awt Package
The girma aji wani muhimmin bangare ne na AWT. Yana ษaukar faษi da tsayin sashi a cikin abu ษaya, yana ba masu haษaka damar yin aiki da inganci tare da girma. Bayan adana wides da tsawo, da girma aji yana ba da hanyoyi don:
- ฦirฦirar sabon girma wanda ke wakiltar mafi girman girma biyu
- Saita girman girman
- Maimaita girman girman
A ฦarshe, samun girman allo a Java yana da sauฦi godiya ga Toolkit da kuma girma azuzuwan bayar da java.awt kunshin. Ta hanyar amfani da waษannan azuzuwan da hanyoyin da aka bayar, masu haษakawa na iya ฦirฦirar aikace-aikacen amsawa da daidaitawa waษanda ke ษaukar nau'ikan allo daban-daban da haษaka ฦwarewar mai amfani akan na'urori daban-daban.