Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Java, JButton buttons yes and no, start loop
Closed Thread
Old 10-20-2005, 05:47 PM   #1 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 198

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default Java, JButton buttons yes and no, start loop

ok..so i had to write a program, a gama called pig...ect,
so far ive encountered 2 problems, one of them being working with buttons

i need to have 2 buttons, before every roll of the dice, user has to specify if he wants to roll, or not. (using buttons 'yes' and 'no')

how would i go about making yes button start the loop(in which the dice are rolled)

another question. after rolling dice, and counting points together, and storing them in a variable, lets say,.... userPoints. i need to be able to access userPoints from a different class (class is called user), how do i do that?

user class is only used for outputting users points.

HELP
ibexpiotr is offline  
Old 10-20-2005, 05:59 PM   #2 (permalink)
 
Newb Techie

Join Date: Aug 2005

Posts: 9

Generic

Default

You go to the frame that the button is in (if you are using an applet you can do this in init) and use the addActionListener method. If your button is called yesButton, and you're using an applet, you would write
this.addActionListener(yesButton);
in the init() method. To do this you will have to implement the ActionListener interface and implement a method called void actionPerformed (actionEvent e). Then in that method you do e.getSource() and find out if the source is yesButton or noButton, and depending on which it is you do different things.

You could pass user the variable userPoints as an argument to some function in the class user.
Generic is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On