daina
11-17-2005, 06:54 AM
Hai,
I got a problem. I have a class ,say, Class A which extends a Jframe.I have 3 other class say,FirstClass,SecondClass & ThirdClass.all of which extends Jpanel.In the class A there is a JPanel panel.In that panel I have 2 buttons. yesButton & noButton . When I pressed YesButton,I have to display Firstpanel,SecondPanel, & ThirdPanel.In the Firstpanel I have 2 textboxes & in the other panel I have buttons.
When I pressed "NoButton" in the class A. I have to display only Firstpanel. ie textboxes.
But when I pressed yesbutton ,all the panels are displaying & then if i pressed nobutton ,secondpanel * thirdpanel should not visible.But it is displaying.I need everything in one frame itself. Can anybody tell me how to do it.
The code is
<code>
public class ClassA extends JFrame implements ActionListener {
transient JPanel panel = null;
transient JPanel panel1 = null;
public ClassA() {
super();
initializeComponent();
}
private void initializeComponent() {
setSize(WIDTH, HIEGHT);
final JButton yesButton = new JButton("Yes");
final JButton noButton = new JButton("No");
panel = new JPanel(new FlowLayout());
final JLabel label = new JLabel(
"Do You want to use Buttons ? ");
panel.add(label);
panel.add(yesButton);
panel.add(noButton);
yesButton.addActionListener(this);
noButton.addActionListener(this);
panel.setBorder(BorderFactory.createEtchedBorder());
this.getContentPane().add(panel);
this.setVisible(true);
}
public void actionPerformed(final ActionEvent event) {
int flag = 0;
if (event.getActionCommand() == "Yes") {
flag = 1;
setLayout(new GridBagLayout() );
final GridBagConstraints constraint1 = new GridBagConstraints();
constraint1.gridx = 0;
constraint1.gridy = 1;
final FirstClass display = new FirstClass (flag);
this.add(display, constraint1);
final GridBagConstraints constraint2 = new GridBagConstraints();
constraint2.gridx = 0;
constraint2.gridy = 2;
final SecondClass displaybuttons1 = new SecondClass ();
displaybuttons1 .addKeyBoardListener(display);
this.add(displaybuttons1 , constraint2);
final GridBagConstraints constraint3 = new GridBagConstraints();
constraint3.gridx = 0;
constraint3.gridy = 3;
final ThirdClass thirdclass= new ThirdClass ();
thirdclass.addKeyBoardListener(display);
this.add(thirdclass, constraint3);
this.add(panel1);
this.setSize(550, 450);
this.setVisible(true);
} else if (event.getActionCommand() == "No") {
flag = 0;
final GridBagConstraints constraint1 = new GridBagConstraints();
constraint1.gridx = 0;
constraint1.gridy = 1;
final FirstClass display = new FirstClass (flag);
this.add(display, constraint1);
this.setVisible(true);
//this.add(panel);
}
}
</code>
Thanks
Jaxy
I got a problem. I have a class ,say, Class A which extends a Jframe.I have 3 other class say,FirstClass,SecondClass & ThirdClass.all of which extends Jpanel.In the class A there is a JPanel panel.In that panel I have 2 buttons. yesButton & noButton . When I pressed YesButton,I have to display Firstpanel,SecondPanel, & ThirdPanel.In the Firstpanel I have 2 textboxes & in the other panel I have buttons.
When I pressed "NoButton" in the class A. I have to display only Firstpanel. ie textboxes.
But when I pressed yesbutton ,all the panels are displaying & then if i pressed nobutton ,secondpanel * thirdpanel should not visible.But it is displaying.I need everything in one frame itself. Can anybody tell me how to do it.
The code is
<code>
public class ClassA extends JFrame implements ActionListener {
transient JPanel panel = null;
transient JPanel panel1 = null;
public ClassA() {
super();
initializeComponent();
}
private void initializeComponent() {
setSize(WIDTH, HIEGHT);
final JButton yesButton = new JButton("Yes");
final JButton noButton = new JButton("No");
panel = new JPanel(new FlowLayout());
final JLabel label = new JLabel(
"Do You want to use Buttons ? ");
panel.add(label);
panel.add(yesButton);
panel.add(noButton);
yesButton.addActionListener(this);
noButton.addActionListener(this);
panel.setBorder(BorderFactory.createEtchedBorder());
this.getContentPane().add(panel);
this.setVisible(true);
}
public void actionPerformed(final ActionEvent event) {
int flag = 0;
if (event.getActionCommand() == "Yes") {
flag = 1;
setLayout(new GridBagLayout() );
final GridBagConstraints constraint1 = new GridBagConstraints();
constraint1.gridx = 0;
constraint1.gridy = 1;
final FirstClass display = new FirstClass (flag);
this.add(display, constraint1);
final GridBagConstraints constraint2 = new GridBagConstraints();
constraint2.gridx = 0;
constraint2.gridy = 2;
final SecondClass displaybuttons1 = new SecondClass ();
displaybuttons1 .addKeyBoardListener(display);
this.add(displaybuttons1 , constraint2);
final GridBagConstraints constraint3 = new GridBagConstraints();
constraint3.gridx = 0;
constraint3.gridy = 3;
final ThirdClass thirdclass= new ThirdClass ();
thirdclass.addKeyBoardListener(display);
this.add(thirdclass, constraint3);
this.add(panel1);
this.setSize(550, 450);
this.setVisible(true);
} else if (event.getActionCommand() == "No") {
flag = 0;
final GridBagConstraints constraint1 = new GridBagConstraints();
constraint1.gridx = 0;
constraint1.gridy = 1;
final FirstClass display = new FirstClass (flag);
this.add(display, constraint1);
this.setVisible(true);
//this.add(panel);
}
}
</code>
Thanks
Jaxy