Answer to Question #18935 in Java | JSP | JSF for Callie

Question #18935
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.
1
Expert's answer
2012-11-19T11:49:55-0500
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS