An warware: Java clear console

share wasan bidiyo A cikin duniyar shirye-shirye, mun ci karo da yanayi iri-iri inda muke buฦ™atar share na'urar bidiyo don inganta karantawa ko kuma kawai don farawa da sabon slate. ฦŠaya daga cikin irin wannan misalin da za mu tattauna a yau shine a cikin harshen shirye-shiryen Java. Java, kasancewar ษ—aya daga cikin mashahuran harsuna, yana ba da ษ—imbin ษ—akunan karatu da ayyuka don magance matsalar da ke hannunsu. A cikin wannan labarin, za mu nutse cikin zurfin fahimtar mafita don share wasan bidiyo a Java, yin bayanin lambar mataki-mataki, da kuma tattauna wasu mahimman ษ—akunan karatu da ayyuka waษ—anda ke taka muhimmiyar rawa wajen warware wannan batu.

Ana share kayan wasan bidiyo a Java

Don share console a Java, babu hanyar ginawa wanda za a iya amfani da shi kai tsaye. Koyaya, zamu iya cimma wannan ta amfani da dabaru daban-daban dangane da dandamali (Windows, Mac, Linux) lambar mu tana gudana. A cikin wannan labarin, za mu mai da hankali kan hanyar da ake amfani da ita da yawa wacce ke amfani da ANSI lambobin tserewa don share na'urar wasan bidiyo, wanda ke zaman kansa.

public class ClearConsole {
    public static void main(String[] args) {
        clearConsole();
        System.out.println("Console cleared!");
    }

    public static void clearConsole() {
        System.out.print("33[H33[2J");
        System.out.flush();
    }
}

A cikin snippet code a sama, muna da ajin Java mai sauฦ™i da ake kira ClearConsole tare da main hanya, wacce ita ce hanyar shiga shirinmu. A cikin babbar hanyar, muna kira da clearConsole() aiki, wanda ke yin sihiri na share na'ura mai kwakwalwa.

Fahimtar Magani

Bari mu rushe lambar don fahimtar yadda hanyar clearConsole() ke aiki.

The clearConsole Hanyar ta ฦ™unshi mahimman layi biyu:
1. `System.out.print ("33[H33[2J");'
2. `System.out.flush();`

Layi na farko yana amfani da lambobin tserewa na ANSI don ba da umarni ga na'ura wasan bidiyo don share abun ciki. Sashin "33[H" na lambar tserewa yana motsa siginan kwamfuta zuwa kusurwar sama-hagu na tasha, yayin da ษ“angaren "33[2J" yana share allon tashar gaba ษ—aya. Haษ—a waษ—annan lambobin tserewa guda biyu yana tabbatar da cewa an tsaftace allon kuma an saita siginan kwamfuta a wurin farawa. An rubuta waษ—annan lambobin a cikin aikin `System.out.print()` wanda ke buga su akan na'ura mai kwakwalwa.

Layi na biyu, `System.out.flush();`, ana amfani da shi don zubar da rafin fitarwa. Yana tabbatar da cewa duk bayanan da aka ษ“oye a cikin rafin fitarwa ana fitar da su nan da nan don nunawa akan na'urar bidiyo. Yana taimakawa wajen kiyaye kayan aikin na'urar bidiyo na zamani da aiki tare da rubutaccen umarni.

Laburaren Java da Ayyuka

Yayin da hanyar da aka nuna a sama sanannen zaษ“i ne don sauฦ™i da inganci, Java yana ba da ษ—akunan karatu da ayyuka daban-daban waษ—anda za a iya amfani da su don ayyuka iri ษ—aya. Wasu daga cikin manyan ษ—akunan karatu da ayyukansu sune:

  • java.io: Wannan ษ—akin karatu yana ba da ayyuka masu alaฦ™a da ayyukan shigarwa/fitarwa, gami da sarrafa fayil da karantawa/rubutu bayanai daga/zuwa na'ura wasan bidiyo. Ana iya amfani da shi a yanayi daban-daban, kamar karanta bayanai daga mai amfani yayin da shirin ke gudana.
  • java.util: Wannan ษ—akin karatu yana ฦ™unshe da tsarin bayanai masu amfani da azuzuwan amfani don tarawa, ranaku, da lokuta. Ana iya amfani da shi don sarrafawa da tsara bayanai a cikin shirin yadda ya kamata.
  • java.lang.System: Wannan ajin ya ฦ™unshi filayen aji da yawa masu amfani da hanyoyin, kamar fita, ciki, currentTimeMillis(), da fita(). Ana amfani da waษ—annan galibi don ayyukan shigarwa/fitarwa, sarrafa lokaci, da sarrafa tafiyar aiwatar da shirin Java.

A ฦ™arshe, share na'urar bidiyo a Java za a iya samu ta hanyoyi daban-daban, dangane da dandamali. Hanyar tserewa ta ANSI dalla-dalla a cikin wannan labarin yana ba da mafita mai zaman kansa. Dakunan karatu na Java, irin su java.io, java.util, da java.lang.System, suna ba da ayyuka da yawa don sarrafa sassa daban-daban na ayyukan na'ura wasan bidiyo da kuma biyan takamaiman bukatun shirin Java.

Shafi posts:

Leave a Comment