Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Zyril

Thread: add button

  1. #1
    laxtrappa is offline Member
    Join Date
    Mar 2012
    Posts
    13
    Rep Power
    0

    Default add button

    a seemingly simple thing i can't get to work, and can't figure out why:

    Java Code:
    import java.applet.Applet;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    
    public class Test extends Applet implements ActionListener {
    	
    	private Integer cnt = 0;
    	
    	public void init() {
    		newButton();
    	}
    	
    	private void newButton () {
    		cnt++;
    
    		JButton testButton = new JButton(cnt.toString());
    		add(testButton);
    		testButton.addActionListener(this);
    
    		System.out.println(cnt);
    
                    repaint();
    	}
    
    	@Override
    	public void actionPerformed(ActionEvent arg0) {
    		newButton();
    	}
    }

  2. #2
    Zyril is offline Senior Member
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    124
    Rep Power
    0

    Default Re: add button

    What are you trying to achieve? Please explain a bit further what your problem is.
    Fubarable likes this.

Similar Threads

  1. Replies: 7
    Last Post: 08-06-2011, 03:39 AM
  2. Make a button class that uses your button image.
    By eLancaster in forum New To Java
    Replies: 1
    Last Post: 04-26-2011, 11:32 AM
  3. Adding a sqrt button and percentage button to a calculator
    By Josie_Taylor in forum New To Java
    Replies: 4
    Last Post: 03-14-2011, 01:16 AM
  4. Using SWT Button
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-08-2008, 09:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •