Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-27-2008, 06:15 AM
Member
 
Join Date: May 2008
Posts: 1
justsomeguy is on a distinguished road
Java actionlistener help
I am making a Yahtzee game and i am having trouble getting the dice to change when i press my roll button. the dice are checkboxes so when they are selected, they can be "held".
For clarity's sake, ill just put the code for changing one of my dice from a one to a three. All my buttons and checkboxes show up just fine but when I click the buttons nothing happens.

Here are the relevant parts of my code:

private JButton roll;
private JCheckBox check;

in the constructor:
roll=new JButton("ROLL");
roll.setActionCommand("roll");
check=new JCheckBox();
Check1.setIcon(Dice1); //Dice1 is an ImageIcon

public void actionPerformed(ActionEvent e) {
if ("roll".equals(e.getActionCommand())
rollDice();}

public void rollDice(){
check.setIcon(Dice3);}

if all of the above is fine, then my problem is most likely with repainting. which leads to my other question...how would I get the screen to repaint itself after every time i press a button?

Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-27-2008, 06:42 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,104
hardwired is on a distinguished road
Code:
public void rollDice(){ check.setIcon(Dice3); // If the new icon is larger/smaller than the older // one you might need to ask for a new layout (but // likely not). You just have to try and see if you // need it. You do that with the JComponent method // revalidate or the Container method validate. check.revalidate(); // Often not needed. // Generally needed for this. check.repaint(); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Demonstrating the ActionListener Java Tip java.awt 0 04-23-2008 09:20 PM
How to use KeyListener and ActionListener Java Tip javax.swing 0 04-23-2008 09:19 PM
ActionListener interface tsantana New To Java 2 03-30-2008 11:24 PM
Implementing ActionListener interface JavaForums Java Blogs 0 12-19-2007 10:54 PM
addActionListener(java.awt.event.ActionListener) in java.awt.Button cannot be applied mathias Java Applets 1 08-06-2007 09:49 AM


All times are GMT +3. The time now is 12:17 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org