This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
jPanel1.add(blankSpace); jLabel1.setText("This is an example of a wizard dialog, which allows a user to traverse"); jPanel1.add(jLabel1); jLabel2.setText("a number of panels (while entering data) until the wizard has enough "); jPanel1.add(jLabel2); jLabel3.setText("information to perform whatever end function is necessary. Note that"); jPanel1.add(jLabel3); jLabel4.setText("panels are not necessarily ordered in a linear fashion, but instead in"); jPanel1.add(jLabel4); jLabel5.setText("a tree-like manner (e.g., there may be more than one panel with a"); jPanel1.add(jLabel5); jLabel7.setText("'Finish' button, and it depends on the user's entries as to how they "); jPanel1.add(jLabel7); jLabel6.setText("traverse the path). That's not the case with this example, however."); jPanel1.add(jLabel6); jPanel1.add(jLabel8); jLabel9.setText("Press the 'Next' button to continue...."); jPanel1.add(jLabel9); jLabel10.setText("Enter the domain name"); jPanel1.add(jLabel10); jPanel1.add(tdomain); jLabel11.setText("Enter the server name"); jPanel1.add(jLabel11); jPanel1.add(tserver);
That is one way to do it. I had a long discussion with somebody on another forum last week, which I hope you will find on this thread, on java(intermediate) about implementing mvc model or observer. There are about three possible ways to implement ActionListeners, and I personally think getting the enclosing JFrame to implement it is an inelegant solution to the problem, although other people will doubtless disagree.
The thing about computing is, that there isn't a "right" way to do things, there can be lots fo "right" ways. But there are also lots of wrong ways.
separate classes, usually private inner classes, but you could use a public class in a separate file for something like "CloseListener" which may be reused frequently
and the anonymous inner class
) really depends on two things: will you be using the same listener more than once. If you have listeners which do similar things, eg GreenListener, RedListener, you might be better to add them as, Anyway, you pays your money and you takes your choice, as they say in London. I have never tried a public class in a different file for ExitListener; I presume it works.
Try all the different options and see which works . . . .