学习Java,希望能够在网站上查看课程

发布于 2024-12-26 01:55:46 字数 338 浏览 3 评论 0原文

我正在学习如何使用 Java,我想为我的网站制作一个文本滚动条。

我找到了一个类似的滚动条,我想添加它,但我想查看代码以了解它是如何完成的。

该小程序可以在这里找到: http://www.javascriptkit.com/java/java20.shtml< /a>

问题是,当我尝试在记事本中打开类文件时,编码或文本会显示奇怪的字符,而不是显示代码。

请有人让我知道是否有任何可能的方式让我查看此类的代码。

谢谢

I am learning how to use Java and I want to make a text scroller for my website.

I have found a similar scroller that I want to add but I want to look at the code to see how it was done.

The applet can be found here: http://www.javascriptkit.com/java/java20.shtml

The problem is when I try to open the class file within notepad the encoding or text shows up with strange characters instead of showing me the code.

Please can someone let me know if there is any possible way of me seeing the code for this class.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⒈起吃苦の倖褔 2025-01-02 01:55:46

这是一个类文件,意味着它是编译代码,因此您看不到它的源代码。
为了查看源代码,您需要 .java 文件,该文件是您编译以获取字节代码的文件。

看来该网站只是提供编译后的类,你永远不知道使用它它们可能在类中还有一些隐藏的功能,例如将信息发送到所有者服务器等。

编辑:

所以这里是ProScroll version 2.3 by Slava Pestov编写的小程序的反编译代码

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;

