Java Reference
In-Depth Information
LISTING 11.5
Continued
66: }
67: JPanel sub3 = new JPanel();
68: nextButton.setEnabled(true);
69: sub3.add(nextButton);
70: finalButton.setEnabled(false);
71: sub3.add(finalButton);
72: GridLayout grid = new GridLayout(3, 1);
73: setLayout(grid);
74: add(sub1);
75: add(sub2);
76: add(sub3);
77: }
78:
79: void setFinalQuestion(boolean finalQuestion) {
80: if (finalQuestion) {
81: nextButton.setEnabled(false);
82: finalButton.setEnabled(true);
83: }
84: }
85: }
After the SurveyWizard class has been compiled, it can be added to any Swing user
interface.
Listing 11.6 contains a simple frame . application that displays a survey panel.
LISTING 11.6
The Full Text of SurveyFrame.java
1: import java.awt.*;
2: import javax.swing.*;
3:
4: public class SurveyFrame extends JFrame {
5: public SurveyFrame() {
6: super(“Survey”);
7: setSize(290, 140);
8: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
9: SurveyWizard wiz = new SurveyWizard();
10: add(wiz);
11: setVisible(true);
12: }
13:
14: public static void main(String[] arguments) {
15: SurveyFrame surv = new SurveyFrame();
16: }
17: }
The running application was shown earlier in Figure 11.5.
 
Search WWH ::




Custom Search