here's a quick explanation, I make my TextField into false condition inside of .setEnabled area. So basically after the user press check on Cake's check-box, he need to choose either one of the sub-item menu, after he do that, he needs to enter the quantity of the cake. But, after choosing the sub-item menu, the TextField condition should be true(means it should be editable), but it doesn't go as were told. Thank you.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
class testingcheckbox
{
public static void main(String[] args)
{
Frame qB = new Frame("Queen Bakery");
JCheckBox cake;
cake = new JCheckBox("Cake");
JCheckBox cakeOpt1 = new JCheckBox("Butter Cake");
JCheckBox cakeOpt2 = new JCheckBox("Cheese Cake");
TextField tfCake = new TextField();
tfCake.setPreferredSize(new Dimension(50,24));
tfCake.setEnabled(false);
ActionListener cakeListener = new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
if(cake.isSelected())
{
cakeOpt1.setEnabled(true);
cakeOpt2.setEnabled(true);
if(cakeOpt1.isSelected())
{
tfCake.setEnabled(true);
}
else
{
tfCake.setEnabled(false);
}
}
else
{
cakeOpt1.setEnabled(false);
cakeOpt2.setEnabled(false);
}
}
};
cake.addActionListener(cakeListener);
qB.add(cake);
cakeOpt1.setEnabled(false);
cakeOpt2.setEnabled(false);
qB.add(cakeOpt1);
qB.add(cakeOpt2);
qB.add(tfCake);
qB.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent windowEvent)
{
System.exit(0);
}
});
qB.setSize(780,470);
qB.setLayout(new FlowLayout(FlowLayout.LEFT));
qB.setVisible(true);
qB.setLocationRelativeTo(null);
qB.setResizable(false);
}
}
Aucun commentaire:
Enregistrer un commentaire