Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Apllet button problem

Options
  • 31-03-2006 1:51pm
    #1
    Registered Users Posts: 7,869 ✭✭✭


    im new to java and im wondering if someone could just quickly show me how i can have me button on the applet to perform an event when i click it. i'm having no luck with the EventHandler sample code off the net.

    the way im doing it is i create the button like:

    button play;
    play=new button("play");
    this.add(play);

    i then put in
    play.addActionListener(this);
    but it told me it couldn't put it in my applet!

    also, there is a
    public boolean event(Event event, Object arg)
    thing there too.

    any help?
    thanks


Comments

  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    what is "this". What does it extend/implement? (your class I mean)


  • Registered Users Posts: 7,869 ✭✭✭The_B_Man


    see im not sure. its in the init() class so i tihnk its that.


  • Registered Users Posts: 527 ✭✭✭Sean^DCT4


    you're prob better just posting the whole lot of what you have coded so far and what you are having trouble with.


  • Registered Users Posts: 7,869 ✭✭✭The_B_Man


    this is the init() functin at the start. im not sure if all this stuff is meant to go in here or not so...
            public void init()
    		{
    		// method typically for initializing fields, creating GUI components,
    		//  loading sounds to play, loading images to display & creating threads
    
    
                    Button play_button;
                    Button Card1_button;
                    Button Card2_button;
                    Button Bet_button;
                    Button Check_button;
                    Button Fold_button;
                    Choice Bets;
                    
                    JButton play_game;
    
    	
    	   // add buttons here
    	   play_button = new Button("Play");
    	   play_button.setForeground(Color.black);
    	   play_button.setBackground(Color.lightGray);
    	   this.add(play_button);
                    play_button.addActionListener(this);
    
                    Card1_button = new Button("Card1");
                    Card1_button.setForeground(Color.black);
                    Card1_button.setBackground(Color.lightGray);
                    this.add(Card1_button);
    
                    Card2_button = new Button("Card2");
                    Card2_button.setForeground(Color.black);
                    Card2_button.setBackground(Color.lightGray);
                    this.add(Card2_button);
    
                    Bet_button = new Button("Bet");
                    Bet_button.setForeground(Color.black);
                    Bet_button.setBackground(Color.lightGray);
                    this.add(Bet_button);
    
                    Check_button = new Button("Check");
                    Check_button.setForeground(Color.black);
                    Check_button.setBackground(Color.lightGray);
                    this.add(Check_button);
    
                    Fold_button = new Button("Fold");
                    Fold_button.setForeground(Color.black);
                    Fold_button.setBackground(Color.lightGray);
                    this.add(Fold_button);
    
    	   Bets = new Choice();
    	   Bets.addItem("5");
    	   this.add(new Label("Bet: "));
    } // end init()
    


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Whats the first part of your Class file. Something like..


    class myClass extends something implements somethingElse


  • Advertisement
  • Registered Users Posts: 7,869 ✭✭✭The_B_Man


    originally "extends Applet" but then changed it to "extends Applet implements ActionListener"


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    You have a method called actionPerformed(ActionEvent e) set up in your class as well?


Advertisement