Answer to Question #18935 in Java | JSP | JSF for Callie
2012-11-19T09:19:21-05:00
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
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 !
Learn more about our help with Assignments:
Java JSP JSF
Comments
Leave a comment