I have a JButton that is suppose to remove JLabels when pressed. Everything I have tried in actionPerformed does not work. All I get are errors for button and labels.
This code removes JLabel lab from the JFrame fr.
static JLabel lab;
staticJFrame fr;
publicstatic void main(String[] args)
{
fr=newJFrame();
fr.setSize(newDimension(100, 100));
fr.setLayout(newFlowLayout());
fr.setVisible(true);
JButtonbut=new JButton("rem");
lab=newJLabel("qwetr");
fr.add(lab);
fr.add(but);
but.addActionListener(newActionListener()
{
@Override
publicvoid actionPerformed(ActionEvent arg0)
{
if(lab.getParent()!=null)
{
lab.getParent().remove(lab);
fr.repaint();
}
}
});
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF