Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: been many years since I programmed in java

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default been many years since I programmed in java

    as title says its been many years and i was looking back on some old code of mine and couldnt figure out why it didnt work. I hope someone can explain what is wrong and how to fix it

       import java.awt.*;
       import java.applet.*;
       import java.awt.event.*;
       import javax.swing.*;
       import java.util.*;
     
     
        public class FinalExam extends JApplet implements ActionListener { 
          JButton SwapButton ;
          JButton SwapOrigButton ;
     
          private Image party;
          private Image party2;
          private Image load;
     
          private AudioClip mcdClip;
     
          final int width = 150, height = 300;
     
           public void init() {
             party = getImage(getDocumentBase(), " Party.jpg ");
             party2 = getImage(getDocumentBase(), " Party2.jpg ");
             load = getImage(getDocumentBase(), " load.jpg ");
             mcdClip = getAudioClip(getCodeBase(), "indy.mid");
             setBackground(Color.blue);
     
          }
     
           public FinalExam()                           
          {
             SwapButton = new JButton("Swap New Image");
             SwapOrigButton = new JButton("Swap Old Image");
             SwapButton.setActionCommand( "swap" );
             SwapOrigButton.setActionCommand( "swap2" );  
     
             getContentPane().setLayout( new FlowLayout() ); 
            getContentPane().add( SwapButton );
             getContentPane().add( SwapOrigButton );                      
     
             SwapButton.addActionListener( this );
             SwapOrigButton.addActionListener( this );
             SwapButton.repaint();
             SwapOrigButton.repaint();
     
     
          }
     
     
     
           public void actionPerformed( ActionEvent evt )
          {
            Graphics g = getGraphics();
             if ( evt.getActionCommand().equals( "swap" ) ){
                g.drawImage(party2, 500, 0, this);
             }
             if ( evt.getActionCommand().equals( "swap2" ) ){
                g.drawImage(party, 500, 0, this);
             }     
          }
     
     
     
     
           public void paint(Graphics g){ 
             g.setFont(new Font("Rage Italic",Font.PLAIN,15));
             g.setColor(new Color(255, 255, 255 ));
             g.drawString("Dear Guest,", 50, 65);
             g.setFont(new Font("Serif",Font.PLAIN, 15)); 
             g.setColor(new Color(255, 255, 0 )); 
             g.drawString("   As you may or may not know I, Neal Cobert, am holding a 2 day", 70, 80);
             g.setFont(new Font("Serif",Font.BOLD, 15)); 
             g.setColor(new Color(255, 255, 0 )); 
             g.drawString("Anti-Prom Party...YAY!!!", 50, 100);
             g.setFont(new Font("Times New Roman",Font.PLAIN, 15)); 
             g.setColor(new Color(193, 255, 193 )); 
             g.drawString("   Now if you have been invited then you may come.", 70, 120);
             g.drawString("However if you did not recieve an invite from me personally than", 50, 135);
             g.setFont(new Font("Times New Roman",Font.ITALIC, 15)); 
             g.setColor(new Color(193, 255, 193 )); 
             g.drawString("you may not come. :D", 50, 150);
     
             g.setFont(new Font("Rockwell",Font.BOLD, 20)); 
             g.setColor(new Color(162, 205, 90)); 
             g.drawString("Who: ME!!!", 50, 200);
             g.drawString("What: ANTI-PROM PARTY!!!", 50, 220);
             g.drawString("Where: MY HOUSE :)", 50, 240);
             g.drawString("When: Prom Weekend", 50, 260);
             g.drawString("Why: Why Not", 50, 280);
     
             g.setColor(Color.black);
             g.fillRect(150,300,200,150);
            g.setColor(Color.lightGray);
             g.fillRect(160,310,180,130);
             g.setColor(Color.black);
             g.drawLine(300,300,400,210);
             g.drawLine(150,210,300,300);
     
             g.drawImage(party, 500, 0, this);
     
             g.drawString("Indiana Jones", 700, 400);
     
             int count =  0 ;
             while (  count < 10  )
             {
                int diameter = width/10;
     
                int X = count*diameter;           // the left edge of each square
                int Y = height/2 - diameter/2;    // the top edge of the squares
     
                g.drawImage(load, X, +4, diameter, diameter, this );
                count = count + 1; 
             }
     
          }
           public void Stop(){
             mcdClip.stop(); 
          }
           public void start() { 
             mcdClip.loop(); 
          }
       }


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: been many years since I programmed in java

    Well, what problems do you have? What errors do you get?

    Chris

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: been many years since I programmed in java

    I dont get any errors but it wont show me any pop up screen like it did when i made it years ago

  4. #4
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: been many years since I programmed in java

    How are you trying to run this?

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: been many years since I programmed in java

    i compile in the terminal by writing javac FinalExam.java then i run by typing java FinalExam

  6. #6
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: been many years since I programmed in java

    This is an Applet not a java program, you should be launching it in the web browser

Similar Threads

  1. Inserting pre programmed UI elements
    By luisp88 in forum AWT / Java Swing
    Replies: 2
    Last Post: September 20th, 2011, 12:56 PM