67 258
Assignments Done
99,1%
Successfully Done
In November 2018

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.
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions