📄 javademo.java
字号:
//******************************************************************************
// JavaDemo.java: Applet
//
//******************************************************************************
import java.applet.*;
import java.awt.*;
import JavaDemoFrame;
import IDD_STOPDIALOG;
//==============================================================================
// Main Class for applet JavaDemo
//
//==============================================================================
public class JavaDemo extends Applet implements Runnable
{
// THREAD SUPPORT:
// m_JavaDemo is the Thread object for the applet
//--------------------------------------------------------------------------
private Thread m_JavaDemo1 = null;
private Thread m_JavaDemo2 = null;
private Thread m_JavaDemo3 = null;
private Thread m_JavaDemo4 = null;
// ANIMATION SUPPORT:
// m_Graphics used for storing the applet's Graphics context
// m_Images[] the array of Image objects for the animation
// m_nCurrImage the index of the next image to be displayed
// m_ImgWidth width of each image
// m_ImgHeight height of each image
// m_fAllLoaded indicates whether all images have been loaded
// NUM_IMAGES number of images used in the animation
//--------------------------------------------------------------------------
private Graphics m_Graphics;
public static 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 = 18;
// STANDALONE APPLICATION SUPPORT:
// m_fStandAlone will be set to true if applet is run standalone
//--------------------------------------------------------------------------
private boolean m_fStandAlone = false;
// STANDALONE APPLICATION SUPPORT
// The main() method acts as the applet's entry point when it is run
// as a standalone application. It is ignored if the applet is run from
// within an HTML page.
//--------------------------------------------------------------------------
// This Is My member Datas
private boolean stopFlag=true;
private IDD_STOPDIALOG stopDialog;
public static Color appletBackGround;
public static int frameRed;
public static int frameGreen;
public static int frameBlue;
public static void main(String args[])
{
// Create Toplevel Window to contain applet JavaDemo
//----------------------------------------------------------------------
JavaDemoFrame frame = new JavaDemoFrame("This Is Yang Main Frame Window");
// Must show Frame before we size it so insets() will return valid values
//----------------------------------------------------------------------
frame.show();
frame.hide();
int screenWidth=Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight=Toolkit.getDefaultToolkit().getScreenSize().height;
frame.resize(frame.insets().left + frame.insets().right + screenWidth/2,
frame.insets().top + frame.insets().bottom + screenHeight/2);
// The following code starts the applet running within the frame window.
// It also calls GetParameters() to retrieve parameter values from the
// command line, and sets m_fStandAlone to true to prevent init() from
// trying to get them from the HTML page.
//----------------------------------------------------------------------
JavaDemo applet_JavaDemo = new JavaDemo();
applet_JavaDemo.m_fStandAlone = true;
frame.add("Center", applet_JavaDemo);
applet_JavaDemo.init();
applet_JavaDemo.start();
frame.locate(screenWidth/2,screenHeight/2);
frame.show();
}
// JavaDemo Class Constructor
//--------------------------------------------------------------------------
public JavaDemo()
{
// TODO: Add constructor code here
}
// APPLET INFO SUPPORT:
// The getAppletInfo() method returns a string describing the applet's
// author, copyright date, or miscellaneous information.
//--------------------------------------------------------------------------
public String getAppletInfo()
{
return "Name: JavaDemo\r\n" +
"Author: wang\r\n" +
"Created with Microsoft Visual J++ Version 1.1";
}
// The init() method is called by the AWT when an applet is first loaded or
// reloaded. Override this method to perform whatever initialization your
// applet needs, such as initializing data structures, loading images or
// fonts, creating frame windows, setting the layout manager, or adding UI
// components.
//--------------------------------------------------------------------------
public void init()
{
// If you use a ResourceWizard-generated "control creator" class to
// arrange controls in your applet, you may want to call its
// CreateControls() method from within this method. Remove the following
// call to resize() before adding the call to CreateControls();
// CreateControls() does its own resizing.
//----------------------------------------------------------------------
//resize(320, 240);
// TODO: Place additional initialization code here
if(m_fStandAlone)
return;
String backGroundString=getParameter("BackGroundColor");
if(backGroundString!=null)
{
try
{
switch(Integer.parseInt(backGroundString))
{
// Color value :
// black=0,blue=1,cyan=2,darkGray=3,gray=4,green=5,lightGray=6,magenta=7
// orange=8 pink=9,red=10,white=11,yellow=12
case 0:
JavaDemo.appletBackGround=Color.black;
break;
case 1:
JavaDemo.appletBackGround=Color.blue;
break;
case 2:
JavaDemo.appletBackGround=Color.cyan;
break;
case 3:
JavaDemo.appletBackGround=Color.darkGray;
break;
case 4:
JavaDemo.appletBackGround=Color.gray;
break;
case 5:
JavaDemo.appletBackGround=Color.green;
break;
case 6:
JavaDemo.appletBackGround=Color.lightGray;
break;
case 7:
JavaDemo.appletBackGround=Color.magenta;
break;
case 8:
JavaDemo.appletBackGround=Color.orange;
break;
case 9:
JavaDemo.appletBackGround=Color.pink;
break;
case 10:
JavaDemo.appletBackGround=Color.red;
break;
case 11:
JavaDemo.appletBackGround=Color.white;
break;
case 12:
JavaDemo.appletBackGround=Color.yellow;
break;
default:
JavaDemo.appletBackGround=Color.green;
break;
}
}
catch(NumberFormatException e)
{
appletBackGround=Color.green;
}
}
setBackground(appletBackGround);
stopDialog=new IDD_STOPDIALOG(this);
stopDialog.CreateControls();
stopDialog.IDCSTOP.setFont(new Font("Times",Font.PLAIN,14));
setFont(new Font("Helvetica",Font.ITALIC,14));
}
// Place additional applet clean up code here. destroy() is called when
// when you applet is terminating and being unloaded.
//-------------------------------------------------------------------------
public void destory()
{
// TODO: Place applet cleanup code here
}
// ANIMATION SUPPORT:
// Draws the next image, if all images are currently loaded
//--------------------------------------------------------------------------
private void displayImage(Graphics g)
{
if (!m_fAllLoaded)
return;
// Draw Image in center of applet
//----------------------------------------------------------------------
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)/3,
(size().height -2*m_nImgHeight)/3, null);
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)*2/3+m_nImgWidth,
(size().height -2*m_nImgHeight)/3, null);
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)/3,
(size().height -2*m_nImgHeight)*2/3+m_nImgHeight, null);
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)*2/3+m_nImgWidth,
(size().height -2*m_nImgHeight)*2/3+m_nImgHeight, null);
if(Thread.currentThread()==m_JavaDemo1)
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)/3,
(size().height -2*m_nImgHeight)/3, null);
else if(Thread.currentThread()==m_JavaDemo2)
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)*2/3+m_nImgWidth,
(size().height -2*m_nImgHeight)/3, null);
else if(Thread.currentThread()==m_JavaDemo3)
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)/3,
(size().height -2*m_nImgHeight)*2/3+m_nImgHeight, null);
else if(Thread.currentThread()==m_JavaDemo4)
g.drawImage(JavaDemo.m_Images[m_nCurrImage],
(size().width - 2*m_nImgWidth)*2/3+m_nImgWidth,
(size().height -2*m_nImgHeight)*2/3+m_nImgHeight, null);
}
// JavaDemo Paint Handler
//--------------------------------------------------------------------------
public void paint(Graphics g)
{
// ANIMATION SUPPORT:
// The following code displays a status message until all the
// images are loaded. Then it calls displayImage to display the current
// image.
//----------------------------------------------------------------------
int stringX;
String displayString;
Dimension rectSize=size();
FontMetrics fm=getFontMetrics(getFont());
if (m_fAllLoaded)
{
// Rectangle r = g.getClipRect();
// g.clearRect(r.x, r.y, r.width, r.height);
displayImage(g);
//This is My Statement inserted
if(m_fStandAlone)
{
displayString="Hello World ! This Is Yang's Application";
}
else
{
displayString=getParameter("AppletString");
if(displayString==null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -