Java Reference
In-Depth Information
Given:
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Interface extends JFrame implements ActionListener {
public boolean deleteFile;
public Interface() {
super(“Interface”);
JLabel commandLabel = new JLabel(“Do you want to delete the file?”);
JButton yes = new JButton(“Yes”);
JButton no = new JButton(“No”);
yes.addActionListener(this);
no.addActionListener(this);
setLayout( new BorderLayout() );
JPanel bottom = new JPanel();
bottom.add(yes);
bottom.add(no);
add(“North”, commandLabel);
add(“South”, bottom);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent evt) {
JButton source = (JButton) evt.getSource();
// answer goes here
deleteFile = true;
else
deleteFile = false;
}
public static void main(String[] arguments) {
new Interface();
}
}
Which of the following statements should replace // answer goes here to make the
application function correctly?
a. if (source instanceof JButton)
b. if (source.getActionCommand().equals(“yes”))
c. if (source.getActionCommand().equals(“Yes”))
d. if source.getActionCommand() == “Yes”
Search WWH ::




Custom Search