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 3 of 3

Thread: New to applets

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post New to applets

    package appletPackage;
     
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.AbstractButton;
    import java.awt.event.*;
     
    public class MainClass extends JApplet {
    	private JButton button;
    	private String text = "Screenflashing";
    	public MainClass(){
     
    	}
    	public void init(){
    		button = new JButton(text);
    		add(button);
    	}
    	public void addActionListener(ActionListener button) {
    		button.actionPerformed(); // line erroring
    		text = "ScReEnFlAsHiNg";
    		repaint();
    	}
     
    }

    I think I've got a few things wrong, but I'm not exactly sure what to do; how do I make the addActionListener listen to my 'button' variable/buttonthing (so I can make stuff happen when the button's clicked... )?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,607
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: New to applets

    This has almost nothing to do with Applets, and more to do with general Swing. I'd suggest reading through the Swing tutorial (Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)), specifically this article: How to Write an Action Listener (The Java™ Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

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

    Default Re: New to applets

    Thank-you!

Similar Threads

  1. [SOLVED] applets in package
    By dabdi in forum Java Theory & Questions
    Replies: 5
    Last Post: June 14th, 2011, 09:04 PM
  2. Help With Applets
    By mukilan in forum AWT / Java Swing
    Replies: 12
    Last Post: February 2nd, 2011, 11:18 PM
  3. Applets progress bar not increasing
    By Edvinauskas in forum Java Servlet
    Replies: 8
    Last Post: November 22nd, 2010, 07:04 PM
  4. Applets
    By santiagomez in forum Java Theory & Questions
    Replies: 2
    Last Post: July 31st, 2010, 05:05 PM
  5. Help needed with applets
    By Brt93yoda in forum What's Wrong With My Code?
    Replies: 16
    Last Post: July 12th, 2010, 08:36 PM