Программирование на Java

       

Исходные тексты приложения


Главный файл исходных текстов приложения CDRotation представлен в листинге 1.

Листинг 1. Файл CDRotation.java

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

public class CDRotation extends Applet implements Runnable { Thread m_CDRotation = null; private Graphics m_Graphics; private Image m_Images[]; private int m_nCurrImage; private int m_nImgWidth = 0; private int m_nImgHeight = 0; private boolean m_fAllLoaded = false; private final int NUM_IMAGES = 11;

public String getAppletInfo() { return "Name: CDRotation"; }

private void displayImage(Graphics g) { if (!m_fAllLoaded) return;

g.drawImage(m_Images[m_nCurrImage], (size().width - m_nImgWidth) / 2, (size().height - m_nImgHeight) / 2, null);

g.drawString( (new Integer(m_nCurrImage)).toString(), (size().width - m_nImgWidth) /2, ((size().height - m_nImgHeight)/2)+ 10); }

public void paint(Graphics g) { Dimension dimAppWndDimension = size(); g.setColor(Color.white); g.fillRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1); g.setColor(Color.black); g.drawRect(0, 0, dimAppWndDimension.width - 1, dimAppWndDimension.height - 1);

if (m_fAllLoaded) { displayImage(g); }

else g.drawString("Please, wait...", 10, dimAppWndDimension.height / 2); }

public void start() { if (m_CDRotation == null) { m_CDRotation = new Thread(this); m_CDRotation.start(); } }

public void stop() { if (m_CDRotation != null) { m_CDRotation.stop(); m_CDRotation = null; } }

public void run() { m_nCurrImage = 0;

if (!m_fAllLoaded) { repaint(); m_Graphics = getGraphics();

m_Images = new Image[NUM_IMAGES];

MediaTracker tracker = new MediaTracker(this);

String strImage;

for (int i = 0; i < NUM_IMAGES; i++) { strImage = "images/cdimg0" + ((i < 10) ? "0" : "") + i + ".gif";

m_Images[i] = getImage( getDocumentBase(), strImage);

tracker.addImage(m_Images[i], 0); }

try { tracker.waitForAll();

m_fAllLoaded = !tracker.isErrorAny(); } catch (InterruptedException e) { }



Содержание раздела