Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match_all(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 834

Warning: Invalid argument supplied for foreach() in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 835

Warning: preg_replace(): Compilation failed: group name must start with a non-digit at offset 4 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 839

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860

Warning: preg_match(): Compilation failed: group name must start with a non-digit at offset 8 in /home/e5m7uo8vro0d/public_html/mediawiki/includes/MagicWord.php on line 860
Hogwarts School Of Computer Science - Huben's Wiki

Hogwarts School Of Computer Science

From Huben's Wiki
Jump to: navigation, search
Line 17: Line 17:
  
 
==The Mystery Of The Curly Braces==
 
==The Mystery Of The Curly Braces==
 +
Banner.java
 +
<code>
 +
// This applet displays a message moving horizontally
 +
// across the screen.
 +
 +
import java.awt.*;
 +
import java.awt.event.*;
 +
import javax.swing.*;
 +
 +
public class Banner extends JApplet
 +
  implements ActionListener
 +
{
 +
  private int xPos, yPos;  // hold the coordinates of the banner
 +
 +
  public void init()
 +
  {
 +
    Container c = getContentPane();
 +
    c.setBackground(Color.WHITE);
 +
    xPos = c.getWidth();
 +
    yPos = c.getHeight() / 2;
 +
    Timer clock = new Timer(30, this);  // fires every 30 milliseconds
 +
    clock.start();
 +
  }
 +
 +
  // Called automatically after a repaint request
 +
  public void paint(Graphics g)
 +
  {
 +
    super.paint(g);
 +
    g.drawString("Hello, World!", xPos, yPos);
 +
  }
 +
 +
  // Called automatically when the timer fires
 +
  public void actionPerformed(ActionEvent e)
 +
  {
 +
    Container c = getContentPane();
 +
 +
    // Adjust the horizontal position of the banner:
 +
    xPos--;
 +
    if (xPos < -100)
 +
    {
 +
      xPos = c.getWidth();
 +
    }
 +
 +
    // Set the vertical position of the banner:
 +
    yPos = c.getHeight() / 2;
 +
 +
    repaint();
 +
  }
 +
}
 +
</code>

Revision as of 09:55, 10 September 2012

Personal tools
translate