📄 javademo.java
字号:
displayString="世界,您好! 我的 Friend !";
}
stringX=(rectSize.width-fm.stringWidth(displayString))/2;
g.drawString(displayString,stringX,20);
}
else
g.drawString("Loading Applet A images...", 10, 20);
// TODO: Place additional applet Paint code here
Color foreGround=getForeground();
g.setColor(Color.red);
g.draw3DRect(0,0,rectSize.width-1,rectSize.height-1,true);
g.draw3DRect(3,3,rectSize.width-7,rectSize.height-7,false);
g.setColor(foreGround);
setBackground(appletBackGround);
}
// The start() method is called when the page containing the applet
// first appears on the screen. The AppletWizard's initial implementation
// of this method starts execution of the applet's thread.
//--------------------------------------------------------------------------
public void start()
{
if (m_JavaDemo1 == null)
{
m_JavaDemo1 = new Thread(this);
m_JavaDemo1.start();
}
// TODO: Place additional applet start code here
if (m_JavaDemo2 == null)
{
m_JavaDemo2 = new Thread(this);
m_JavaDemo2.start();
}
if (m_JavaDemo3 == null)
{
m_JavaDemo3 = new Thread(this);
m_JavaDemo3.start();
}
if (m_JavaDemo4 == null)
{
m_JavaDemo4 = new Thread(this);
m_JavaDemo4.start();
}
}
// The stop() method is called when the page containing the applet is
// no longer on the screen. The AppletWizard's initial implementation of
// this method stops execution of the applet's thread.
//--------------------------------------------------------------------------
public void stop()
{
if (m_JavaDemo1 != null)
{
m_JavaDemo1.stop();
m_JavaDemo1 = null;
}
// TODO: Place additional applet stop code here
if (m_JavaDemo2 != null)
{
m_JavaDemo2.stop();
m_JavaDemo2 = null;
}
if (m_JavaDemo3 != null)
{
m_JavaDemo3.stop();
m_JavaDemo3 = null;
}
if (m_JavaDemo4 != null)
{
m_JavaDemo4.stop();
m_JavaDemo4 = null;
}
}
// THREAD SUPPORT
// The run() method is called when the applet's thread is started. If
// your applet performs any ongoing activities without waiting for user
// input, the code for implementing that behavior typically goes here. For
// example, for an applet that performs animation, the run() method controls
// the display of images.
//--------------------------------------------------------------------------
public void run()
{
m_nCurrImage = 0;
// If re-entering the page, then the images have already been loaded.
// m_fAllLoaded == TRUE.
//----------------------------------------------------------------------
if (!m_fAllLoaded)
{
repaint();
m_Graphics = getGraphics();
JavaDemo.m_Images = new Image[NUM_IMAGES];
// Load in all the images
//------------------------------------------------------------------
MediaTracker tracker = new MediaTracker(this);
String strImage;
// For each image in the animation, this method first constructs a
// string containing the path to the image file; then it begins
// loading the image into the m_Images array. Note that the call to
// getImage will return before the image is completely loaded.
//------------------------------------------------------------------
for (int i = 1; i <= NUM_IMAGES; i++)
{
// Build path to next image
//--------------------------------------------------------------
strImage = "images\\img00" + ((i < 10) ? "0" : "") + i + ".gif";
if(!m_fStandAlone)
showStatus("Applet Is Loading Image File:"+System.getProperty("user.dir")+"\\"+strImage);
if (m_fStandAlone)
JavaDemo.m_Images[i-1] =Toolkit.getDefaultToolkit().getImage(strImage);
else
JavaDemo.m_Images[i-1] = getImage(getDocumentBase(), strImage);
tracker.addImage(JavaDemo.m_Images[i-1], 0);
}
// Wait until all images are fully loaded
//------------------------------------------------------------------
try
{
tracker.waitForAll();
m_fAllLoaded = !tracker.isErrorAny();
}
catch (InterruptedException e)
{
// TODO: Place exception-handling code here in case an
// InterruptedException is thrown by Thread.sleep(),
// meaning that another thread has interrupted this one
}
if (!m_fAllLoaded)
{
stop();
m_Graphics.drawString("Error loading images!", 10, 40);
return;
}
// Assuming all images are same width and height.
//--------------------------------------------------------------
m_nImgWidth = JavaDemo.m_Images[0].getWidth(this);
m_nImgHeight = JavaDemo.m_Images[0].getHeight(this);
}
if(!m_fStandAlone)
showStatus("Now Applet's Image File Is Loaded Completely");
repaint();
while (true)
{
try
{
// Draw next image in animation
//--------------------------------------------------------------
displayImage(m_Graphics);
m_nCurrImage++;
if (m_nCurrImage == NUM_IMAGES)
m_nCurrImage = 0;
// TODO: Add additional thread-specific code here
Thread.sleep(50);
}
catch (InterruptedException e)
{
// TODO: Place exception-handling code here in case an
// InterruptedException is thrown by Thread.sleep(),
// meaning that another thread has interrupted this one
stop();
}
}
}
public boolean action(Event event,Object obj)
{
String displayString;
if(event.target==stopDialog.IDCSTOP)
{
stopDialog.IDCSTOP.setFont(new Font("Helvetica",Font.PLAIN,14));
if(stopFlag)
{
stop();
stopFlag=false;
displayString="Click Here,Start The World !";
}
else
{
start();
stopFlag=true;
displayString="Click Here,Stop The World !";
}
stopDialog.IDCSTOP.setLabel(displayString);
if(!m_fStandAlone)
{
Applet receiveApplet=
getAppletContext().getApplet(getParameter("Receive"));
((JavaApplet)receiveApplet).processRequestFrom(displayString);
}
}
return false;
}
// MOUSE SUPPORT:
// The mouseDown() method is called if the mouse button is pressed
// while the mouse cursor is over the applet's portion of the screen.
//--------------------------------------------------------------------------
public boolean mouseDown(Event evt, int x, int y)
{
// TODO: Place applet mouseDown code here
return true;
}
// MOUSE SUPPORT:
// The mouseUp() method is called if the mouse button is released
// while the mouse cursor is over the applet's portion of the screen.
//--------------------------------------------------------------------------
public boolean mouseUp(Event evt, int x, int y)
{
// TODO: Place applet mouseUp code here
return true;
}
// MOUSE SUPPORT:
// The mouseDrag() method is called if the mouse cursor moves over the
// applet's portion of the screen while the mouse button is being held down.
//--------------------------------------------------------------------------
public boolean mouseDrag(Event evt, int x, int y)
{
// TODO: Place applet mouseDrag code here
return true;
}
// MOUSE SUPPORT:
// The mouseMove() method is called if the mouse cursor moves over the
// applet's portion of the screen and the mouse button isn't being held down.
//--------------------------------------------------------------------------
public boolean mouseMove(Event evt, int x, int y)
{
// TODO: Place applet mouseMove code here
return true;
}
// MOUSE SUPPORT:
// The mouseEnter() method is called if the mouse cursor enters the
// applet's portion of the screen.
//--------------------------------------------------------------------------
public boolean mouseEnter(Event evt, int x, int y)
{
// TODO: Place applet mouseEnter code here
return true;
}
// MOUSE SUPPORT:
// The mouseExit() method is called if the mouse cursor leaves the
// applet's portion of the screen.
//--------------------------------------------------------------------------
public boolean mouseExit(Event evt, int x, int y)
{
// TODO: Place applet mouseExit code here
return true;
}
// TODO: Place additional applet code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -