✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
The following code is intended to show quotes; it provides a window, a button, a text (JLabel), and another button:
JFrame frame = new JFrame("Quote"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(400, 300); frame.setLayout(new BorderLayout()); JButton quoteButton = new JButton("Show Quote"); frame.add(quoteButton,BorderLayout.NORTH); JLabel quoteText = new JLabel("Quote coming soon ..."); quoteText.setHorizontalAlignment(SwingConstants.CENTER); frame.add(quoteText,BorderLayout.CENTER); JButton anotherQuoteButton = new JButton("Show Quote");
frame.setVisible(true);
Assume you want to show a quote in quoteText (a text in HTML format, <br> is the tag for line break) when pressing quoteButton or anotherQuoteButton. Which of the following statements enable this behavior for at least one of the buttons?
a)
quoteText.addActionListener(e -> { quoteText.setText("<html> There are 10 kind of people,<br> those who understand binary, <br> and those who don’t.</html>"); frame.repaint(); });
b)
quoteButton.addActionListener(e-> { quoteButton.setText("<html> There are 10 kind of people,<br> those who understand binary, <br> and those who don’t.</html>"); frame.repaint(); });
c)
quoteButton.addActionListener(e-> { quoteText.setText("<html> There are 10 kind of people,<br> those who understand binary, <br> and those who don’t.</html>"); frame.repaint(); });
d)
anotherQuoteButton.addActionListener(e-> { quoteText.setText("<html> There are 10 kind of people,<br> those who understand binary, <br> and those who don’t.</html>"); frame.repaint(); });