Let's add another button to this version of the WordPlay program, a "Double" button. Notice that we've added new code, so that WordPlay now contains a JButton component called doubleButton. When the Double button is clicked, the displayed string should be doubled, or repeated, in the program.
They give me most of the code but it is incomplete, im going to post the code that they gave first, then my answers which are incorrect.
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class WordPlay extends JPanel implements ActionListener{ JLabel inst = new JLabel("Enter your text:"); JTextField textField = new JTextField(5); JButton submit = new JButton("Submit"); JButton doubleButton = new JButton("Double"); JLabel display = new JLabel(); public WordPlay() { this.add(inst); this.add(textField); this.add(submit); submit.addActionListener(this); CODE 1 this.add(display); } public void actionPerformed(ActionEvent e){ Object source = e.getSource(); if(source == submit){ display.setText(textField.getText()); } CODE 2 } }
MY answer for CODE 1
My answer for CODE 2doubleButton = new JButton("Double"); this.add(doubleButton); doubleButton.addActionListener(this);
if(source == doubleButton){ display.setText(textField.getText(Double)); }
Usually when I submit something, it gives me some sort of feedback or error but not in this problem, i get nothing back. it just says it is wrong.