Loading:


    Tekst płynący w lewo płynnie zmieniający kolory

    Skrypt wyświetla aplet w którym tekst wpłynie w lewo i płynnie zmienia kolory.

    Aby stworzyć Aplet Java tworzymy najpierw kod Java w pliku plik.class a następnie tworzymy odwołanie do niego w HTML poprzez znacznik <aplet></aplet>



    Napisz Artyku³

    Listing


    // Kod HTML

    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <APPLET
            code      = "kodJava.class"
            text      = "Java wiczenia Praktyczne - http://helion.pl/ksiazki/cwjava.htm - Numer katalogowy 1736"
            fontsize  = "30"
            speedstep = "1"
            sleepInterval = "10"
            width     = "800"
            height    = "100">
    </APPLET>
    </BODY>
    </HTML>


    //Kod Java kodJava.class

    import java.awt.*;
    import java.applet.*;

    public
    class FlowString extends Applet implements Runnable
    {
      int x, y, speedStep;
      int appWidth, appHeight;
      int strWidth, strHeight;
      int sleepInterval;
      String napis;
      Font fontTimesRoman;
      Image img;
      Graphics gDC, mDC;
      boolean stopped = false;
      public void init()
      {
        if((napis = getParameter("text")) == null)
          napis = "Brak parametru text!";

        String strFontSize;
        int fontSize;
        if((strFontSize = getParameter("fontsize")) == null)
          strFontSize = "36";

        try{
           fontSize = Integer.parseInt(strFontSize);
        }
        catch(Exception e){
          fontSize = 36;
        }

        String strSpeedStep;
        if((strSpeedStep = getParameter("speedstep")) == null)
          strSpeedStep = "1";

        try{
            speedStep = Math.abs(Integer.parseInt(strSpeedStep));
        }
        catch(Exception e){
          speedStep = 1;
        }

        String strSleepInterval;
        if((strSleepInterval = getParameter("sleepInterval")) == null)
          strSleepInterval = "1";
        try{
            sleepInterval = Math.abs(Integer.parseInt(strSleepInterval));
        }
        catch(Exception e){
          sleepInterval = 1;
        }

        appWidth = getWidth();
        appHeight = getHeight();

        setBackground(Color.white);

        fontTimesRoman = new Font ("TimesRoman", Font.BOLD, fontSize);
        img = createImage(appWidth, appHeight);
        mDC = img.getGraphics();
        gDC = getGraphics();

        gDC.setFont(fontTimesRoman);
        FontMetrics fm = gDC.getFontMetrics();
        strHeight = fm.getHeight();
        strWidth = fm.stringWidth(napis);

        x = appWidth;
        y = (int)((appHeight + strHeight) / 2);
      }
      public void start()
      {
        Thread thread = new Thread (this);
        thread.start();
      }
      public void stop()
      {
        stopped = true;
      }
      public void run()
      {
        Color color;
        int i = 0, j = 1;
        while (!stopped){
          if (x < -strWidth){
            x = appWidth;
          }
          try{
            Thread.sleep(sleepInterval);
          }
          catch (InterruptedException e){
          }
          color = new Color(i, 0, 255 - i);
          i += j;
          if(i >= 255 || i <= 0) j = -j;
          x -= speedStep;
          mDC.clearRect(0, 0, appWidth, appHeight);
          mDC.setColor (color);
          mDC.setFont (fontTimesRoman);
          mDC.drawString (napis, x, y);
          gDC.drawImage (img, 0, 0, this);
        }
      }
    }
     




    Dodano przez: igor
    Ranga: Administrator serwisu Punktów: 0
    Komentarze użytkowników
      • Tre¶æ komentarza
        Kod do komentarza (opcjonalnie)
        PHP JavaScript MySQL Smarty SQL HTML CSS ActionScript
        Autor
        Token
        token

         

         








    funkcje.net
    Wszelkie prawa zastrzeżone©. | Funkcje.net 2008-2025 v.1.5 | design: diviXdesign & rainbowcolors