public class ProScroll extends Applet
  implements Runnable
{
  private Thread thread;
  private Image image;
  private int scrollLength;
  private int scrolled;
  private int speed = 10;
  private int imgsWidth;
  private URL url;
  private String target;
  private Color bgColor;

  public void init()
  {
    int i = 12; int j = 0;

    String str2 = getParameter("TEXT");
    String str3 = getParameter("TEXTURL");

    if ((str2 == null) && (str3 == null)) {
      str2 = "No TEXT or TEXTURL parameter specified";
    }
    if (str3 != null)
    {
      localObject = new StringBuffer();
      try
      {
        InputStream localInputStream = new URL(str3)
          .openConnection().getInputStream();
        while (true)
        {
          int k = localInputStream.read();
          if (k == -1) break;
          if (k != 10) {
            if (k == 9) { ((StringBuffer)localObject).append(' '); continue; }
            ((StringBuffer)localObject).append((char)k);
          }
        }
        localInputStream.close();

        str2 = ((StringBuffer)localObject).toString();
      }
      catch (Exception localException1)
      {
        if (str2 == null) {
          str2 = "Error loading text from URL: " + localException1;
        }
      }
    }
    String str1 = getParameter("FONT");
    if (str1 == null) str1 = "TimesRoman";

    this.target = getParameter("TARGET");
    if (this.target == null) this.target = "_self";

    try
    {
      i = Integer.parseInt(getParameter("SIZE"));
    }
    catch (Exception localException2)
    {
    }

    Object localObject = getParameter("STYLE");
    if ("bold".equals(localObject)) j = 1;
    else if ("italic".equals(localObject)) j = 2;
    else if ("bolditalic".equals(localObject)) j = 3;

    String str4 = getParameter("SPEED");
    if ("slow".equals(str4)) this.speed = 20;
    else if ("medium".equals(str4)) this.speed = 15; else {
      this.speed = 10;
    }
    try
    {
      this.url = new URL(getDocumentBase(), getParameter("URL"));
    }
    catch (Exception localException3)
    {
    }

    this.bgColor = parseColorName(getParameter("BGCOLOR"), Color.black);

    Enumeration localEnumeration = parseAndLoadImages(getParameter("IMAGES"));

    Font localFont = new Font(str1, j, i);

    FontMetrics localFontMetrics = getToolkit().getFontMetrics(localFont);

    this.image = createImage(localFontMetrics.stringWidth(str2) + this.imgsWidth + size().width, size().height);

    this.scrolled = (-size().width);

    parseAndDrawText(this.image.getGraphics(), str2, localFontMetrics, localFont, localEnumeration);
  }

  private void parseAndDrawText(Graphics paramGraphics, String paramString, FontMetrics paramFontMetrics, Font paramFont, Enumeration paramEnumeration)
  {
    paramGraphics.setFont(paramFont);
    paramGraphics.setColor(this.bgColor);
    paramGraphics.fillRect(0, 0, this.image.getWidth(this), this.image.getHeight(this));
    paramGraphics.setColor(Color.white);

    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0; int j = 0;

    for (int k = 0; k < paramString.length(); k++)
    {
      char c = paramString.charAt(k);

      if ((c == '#') && (j == 0))
      {
        if (i != 0)
        {
          paramGraphics.setColor(parseColorName(localStringBuffer.toString(), Color.white));
          localStringBuffer.setLength(0);
          i = 0;
        }
        else
        {
          i = 1;
        }
      }
      else if ((c == '
) && (i == 0) && (j == 0))
      {
        try
        {
          Image localImage = (Image)paramEnumeration.nextElement();
          paramGraphics.drawImage(localImage, this.scrollLength, 0, this);
          this.scrollLength += localImage.getWidth(this);
        }
        catch (Exception localException)
        {
        }
      }
      else if ((c == '/') && (j == 0))
      {
        j = 1;
      }
      else if (i != 0)
      {
        localStringBuffer.append(c);
      }
      else
      {
        if (j == 1) j = 0;
        paramGraphics.drawString(String.valueOf(c), this.scrollLength, paramFontMetrics.getAscent());
        this.scrollLength += paramFontMetrics.charWidth(c);
      }
    }
  }

  private Color parseColorName(String paramString, Color paramColor)
  {
    if ("red".equals(paramString)) return Color.red;
    if ("green".equals(paramString)) return Color.green;
    if ("blue".equals(paramString)) return Color.blue;
    if ("yellow".equals(paramString)) return Color.yellow;
    if ("orange".equals(paramString)) return Color.orange;
    if ("white".equals(paramString)) return Color.white;
    if ("lightGray".equals(paramString)) return Color.lightGray;
    if ("gray".equals(paramString)) return Color.gray;
    if ("darkGray".equals(paramString)) return Color.darkGray;
    if ("black".equals(paramString)) return Color.black;
    if ("cyan".equals(paramString)) return Color.cyan;
    if ("magenta".equals(paramString)) return Color.magenta;
    if ("pink".equals(paramString)) return Color.pink;
    return paramColor;
  }

  private Enumeration parseAndLoadImages(String paramString)
  {
    if (paramString == null) return null;

    int i = 0;
    Vector localVector = new Vector();
    StringTokenizer localStringTokenizer = new StringTokenizer(paramString);
    MediaTracker localMediaTracker = new MediaTracker(this);

    while (localStringTokenizer.hasMoreTokens())
    {
      try
      {
        Image localImage = getImage(new URL(getDocumentBase(), localStringTokenizer.nextToken()));
        localVector.addElement(localImage);
        localMediaTracker.addImage(localImage, i);
        localMediaTracker.waitForID(i++);
        this.imgsWidth += localImage.getWidth(this);
      }
      catch (Exception localException)
      {
      }
    }

    return localVector.elements();
  }

  public void start()
  {
    this.thread = new Thread(this);
    this.thread.start();
  }

  public void stop()
  {
    this.thread = null;
    this.scrolled = (-size().width);
  }

  public void run()
  {
    while (Thread.currentThread() == this.thread)
    {
      long l = System.currentTimeMillis();

      if (++this.scrolled > this.scrollLength) this.scrolled = (-size().width);

      repaint();
      try
      {
        Thread.sleep(Math.max(this.speed - (System.currentTimeMillis() - l), 0L));
      }
      catch (InterruptedException localInterruptedException)
      {
      }
    }
  }

  public boolean mouseEnter(Event paramEvent, int paramInt1, int paramInt2)
  {
    if (this.url != null) getAppletContext().showStatus("Link: " + this.url.toString());
    return true;
  }

  public boolean mouseExit(Event paramEvent, int paramInt1, int paramInt2)
  {
    if (this.url != null) getAppletContext().showStatus("");
    return true;
  }

  public boolean mouseUp(Event paramEvent, int paramInt1, int paramInt2)
  {
    if (this.url != null) getAppletContext().showDocument(this.url, this.target);
    return true;
  }

  public void update(Graphics paramGraphics)
  {
    paramGraphics.setColor(this.bgColor);
    if (this.scrolled < 0)
    {
      paramGraphics.setColor(this.bgColor);
      paramGraphics.fillRect(0, 0, -this.scrolled, size().height);
    }
    paramGraphics.drawImage(this.image, -this.scrolled, 0, this);
  }

  public void paint(Graphics paramGraphics)
  {
    update(paramGraphics);
  }

  public String getAppletInfo()
  {
    return "ProScroll version 2.3 by Slava Pestov";
  }
}

