Why won't this piece of code work?

Hello all, i am new to HTML and web design and i'm trying to make a website. I created this piece of code so that when the user mouses over one of the links (jpg image) it will change colors ( i have the same image in different color scheme saved in the same folder).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>XXXXXXXXXX</title>
</head>
<body bgcolor="#000000">
<table width="1050" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><table width="1050" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td><img src="_images/XXXXbanner.jpg" width="1050" height="311" alt="banner" /></td>
      </tr>
    </table>
      <table width="901" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td width="150"><a href="index.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ButtonOne','','_images/home_on.jpg',1)">
             <img name="ButtonOne" border="0" src="_images/home.jpg" width="150" height="75" alt="home" /></a></td>
          <td width="150"><a href="gallery.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ButtonTwo','','_images/gallery_on.jpg',1)">
              <img name="ButtonTwo" border="0" src="_images/gallery.jpg" width="150" height="75" alt="gallery" /></a></td>
          <td width="150"><a href="products.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ButtonThree','','_images/product_on.jpg',1)">
             <img name="ButtonThree" border="0" src="_images/product.jpg" width="150" height="75" alt="products" /></a></td>
          <td width="150"><a href="store.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ButtonFour','','_images/shop_on.jpg',1)">
             <img name="ButtonFour" border="0" src="_images/shop.jpg" width="150" height="75" alt="store" /></a></td>
          <td width="150"><a href="profile.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ButtonFive','','_images/profile_on.jpg',1)">
             <img name="ButtonFive" border="0" src="_images/profile.jpg" width="150" height="75" alt="profile" /></a></td>
          <td width="151"><a href="contactus.html" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ButtonSix','','_images/contact_us_on.jpg',1)">
          <img name="ButtonSix" border="0" src="_images/contact_us.jpg" width="150" height="75" alt="contact" /></a></td>
        </tr>
      </table>
      <table width="1050" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td> </td>
          <td> </td>
          <td> </td>
        </tr>
      </table>
      <p> </p>
    <p> </p></td>
  </tr>
</table>
</body>
</html>
the images and banner are showing up fine and i havent mistpyed any of the locations/file names. why doesn't the icon change colors (display the "on" image) when u hover the mouse over it? please help thanks in advance.
** i'm using Adobe Dreamweaver CS4

He's right...
try instering this into the head tags of your html
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
//-->
</script>

