Win a copy of Rust Web Development this week in the Other Languages forum!

chanakya nani

Greenhorn
+ Follow
since Jan 11, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by chanakya nani

Matthew Brown wrote:So how do you expect an icon to be visible on the button, when you are explicitly setting that icon to null? What do you think the createImage() method is doing?




can you please tell me what should i do..??
10 years ago

Matthew Brown wrote:I may be missing something obvious...but in the code you've just posted, createImage returns null. Which would explain why you can't see any image - there isn't one to see. Is that the correct code?




yeah it is working fine...i can see the output, a chess board...and the code null is auto generated by eclipse when i tried to fix the bug
10 years ago

Paul Clapham wrote:It doesn't make sense to say "the" button because you have 64 buttons, not just one.

But let's suppose you aren't seeing an icon on any of those 64 buttons. (Your description isn't very clear so it could mean other things, but let's start with that as a first guess.) Then that would mean your createImage() method is returning something which can't be seen by you.

There are other possibilities, like for example perhaps you aren't calling pack() or setVisible(true) on the JFrame at the right time... in fact I see you call setVisible(true) before you add the buttons; that might be the problem too. It's better to use a standard set of code (see the Swing tutorial for an example of a simple Swing program) rather than throwing together code at random.






This is my code... i just created a chess board and i wanted to add the image of queen to the button...8 Queens problem....i did not write the loop yet..do you have any better ideas than looping the queens..??? please tell me
10 years ago

Matthew Brown wrote:So what's happening at the moment? Don't ask us to guess what the problem is. TellTheDetails.



sorry but the Image is not getting added to the button
10 years ago
Guys please help me in adding an image to the button..

10 years ago
Guys, I wanted to compare the text on the label and proceed furthur...can you please tell me how to do it...?

my code fragment is

10 years ago

Guys, My problem is that although i create a grid in a panel and add labels to it i cant see them when i run the program....i think it is being camouflaged,please tell me how to change the border colors of that grid in order to see it.


10 years ago

Paul Clapham wrote:Ah, I see. So your problem isn't really "accessing" the buttons. Your problem is that each button should be able to identify its neighbours, and should be able to identify the state (dead or alive) of those neighbours.

Or perhaps your design should be that the controller should be able to identify a button's neighbours, and should be able to identify the state of a button.

So which is your design? Is it the controller which will be doing the work, or the buttons themselves? I can't tell from your code; remember that designing should be done before coding.

More fundamentally: I don't understand why you have buttons at all. The Game Of Life doesn't involve a user interacting with the grid cells at all, as far as I can see.




Yeah,My design is that the controller should be able to identify the state of the button...how do i do that and what's wrong in my code..can you please tell me..?

hey,But how does the game work if user is not interacting...the question says that i should take input from the user..??
11 years ago

Paul Clapham wrote:If you want a 2-dimensional array of buttons, it wouldn't be hard to modify that code to produce one. But why do you want to "access" a button in a grid? What does it mean to "access" a button?




My idea is if i click the button it should check the conditions and display "live" or "dead"..
11 years ago

Paul Clapham wrote:If you want a 2-dimensional array of buttons, it wouldn't be hard to modify that code to produce one. But why do you want to "access" a button in a grid? What does it mean to "access" a button?




Actually the question i'm trying to do has conditions:


1. Game of Life is a one player game invented by John Conway. The game is played on a 8*8
two-dimensional grid of square cells. At any given time, a cell is either living or dead. Patterns of cells
transform themselves according to a simple set of rules:
• If a cell is living, it continues to live if surrounded by exactly two or three living cells. If it is
surrounded by more than three living cells, it dies of overcrowding; if less than two of its neighbors is
alive, it dies of loneliness.
• If a cell is dead, it becomes living only if it is surrounded by exactly three living cells.
Otherwise, it remains dead.
Simulate the game of Life program. Assume an initial configuration which can be specified by the
user and the program should start from that starting configuration.
11 years ago

Paul Clapham wrote:If you want a 2-dimensional array of buttons, it wouldn't be hard to modify that code to produce one. But why do you want to "access" a button in a grid? What does it mean to "access" a button?




i want each button to display some text when i click it...as i can't write ActionListener and Performed methods for each and everyone of the 64 buttons i need a loop to perform that....So i created a loop which creates all the 64 buttons and listeners...but when i run it i am getting the output, that is ,the text is printed only on the last button even if i click any button out of 64 ones...

once if you run the code you may understand perfectly what my problem is..
11 years ago
Guys,

My program is of a (8,8) grid..when i pressed a specific button i want it to be displayed the text on that button itself

I'm not getting the desired output

(Desired output: Display the text on the same button)


when i click the button, i am getting the display on the last square of the grid..
can you please help me...


My code is(where i think the problem is )





My full program for a quick reference is


11 years ago
Guys,
I 'm stuck in middle of the code....How do i access a particular button in a grid(8/8) as accessing an element in an array like


My entire code(or atleast upto what i have written) is below...for a quick reference



11 years ago

Jesper de Jong wrote:Do you already know how to add an action listener to a single button? If you know that, it's easy to do the same thing in a loop.

First of all, I'd split line 13 in two parts: creating the button and adding it to the frame, because you need a reference to the JButton object so that you can add an action listener to it:





Thank you very much....How could i miss that simple thing?..!!..I feel i am such a douche..
Thank you once again.
Ciao.
11 years ago
Here's my code...

I want to add Action Listeners to each and every button in the grid...Can you help me please..



11 years ago