That is a class file meaning it is compiled code so you can not see it's source.
In order to see the source, you need the .java file which is the file which you compile to get the byte code.

It seems the site is just providing the compiled class, and you never know using it they might have some hidden functionality in the class as well e.g to send information to the owner servers etc.

EDIT:

So here is the de-compiled code of applet written by ProScroll version 2.3 by Slava Pestov

import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Enumeration;
import java.util.StringTokenizer;
import java.util.Vector;

public class ProScroll extends Applet
  implements Runnable
{
  private Thread thread;
  private Image image;
  private int scrollLength;
  private int scrolled;
  private int speed = 10;
  private int imgsWidth;
  private URL url;
  private String target;
  private Color bgColor;

  public void init()
  {
    int i = 12; int j = 0;

    String str2 = getParameter("TEXT");
    String str3 = getParameter("TEXTURL");

    if ((str2 == null) && (str3 == null)) {
      str2 = "No TEXT or TEXTURL parameter specified";
    }
    if (str3 != null)
    {
      localObject = new StringBuffer();
      try
      {
        InputStream localInputStream = new URL(str3)
          .openConnection().getInputStream();
        while (true)
        {
          int k = localInputStream.read();
          if (k == -1) break;
          if (k != 10) {
            if (k == 9) { ((StringBuffer)localObject).append(' '); continue; }
            ((StringBuffer)localObject).append((char)k);
          }
        }
        localInputStream.close();

        str2 = ((StringBuffer)localObject).toString();
      }
      catch (Exception localException1)
      {
        if (str2 == null) {
          str2 = "Error loading text from URL: " + localException1;
        }
      }
    }
    String str1 = getParameter("FONT");
    if (str1 == null) str1 = "TimesRoman";

    this.target = getParameter("TARGET");
    if (this.target == null) this.target = "_self";

    try
    {
      i = Integer.parseInt(getParameter("SIZE"));
    }
    catch (Exception localException2)
    {
    }

    Object localObject = getParameter("STYLE");
    if ("bold".equals(localObject)) j = 1;
    else if ("italic".equals(localObject)) j = 2;
    else if ("bolditalic".equals(localObject)) j = 3;

    String str4 = getParameter("SPEED");
    if ("slow".equals(str4)) this.speed = 20;
    else if ("medium".equals(str4)) this.speed = 15; else {
      this.speed = 10;
    }
    try
    {
      this.url = new URL(getDocumentBase(), getParameter("URL"));
    }
    catch (Exception localException3)
    {
    }

    this.bgColor = parseColorName(getParameter("BGCOLOR"), Color.black);

    Enumeration localEnumeration = parseAndLoadImages(getParameter("IMAGES"));

    Font localFont = new Font(str1, j, i);

    FontMetrics localFontMetrics = getToolkit().getFontMetrics(localFont);

    this.image = createImage(localFontMetrics.stringWidth(str2) + this.imgsWidth + size().width, size().height);

    this.scrolled = (-size().width);

    parseAndDrawText(this.image.getGraphics(), str2, localFontMetrics, localFont, localEnumeration);
  }

  private void parseAndDrawText(Graphics paramGraphics, String paramString, FontMetrics paramFontMetrics, Font paramFont, Enumeration paramEnumeration)
  {
    paramGraphics.setFont(paramFont);
    paramGraphics.setColor(this.bgColor);
    paramGraphics.fillRect(0, 0, this.image.getWidth(this), this.image.getHeight(this));
    paramGraphics.setColor(Color.white);

    StringBuffer localStringBuffer = new StringBuffer();
    int i = 0; int j = 0;

    for (int k = 0; k < paramString.length(); k++)
    {
      char c = paramString.charAt(k);

      if ((c == '#') && (j == 0))
      {
        if (i != 0)
        {
          paramGraphics.setColor(parseColorName(localStringBuffer.toString(), Color.white));
          localStringBuffer.setLength(0);
          i = 0;
        }
        else
        {
          i = 1;
        }
      }
      else if ((c == '
) && (i == 0) && (j == 0))
      {
        try
        {
          Image localImage = (Image)paramEnumeration.nextElement();
          paramGraphics.drawImage(localImage, this.scrollLength, 0, this);
          this.scrollLength += localImage.getWidth(this);
        }
        catch (Exception localException)
        {
        }
      }
      else if ((c == '/') && (j == 0))
      {
        j = 1;
      }
      else if (i != 0)
      {
        localStringBuffer.append(c);
      }
      else
      {
        if (j == 1) j = 0;
        paramGraphics.drawString(String.valueOf(c), this.scrollLength, paramFontMetrics.getAscent());
        this.scrollLength += paramFontMetrics.charWidth(c);
      }
    }
  }

  private Color parseColorName(String paramString, Color paramColor)
  {
    if ("red".equals(paramString)) return Color.red;
    if ("green".equals(paramString)) return Color.green;
    if ("blue".equals(paramString)) return Color.blue;
    if ("yellow".equals(paramString)) return Color.yellow;
    if ("orange".equals(paramString)) return Color.orange;
    if ("white".equals(paramString)) return Color.white;
    if ("lightGray".equals(paramString)) return Color.lightGray;
    if ("gray".equals(paramString)) return Color.gray;
    if ("darkGray".equals(paramString)) return Color.darkGray;
    if ("black".equals(paramString)) return Color.black;
    if ("cyan".equals(paramString)) return Color.cyan;
    if ("magenta".equals(paramString)) return Color.magenta;
    if ("pink".equals(paramString)) return Color.pink;
    return paramColor;
  }

  private Enumeration parseAndLoadImages(String paramString)
  {
    if (paramString == null) return null;

    int i = 0;
    Vector localVector = new Vector();
    StringTokenizer localStringTokenizer = new StringTokenizer(paramString);
    MediaTracker localMediaTracker = new MediaTracker(this);

    while (localStringTokenizer.hasMoreTokens())
    {
      try
      {
        Image localImage = getImage(new URL(getDocumentBase(), localStringTokenizer.nextToken()));
        localVector.addElement(localImage);
        localMediaTracker.addImage(localImage, i);
        localMediaTracker.waitForID(i++);
        this.imgsWidth += localImage.getWidth(this);
      }
      catch (Exception localException)
      {
      }
    }

    return localVector.elements();
  }

  public void start()
  {
    this.thread = new Thread(this);
    this.thread.start();
  }

  public void stop()
  {
    this.thread = null;
    this.scrolled = (-size().width);
  }

  public void run()
  {
    while (Thread.currentThread() == this.thread)
    {
      long l = System.currentTimeMillis();

      if (++this.scrolled > this.scrollLength) this.scrolled = (-size().width);

      repaint();
      try
      {
        Thread.sleep(Math.max(this.speed - (System.currentTimeMillis() - l), 0L));
      }
      catch (InterruptedException localInterruptedException)
      {
      }
    }
  }

  public boolean mouseEnter(Event paramEvent, int paramInt1, int paramInt2)
  {
    if (this.url != null) getAppletContext().showStatus("Link: " + this.url.toString());
    return true;
  }

  public boolean mouseExit(Event paramEvent, int paramInt1, int paramInt2)
  {
    if (this.url != null) getAppletContext().showStatus("");
    return true;
  }

  public boolean mouseUp(Event paramEvent, int paramInt1, int paramInt2)
  {
    if (this.url != null) getAppletContext().showDocument(this.url, this.target);
    return true;
  }

  public void update(Graphics paramGraphics)
  {
    paramGraphics.setColor(this.bgColor);
    if (this.scrolled < 0)
    {
      paramGraphics.setColor(this.bgColor);
      paramGraphics.fillRect(0, 0, -this.scrolled, size().height);
    }
    paramGraphics.drawImage(this.image, -this.scrolled, 0, this);
  }

  public void paint(Graphics paramGraphics)
  {
    update(paramGraphics);
  }

  public String getAppletInfo()
  {
    return "ProScroll version 2.3 by Slava Pestov";
  }
}
番薯 2025-01-02 01:55:46

java .class 文件是编译后的文件,无法使用记事本读取。

如果您想要源代码,您应该尝试向文章作者询问,否则您可以对其进行反编译。

a java .class file is a compiled file that you cannot read with notepad.

if you want the source code you should try to ask it to the author of the article or you could decompile it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文