Similar Messages

  • Functions in a For Loop defining objects from an Array. . .Why Won't This Work?!

    I'm trying to put these functions into a Loop to conserve
    space. Why won't this work?
    .

    Yeah, sly one is right. You can not have the "i" inside the
    onRollOver function, what you have to do is: As the movieClip class
    is dynamic you can create a property of the movieClip which stores
    the value if the "i". And then, inside the onRollOver function, you
    have to make reference to that property.
    for (i=0; i<2; i++) {
    this.regArray
    .iterator = i;
    this.regArray.onRollOver = function () {
    showRegion(regArray[this.iterator]);
    this.regArray
    .onRollOut = function () {
    hideRegion(regArray[this.iterator]);

  • Why won't my mac internal microphone work?

    Why won't my mac internal microphone work?

    I just found and removed a small piece of sticky tape which was covering the mic. The mic is on the top surface of a mac - you can only just see a lighter coloured small round circle in line with the camera on the top narrow surface. My problem was sorted despite all other help and just before I gave up.  Check no-one has posted a sticky message, camera cover or even an ornament over your mic. How many folk know where the mic is?

  • Help...Why won't this compile?

    Why won't this compile?
    Here is my code:
    import java.util.Calendar;
    import javax.swing.JOptionPane;
    public class GetAge{
    public static void main(String[] args){
    int month=Integer.parseInt(JOptionPane.showInputDialog
    (null,"Enter what month(MM) you were born:"));
    int day=Integer.parseInt(JOptionPane.showInputDialog
    (null,"Enter what day(dd) you were born:"));
    int year=Integer.parseInt(JOptionPane.showInputDialog
    (null,"Enter what year(yyyy) you were born:"));
    Calendar rightNow = Calendar.getInstance();
    int year2 = rightNow.get(Calendar.YEAR);
    int day2 = rightNow.get(Calendar.DATE);
    int month2 = rightNow.get(Calendar.MONTH)+1;
    int years = year2-year-1;
    int months = month2-month+12;
    if(day2 >= day)
       int days = day2-day;
    else
       days = day-day2+8;
    JOptionPane.showMessageDialog(null,"You are: " + years
    + " years " + months + " months and " + days + " days old.");
    }

    What you're doing is using days after the if statement; without curly braces only a valid statement is allowed.
    But if you add curly braces, days will be available only in the if block.
    So what you should do is:
    import java.util.Calendar;
    import javax.swing.JOptionPane;
    public class GetAge{
    public static void main(String[] args){
    int month=Integer.parseInt(JOptionPane.showInputDialog
    (null,"Enter what month(MM) you were born:"));
    int day=Integer.parseInt(JOptionPane.showInputDialog
    (null,"Enter what day(dd) you were born:"));
    int year=Integer.parseInt(JOptionPane.showInputDialog
    (null,"Enter what year(yyyy) you were born:"));
    Calendar rightNow = Calendar.getInstance();
    int year2 = rightNow.get(Calendar.YEAR);
    int day2 = rightNow.get(Calendar.DATE);
    int month2 = rightNow.get(Calendar.MONTH)+1;
    int years = year2-year-1;
    int months = month2-month+12;
    int days = 0;      //declare here
    if(day2 >= day)
       days = day2-day;  //...and use here
    else
       days = day-day2+8;   //..and here
    JOptionPane.showMessageDialog(null,"You are: " + years
    + " years " + months + " months and " + days + " days old.");
    }

  • Why won't the Avatar Interactive Desktop work on Windows xp SP3

    As said in the title Why won't the Avatar Interactive Desktop work on Windows xp SP3. I have tried everything (uninstalling AIR, reinsalling it etc) I can think of but nothing makes it work. This image shows what I get in return every time I try to install the app. My PC meets all requirements to run Adobe AIR. Why is this occuring? I have the current version of AIR.  

    Hi oxide9999999999,
    For the moment, you have to install the version of AIR linked from their site: http://www.avatarmovie.com/desktop/index.html
    Hope this helps,
    Mirela

  • HT4145 why won't my old airport express work?

    why won't my old airport express work?

    Not sure what you mean by "won't work".
    Won't turn on at all?
    Won't allow configuration changes?
    What are you trying to do with the AirPort Express?
    If you could provide the Model No of the old Express.....look on the side of the Express for this.....it will be something like "A x x x x"
    and
    If you could provide the version of AirPort Utility that you are using.....open AirPort Utility, click on the AirPort Utility menu in the upper left corner of the screen, then click About AirPort Utility to locate the version number
    We can probably help

  • Why won't iTunes 10.6.3 work after installing Mountain Lion?

    Why won't iTunes 10.6.3 work after installing Mountain Lion?

    Instead of downloading from Apple updates on my computer, I went to apple.com, loaded it from there and the update worked fine. 

  • Why won't one of my speakers work on my iphone 4?

    why won't one of my speakers work on my iphone 4?

    Not strictly true - though I know what you mean.
    To be absolutely accurate - there is another one - you put your ear to when using the phone to make a call.
    Sorry its being pedantic - but I couldn't resist.

  • Why won't one of my games work ?

    Why won't one of my games work ?

    Try here:
    iOS: Troubleshooting applications purchased from the App Store
    That is all I can say since you did not say how they do not work. Do they freeze or what?

  • I purchased the new gen 7 ipod nano and needed to update itunes to 10.7 but my current software says its up to date and won't download 10.6.8 Currently I have 10.5.8 Why won't this update?

    I purchased the new gen 7 ipod nano and needed to update itunes to 10.7 but my current software says its up to date and won't download 10.6.8 Currently I have 10.5.8 Why won't this update?

    The first generation Intel-based Mac's were released in January 2006.
    Snow Leopard requires an Intel processor:
    General requirements
    Mac computer with an Intel processor
    1GB of memory
    5GB of available disk space
    DVD drive for installation
    Some features require a compatible Internet service provider; fees may apply.
    If you go to the Apple menu & "About this Mac" this will tell you what type of processor you have:

  • Why won't a Vivitar DVR camcorder work

    Why won't a  Vivitar DVR camcorder work with Imovies? Can someone please let me know.
    Thanks

    It would have speeded up a reply if you had bothered to mention what version of iMovie, on what Mac, running what version of OS X.
    iMovie 11 - cameras supported:
    http://help.apple.com/imovie/cameras/en/index.html?lang=en_US
    iMovie 9 - cameras supported:
    http://support.apple.com/kb/HT3290?viewlocale=en_US
    iMovie 8 Camcorders supported:
    http://support.apple.com/kb/HT1014
    Digital camera RAW formats supported by OS X Lion:
    http://support.apple.com/kb/HT4757?viewlocale=en_US
    Digital camera RAW formats supported by OS X Snow Leopard:
    http://support.apple.com/kb/HT3825?viewlocale=en_US

  • Why won't this song play even after I authorized the computer? It says that I need to authorize the computer, then I enter my username and password and it says the computer is already authorized. But then the song still won't play. What do I do?

    Why won't this song play even after I authorized the computer? It says that I need to authorize the computer, then I enter my username and password and it says the computer is already authorized. But then the song still won't play. What do I do?

    Use the Apple ID support -> http://www.apple.com/support/appleid/ - click through the contact information and select the iTunes, etc., hot button. You can have Apple call you or email them.
    Clinton

  • Why won't this code work?

    All I want to do is resize the select panel to the same size as east panel. Why won't it work?
    Space.java_____________________________________________
    import javax.sound.sampled.*;
    import java.awt.*;
    import javax.sound.midi.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import java.io.*;
    public class Space extends JFrame implements ActionListener, Runnable{
         //Sound
         Sequence currentSound;
         Sequencer player;
         Thread soundCheck;
         boolean check = true;
         public void start(){
              soundCheck = new Thread();
              soundCheck.start();
         public void run(){
              try{
                   File bgsound = new File("Sounds" + File.separator + "Space.mid");
                   currentSound = MidiSystem.getSequence(bgsound);
                   player = MidiSystem.getSequencer();
                   player.open();
                   player.setSequence(currentSound);
                   player.start();
                   checkSound();
              } catch (Exception exc){}
         public void checkSound(){
              while(check){
                   if(!player.isRunning()){
                     run();
                   try{
                        soundCheck.sleep((player.getMicrosecondLength() / 1000)-player.getMicrosecondPosition()); // sleep for the length of the track
                   }catch (InterruptedException IE){}
         //Screen Variables:
         Dimension SCREEN = Toolkit.getDefaultToolkit().getScreenSize();
         final int SCREENWIDTH = SCREEN.width;
         final int SCREENHEIGHT = SCREEN.height;
         //Panels:
         JPanel select, main, north, south, east;
        //Buttons:
         JButton instructB, cheatB, playB, exit, about;
         //Labels:
         JLabel open, cheat1, cheat2, cheatInstruct, i1, i2 , i3, aboutLabel;
         //The container and frame:
         static Space jframe;
         Container content;
         //The Constructor:
         public Space(){
              super("Space");
              //set  container attributes:
              content = getContentPane();
              content.setLayout(new BorderLayout());
              //init panels:
              main   = new JPanel();
              select = new JPanel();
              north  = new JPanel();
              east   = new JPanel();
              south  = new JPanel();
              //set panel attributes:
              select.setLayout(new GridLayout(3,0,10,10));     
              select.setBackground(Color.black);
              main.setBackground(Color.black);
              north.setBackground(Color.black);
              //add panels:
              content.add("West", select);
              content.add("Center", main);
              content.add("North", north);
              content.add("East", east);
              //Image Icons:
              Icon exit1 = new ImageIcon("Images" + File.separator + "exit1.gif");
              Icon exit2 = new ImageIcon("Images" + File.separator + "exit2.gif");
              Icon about1 = new ImageIcon("Images" + File.separator + "about1.gif");
              Icon about2 = new ImageIcon("Images" + File.separator + "about2.gif");
              //init buttons, add their listeners, and set their attributes:
              instructB = new JButton("Instructions", new ImageIcon("Images" + File.separator + "ship.gif"));
              instructB.setContentAreaFilled(false);
              instructB.setForeground(Color.yellow);
              instructB.addActionListener(this);
              select.add(instructB);
              cheatB = new JButton("Cheats", new ImageIcon("Images" + File.separator + "cheat.gif"));
              cheatB.setContentAreaFilled(false);
              cheatB.setForeground(Color.yellow);
              cheatB.addActionListener(this);
              select.add(cheatB);
              playB = new JButton("Play", new ImageIcon("Images" + File.separator + "ship2.gif"));
              playB.setContentAreaFilled(false);
              playB.setForeground(Color.yellow);
              playB.addActionListener(this);
              select.add(playB);          
              exit = new JButton();
              exit.setRolloverEnabled(true);
              exit.setIcon(exit1);
              exit.setRolloverIcon(exit2);
              exit.setBorderPainted(false);
              exit.setContentAreaFilled(false);
              exit.addActionListener(this);
              north.add(exit);
              about = new JButton();
              about.setRolloverEnabled(true);
              about.setIcon(about1);
              about.setRolloverIcon(about2);
              about.setBorderPainted(false);
              about.setContentAreaFilled(false);
              about.addActionListener(this);
             north.add(about);
             //Labels:
             open = new JLabel("", new ImageIcon("Images" + File.separator + "open.gif"), JLabel.CENTER);
              main.add(open);
              cheat1 = new JLabel("<html><h1>tport</h1></html>");
              cheat1.setForeground(Color.red);
              cheat2 = new JLabel("<html><h1>zap</h1></html>");
              cheat2.setForeground(Color.green);
              cheatInstruct = new JLabel("<html><h1>Type a cheat at any time during a game, and press the \"Enter\" key.</html></h1>");
              cheatInstruct.setForeground(Color.blue);     
              i1 = new JLabel("<html><h1>The arrow keys move your ship.</h1></html>");
              i1.setForeground(Color.red);
              i2 = new JLabel("<html><h1>The space-bar fires the gun.</h1></html>");
              i2.setForeground(Color.green);
              i3 = new JLabel("<html><h1>The red circles give upgrades.</html></h1>");
              i3.setForeground(Color.blue);
              aboutLabel    = new JLabel("", new ImageIcon("Images" + File.separator + "aboutImage.gif"), JLabel.CENTER);
              //centerPanel();     
         private void centerPanel(final int width, final int height){
              try{
                   Runnable setPanelSize = new Runnable(){
                        public void run(){
                             east.setPreferredSize(new Dimension(width, height));                    
                   SwingUtilities.invokeAndWait(setPanelSize);
              } catch (Exception e){}
         public void actionPerformed(ActionEvent e){
              //if the play button was pressed do:
              if(e.getSource() == playB){
                  //do something
             //else if the cheat button was pressed do:
              else if(e.getSource() == cheatB){
                   //remove and add components
                   main.removeAll();
                   main.setLayout(new GridLayout(3,0,0,0));
                   main.add(cheat1);
                   main.add(cheat2);
                   main.add(cheatInstruct);
                   main.repaint();
                   main.validate();          
              else if(e.getSource() == instructB){
                   //remove and add components
                   main.removeAll();
                   main.setLayout(new GridLayout(3,0,0,0));
                   main.add(i1);
                   main.add(i2);
                   main.add(i3);
                   main.repaint();
                   main.validate();          
              else if(e.getSource() == exit){
                   jframe.setVisible(false);
                   showCredits();          
              else if(e.getSource() == about){
                   main.removeAll();
                   main.setLayout(new FlowLayout());
                   main.add(aboutLabel);                         
                   main.repaint();
                   main.validate();
         public void showCredits(){
              try{
                   String[] args = {};
                   Credits.main(args);
              }catch (Exception e){}
         public static void main(String args[]){
              jframe = new Space();
              jframe.setUndecorated(true);
              jframe.setBounds(0, 0, jframe.SCREENWIDTH, jframe.SCREENHEIGHT);
              jframe.setVisible(true);
            jframe.show();     
            jframe.setResizable(false);
               jframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
             jframe.centerPanel(jframe.select.getWidth(), jframe.select.getHeight());
             jframe.run(); //start music

    The reason it wasn't working was because you were calling the method after you had set the frame visible, so you saw no change. On top of that, jframe.select.getWidth() only works after the frame is visible in this case. So it's best to set a fixed size for one of them, then use getWidth, or as I did... it's the same thing. I also changed the centerPanel method, I'm not sure if all that's exactly needed, but you can change it back if you think you'll need it.
    import javax.sound.sampled.*;
    import java.awt.*;
    import javax.sound.midi.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    import java.io.*;
    public class Space extends JFrame implements ActionListener, Runnable{
    //Sound
    Sequence currentSound;
    Sequencer player;
    Thread soundCheck;
    boolean check = true;
    public void start(){
    soundCheck = new Thread();
    soundCheck.start();
    public void run(){
    try{
    File bgsound = new File("Sounds" + File.separator + "Space.mid");
    currentSound = MidiSystem.getSequence(bgsound);
    player = MidiSystem.getSequencer();
    player.open();
    player.setSequence(currentSound);
    player.start();
    checkSound();
    } catch (Exception exc){}
    public void checkSound(){
    while(check){
    if(!player.isRunning()){
                run();
    try{
    soundCheck.sleep((player.getMicrosecondLength() / 1000)-player.getMicrosecondPosition()); // sleep for the length of the track
    }catch (InterruptedException IE){}
    //Screen Variables:
    Dimension SCREEN = Toolkit.getDefaultToolkit().getScreenSize();
    final int SCREENWIDTH = SCREEN.width;
    final int SCREENHEIGHT = SCREEN.height;
    //Panels:
    JPanel select, main, north, south, east;
        //Buttons:
    JButton instructB, cheatB, playB, exit, about;
    //Labels:
    JLabel open, cheat1, cheat2, cheatInstruct, i1, i2 , i3, aboutLabel;
    //The container and frame:
    static Space jframe;
    Container content;
    //The Constructor:
    public Space(){
    super("Space");
    //set  container attributes:
    content = getContentPane();
    content.setLayout(new BorderLayout());
    //init panels:
    main   = new JPanel();
    select = new JPanel();
    north  = new JPanel();
    east   = new JPanel();
    south  = new JPanel();
    //set panel attributes:
    select.setLayout(new GridLayout(3,0,10,10));
    select.setBackground(Color.black);
    main.setBackground(Color.black);
    north.setBackground(Color.black);
    //add panels:
    content.add("West", select);
    content.add("Center", main);
    content.add("North", north);
    content.add("East", east);
    //Image Icons:
    Icon exit1 = new ImageIcon("Images" + File.separator + "exit1.gif");
    Icon exit2 = new ImageIcon("Images" + File.separator + "exit2.gif");
    Icon about1 = new ImageIcon("Images" + File.separator + "about1.gif");
    Icon about2 = new ImageIcon("Images" + File.separator + "about2.gif");
    //init buttons, add their listeners, and set their attributes:
    instructB = new JButton("Instructions", new ImageIcon("Images" + File.separator + "ship.gif"));
    instructB.setContentAreaFilled(false);
    instructB.setForeground(Color.yellow);
    instructB.addActionListener(this);
    select.add(instructB);
    cheatB = new JButton("Cheats", new ImageIcon("Images" + File.separator + "cheat.gif"));
    cheatB.setContentAreaFilled(false);
    cheatB.setForeground(Color.yellow);
    cheatB.addActionListener(this);
    select.add(cheatB);
    playB = new JButton("Play", new ImageIcon("Images" + File.separator + "ship2.gif"));
    playB.setContentAreaFilled(false);
    playB.setForeground(Color.yellow);
    playB.addActionListener(this);
    select.add(playB);
    exit = new JButton();
    exit.setRolloverEnabled(true);
    exit.setIcon(exit1);
    exit.setRolloverIcon(exit2);
    exit.setBorderPainted(false);
    exit.setContentAreaFilled(false);
    exit.addActionListener(this);
    north.add(exit);
    about = new JButton();
    about.setRolloverEnabled(true);
    about.setIcon(about1);
    about.setRolloverIcon(about2);
    about.setBorderPainted(false);
    about.setContentAreaFilled(false);
    about.addActionListener(this);
        north.add(about);
        //Labels:
        open = new JLabel("", new ImageIcon("Images" + File.separator + "open.gif"), JLabel.CENTER);
    main.add(open);
    cheat1 = new JLabel("<html><h1>tport</h1></html>");
    cheat1.setForeground(Color.red);
    cheat2 = new JLabel("<html><h1>zap</h1></html>");
    cheat2.setForeground(Color.green);
    cheatInstruct = new JLabel("<html><h1>Type a cheat at any time during a game, and press the \"Enter\" key.</html></h1>");
    cheatInstruct.setForeground(Color.blue);
    i1 = new JLabel("<html><h1>The arrow keys move your ship.</h1></html>");
    i1.setForeground(Color.red);
    i2 = new JLabel("<html><h1>The space-bar fires the gun.</h1></html>");
    i2.setForeground(Color.green);
    i3 = new JLabel("<html><h1>The red circles give upgrades.</html></h1>");
    i3.setForeground(Color.blue);
    aboutLabel    = new JLabel("", new ImageIcon("Images" + File.separator + "aboutImage.gif"), JLabel.CENTER);
    east.setPreferredSize(new Dimension(125, SCREEN.width));
    //centerPanel();
    /*private void centerPanel(final int width, final int height){
    try{
    Runnable setPanelSize = new Runnable(){
    public void run(){
    east.setPreferredSize(new Dimension(width, height));
    SwingUtilities.invokeAndWait(setPanelSize);
    } catch (Exception e){}
    private void centerPanel(final int width, final int height)
         east.setPreferredSize(new Dimension(width, height));
    public void actionPerformed(ActionEvent e){
    //if the play button was pressed do:
    if(e.getSource() == playB){
        //do something
        //else if the cheat button was pressed do:
    else if(e.getSource() == cheatB){
    //remove and add components
    main.removeAll();
    main.setLayout(new GridLayout(3,0,0,0));
    main.add(cheat1);
    main.add(cheat2);
    main.add(cheatInstruct);
    main.repaint();
    main.validate();
    else if(e.getSource() == instructB){
    //remove and add components
    main.removeAll();
    main.setLayout(new GridLayout(3,0,0,0));
    main.add(i1);
    main.add(i2);
    main.add(i3);
    main.repaint();
    main.validate();
    else if(e.getSource() == exit){
    jframe.setVisible(false);
    //showCredits();
    else if(e.getSource() == about){
    main.removeAll();
    main.setLayout(new FlowLayout());
    main.add(aboutLabel);
    main.repaint();
    main.validate();
    /*public void showCredits(){
    try{
    String[] args = {};
    Credits.main(args);
    }catch (Exception e){}
    public static void main(String args[]){
    jframe = new Space();
    //jframe.centerPanel(500, jframe.select.getHeight());
    jframe.setUndecorated(true);
    jframe.setBounds(0, 0, jframe.SCREENWIDTH, jframe.SCREENHEIGHT);
    jframe.setVisible(true);
            jframe.show();
            jframe.setResizable(false);
          jframe.setDefaultCloseOperation(EXIT_ON_CLOSE);
        //jframe.centerPanel(jframe.select.getWidth(), jframe.select.getHeight());
        jframe.run(); //start music
    }Sorry I lost all the indenting :) I guess you can take a look at the few lines I changed and copy those lines.

  • I can't get this piece of code to work.

    Hello everybody!
    I am using AS2 and I am trying to make a simple 'game' for an assignment for school.
    I am first trying to make a simplified version of the game, to get some experience before I make the final version.
    I will try to explain this simplified version:
    The player has to drag an object in a big square and then release it. The object resamples 20 liter water. In total the player has to drag 100 liter water to the square, so it has to drag and drop the 'water' object 5 times.
    I want some text in screen that says: You still need ... liters of water.
    The ... is a dynamic text field with the name 'liters'.
    To help myself I made a counter that counts how many times the water is dragged and dropped.
    This is the code I placed in the 'water' movieclip:
    <code>
    onClipEvent(load)
    var countWater = 0;
    _root.createTextField("watercount",1,500,100,100,40); //this is the counter I was talking about
    _root.watercount.text = countWater;
    var literWater;
    on(press)
    startDrag(this);
    on(release)
    stopDrag();
    if(this._droptarget == "/watertarget"){ //watertarget is the box the waterobject has to be placed in
    this._x = 150;
    this._y = 300;
    countWater++;
    _root.watercount.text = countWater;
    literWater = (100 - (20 * countWater)); //I thought this should work. For example if countWater is 1, literWater schould be 100 - 20*1 = 80.
    _root.liters.text = literWater;
    } else
    this._x = 150;
    this._y = 300;
    </code>
    But this for some reason doesn't work. Before I drop the waterobject in the box, the text displayed is 'lev' and after I drop the waterobject, '0' is displayed, instead of 80.
    The counter does actually works well. It counts 0, 1, 2, 3, 4, 5, etc.
    So I figured there is probably something wrong in one of these 2 lines:
    literWater = (100 - (20 * countWater));
    _root.liters.text = literWater;
    Could someone please help me out with this? I would really appreciate it!
    By the way, I'm quitte new to AS, so it could be some newby mistake.
    Message was edited by: rickbreda1

    I would be most suspscious of your liters textfield not being named properly.  If I recreate what would support your code it works fine for me.
    Why don't you try creating it the same way do the watercount textfield just to see if it is working correctly.  I've been assuming there is only one water movieclip that you use over and over again.  If not, then you should get take the on(clipEvent) code off of it and just put that code in the timeline, less the on(clipEvent) part of it.
    Actually, placing any code on objects is not a good practice.  You should assign instance names to all your objects and then place the code in the timeline, using the instance names to target them.  If you give your "water" movieclip that name, your code in the timeline would end up looking like...
    var countWater = 0;
    _root.createTextField("watercount",1,500,100,100,40);
    _root.watercount.text = countWater;
    var literWater;
    water.onPress = function(){
        startDrag(this);
    water.onRelease = function(){
       stopDrag();
       if(this._droptarget == "/watertarget"){
            countWater++;
            _root.watercount.text = countWater;
           literWater = (100 - (20 * countWater));_root.liters.text = literWater;
       this._x = 150; // no need to have an else if it only does part of what the if does
       this._y = 300;
    As far as placing code into posts goes,  I usually just paste it (Ctrl-v) and then do what I can to make it look properly indented.  Others will use the >> tool offered in the editing interface to enter an area for code.  As far as having tags for code, I don't think that is supported any longer.

  • Why won't this Applet work? Any help?

    I followed a tutorial, though the tutorial left me to do a lot of the work. Which is good.
    Anyway, I finished the Applet, but I get a message in the bottom corner of the window saying "Applet not initialized."
    I can't figure out what's wrong.
    I downloaded the tutorial's source code and checked it, and I think I have everything they do... I tried running the downloaded source code and it worked fine.
    Here's the main class file of my Applet:
    import java.applet.*;
    import java.awt.*;
    import java.net.*;
    public class Main2 extends Applet implements Runnable
              AudioClip ballLost = getAudioClip(getCodeBase(), "beep_1.au");
              AudioClip bounce = getAudioClip(getCodeBase(), "beep_2.au");
              Player player = new Player();
              Ball ball1 = new Ball(20, this.getSize().width+40, this.getSize().height-30,1,3,8,ballLost,bounce,player,Color.red);
              Ball ball2 = new Ball(20, this.getSize().width+40, 30,1,5,10,ballLost,bounce,player,Color.blue);
              Thread th;
              Cursor c;
              Image dbImage;
              Graphics dbg;
         boolean isStopped = true;
         public void init()
              c = new Cursor(Cursor.CROSSHAIR_CURSOR);
              this.setCursor(c);
              ballLost = getAudioClip(getCodeBase(), "beep_1.au");
              bounce = getAudioClip(getCodeBase(), "beep_2.au");
              player = new Player();
              ball1 = new Ball(20, this.getSize().width+40, this.getSize().height-30,1,3,8,ballLost,bounce,player,Color.red);
              ball2 = new Ball(20, this.getSize().width+40, 30,1,5,10,ballLost,bounce,player,Color.blue);
         public void start()
              th = new Thread(this);
              th.start();
         public void stop()
              th.stop();
         public void run()
              Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
              while (true)
                   if (player.getLives()>0 && !isStopped)
                        ball1.move();
                        ball2.move();
                   repaint();
                   try
                        Thread.sleep (30);
                   catch (InterruptedException ex)
                        // do nothing
                   Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
         public void paint(Graphics g)
              if (player.getLives()>0)
                   ball1.drawBall(g);
                   ball2.drawBall(g);
                   if (isStopped)
                        g.setColor(Color.green);
                        g.drawString("Double click to start.", 40, 200);
              else if (player.getLives() <= 0)
                   g.setColor(Color.green);
                   g.drawString("Game Over!", 40, 200);
                   g.drawString("Double click to player again", 40, 300);
                   isStopped = true;
         public boolean mouseDown(Event e, int x, int y)
              if (!isStopped)
                   if (ball1.userHit(x,y))
                        //Need audio
                        ball1.ballWasHit();
                   else if (ball2.userHit(x,y))
                        //Need audio
                        ball2.ballWasHit();
                   else
                        //Play normal shot audio
              else if (isStopped && e.clickCount == 2)
                   isStopped = false;
                   init();
              return true;
         public void update (Graphics g)
              if (dbImage == null)
                   dbImage = createImage (this.getSize().width, this.getSize().height);
                   dbg = dbImage.getGraphics ();
              dbg.setColor (getBackground ());
              dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
              dbg.setColor (getForeground());
              paint (dbg);
              g.drawImage (dbImage, 0, 0, this);
    }My HTML code uses <APPLET CODE="Main2.class" WIDTH=700 HEIGHT=400>.
    And they are both located in the same folder.
    Any idea what's going wrong here?
    Thanks for any help.

    All of the files are in the folder.
    My folder contains:
    Main2.class
    Ball.class
    Player.class
    ShooterGame.html
    beep_1.au
    beep_2.au
    And corresponding source code files.
    Looks correct, right?
    ...

Maybe you are looking for

  • Extend Sales area data of a BP via copy

    Hi, Is there any functionality in SAP CRM 2007 to extend the Sales area data for a BP via copying. Example: BP 'A' has been created for Sales area 'AB' and the relevant fields have been populated. Later on the BP 'A' needs to be extended to Sales are

  • Problem with generating adhoc query..

    Hi experts, I am trying to generate Adhoc querry on Previous employer list along with Employee Id. I completed  till  process of generation of  Infoset. The system has generated a Message saying "Infoset------- generated. In sq02 there is a button wi

  • When I change pages it takes for ever to load, but if I move my mouse around it loads fast

    Fire Fox has been acting weird lately. Every time I change to a new page, it just sits there, does not change some times for as long a a minute or two. The Indicator in the Tab shows no motion. If I move the mouse around in the windows it will open a

  • Backup strategy

    Hi, short story: Due to the structure of the library I have the "originals" and "modified" images, when edited some. When importing a library into another without copying them I have some/many thumbnails twice. How do I prevent iPhoto to use the orig

  • Best to pay off credit card all at once or slowly over time?

    My urrent FICO score is ~730.  I just received a bonus and I want to pay off my sole (CitiBank) credit card with a significant balance.  Should I pay it off all at once or would it be better to pay it off slowly over an extended period?