Click here to Skip to main content
15,891,938 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
at puzzle game , how can i refresh the game
Java
refreshButton = new JButton( "Refresh" );
refreshButton.setBorder( BorderFactory.createRaisedBevelBorder() );
refreshButton.addActionListener( this );
// Add the button to the frame
getContentPane().add( refreshButton, BorderLayout.NORTH );


how that make refresh?
Posted
Updated 10-May-11 2:18am
v2

Add the button:
Java
refreshButton.setText("Refresh");


And then the listener is added thus:
Java
refreshButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        refreshButtonActionPerformed(evt);
    }
});


Then add the method refreshButtonActionPerformed:
Java
private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {

    // TODO add your handling code here

}
 
Share this answer
 
Comments
Marc A. Brown 10-May-11 9:21am    
That code looks familiar. Netbeans user? :) Seriously though, good answer. My 5.
Nagy Vilmos 10-May-11 10:57am    
That I find is the easiest way to ensure the syntax is correct.
hmmm - do you really think, he's asking for the ActionListener? That one is prompted by the IDE, that should not be the problem.

I think he's asking for the code in the ActionPerformed:

private void refreshButtonActionPerformed(java.awt.event.ActionEvent evt) {

    someJPanel.repaint();

}


so you basically need to repaint your surrounding Container. The method repaint()[^] is located in the general Component JComponent and available at most graphical stuff.

regards
Torsten
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900