0

Good Evening all

I'm attempting to add multiple buttons to a frame on the press of a previous button so lets say I have a go button on a frame when I press that I want to be able to display a number of buttons that represent months while removing the Go button previously (I'd post an image but not enough reputation points).

I've tried putting them in a panel and making them visible as the panel becomes visible but that doesn't seem to work.

Once I've pressed the month button I then want a bunch of buttons to be shown that correspond to dates

Any clues as to how to do this

You may have guessed I'm fairly new to Java I haven't posted any code as I'd rather get a rough idea as to how this can be achieved then attempt to do it myself so to speak

Many Thanks

1
  • your question is not really well structured. Please provide more information. Here is to get you started with how-to write questions well: stackoverflow.com/help/how-to-ask Commented Dec 3, 2014 at 17:52

2 Answers 2

1

add all the buttons at the time of frame initialization. In the actionlistners of each but set the new buttons which you require as visible.

Sign up to request clarification or add additional context in comments.

Comments

0

That is how I did it initially, added buttons for go all of the months and the dates to the initial frame made all the buttons I didn't want to see invisible when the fram was first made then as I clicked a button made each individual button visible or not depending on what I wanted to show.

that seems a fairly inefficient way to go about it though for instance when I select the Month I have a line of code to such as

jButtonJan.setVisible(false);

so I have 12 of these

then I have

jButtonDay1.setVisible(true);

so I have upto 31 of these.

Isn't there a more efficient way of doing this a for loop maybe

I tried to set up a string variable that would increment the last number so

private String month = "jButtonMonth" + i;

Where i is determined by the for loop but

if I then try

month.setVisible(false);

I get an error ???

Ideas?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.