posted 8 years ago
Hello, I have this window where I want to add a logout icon on the top right corner. And also I have tried adding a background image through many ways but it won't even appear. I have tried adding the logout icon like this: 1st Method 2nd Method None of them worked.. Here is my code: Thanks for any help! Screenshot-(242).png .png) This is where the logout icon us to be placed Screenshot-(241).png .png) This is where the icon is being positioned when I tried I'm sure that this question has been asked before, but none of the answers I have found so far have matched exactly what I am looking for. I am making a simple tic-tac-toe game, and I want to be able to set the icon of a button when it is clicked, but what the icon is depends on what the player's piece is. For instance, if the player is "X," then it will make the button have an "X." Most solutions I have found involve using setPressedIcon() and then adding the button to the panel with that information, but I cannot set the pressed icon until after the buttons have already been created and added to the board. Also, the computer must be able to change the icon of a button to the opposing letter. Can anyone help me find a way to do this? posted 11 years ago
Use: to set the icon on the bases of your icon clicked, Add a mouseListener to the JLabel of your icon, in the actionPreformed, change the icon image. If not clear, let me know. Ranch Hand Posts: 250 posted 11 years ago
And as for picking what icon to use, have a boolean state variable called turn. One player's turn is true and one player's turn is false. Whenever a button is clicked and it is given an icon, change the turn: turn = !turn; rohan sethi Ranch Hand Posts: 34 posted 11 years ago
So? what problem you are facing?When you change the turn, change the icon. posted 11 years ago
- use JToggleButton instead of JButton - maybe ther is everything that you needed for tic-tac-toe game Joel Christophel Ranch Hand Posts: 250 posted 11 years ago
This is quite superfluous. Leonard Connoway Greenhorn Posts: 21 posted 11 years ago
I am trying to do this, but I keep getting the error that non-static method getClass() cannot be referenced from a static context even though I do not have it set as static. Joel Christophel Ranch Hand Posts: 250 posted 11 years ago
The getClass() method just returns your class, so you can replace it with YourClassName.class.getResource(). Leonard Connoway Greenhorn Posts: 21 posted 11 years ago
This is my current statement. and I have imported but, I am now getting the error "cannot find symbol - method getResource(java.lang.String)" Joel Christophel Ranch Hand Posts: 250 posted 11 years ago
Look closely at what I wrote and what you wrote. You're missing something very important! Leonard Connoway Greenhorn Posts: 21 posted 11 years ago
Haha I'm just not seeing it. I even tried copying/pasting exactly what you typed and it still said it cannot find the getResource method How to add icon to Java program?Creating an Icon for Your Java Application on Windows. Right-click on your . bat file or executable JAR file. Select Create Shortcut.. Select Properties.. Click Change Icon….. How to set position of button in Java?Example 1:. import java.awt.*;. public class ButtonExample {. public static void main (String[] args) {. // create instance of frame with the label.. Frame f = new Frame("Button Example");. // create instance of button with label.. Button b = new Button("Click Here");. // set the position for the button in frame.. |