Hello guys. I am receiving an error while creating a program that will capitalize words entered in a text box. I have 2 files with code. Here they are:
File No. 1:
File No. 2:
Here is my error:
symbol : class MyActionListene r
location: class capitalizeme.Ma in
button.addActio nListener(new MyActionListene r(textfield));
1 error
File No. 1:
Code:
package capitalizeme;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.FlowLayout;
public class CapitalizeMe {
public static void main(String[] args) {
JFrame frame;
Container contentPane;
JTextField textfield;
JButton button;
FlowLayout layout;
frame = new JFrame();
frame.setTitle("Handy capitalization service");
contentPane = frame.getContentPane();
textfield = new JTextField("Type your text here.", 20);
button = new JButton("Capitalize");
button.addActionListener(new MyActionListener(textfield));
contentPane.add(textfield);
contentPane.add(button);
layout = new FlowLayout();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}
Code:
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
class MyActionListener implements ActionListener {
JTextField textfield;
MyActionListener(JTextField textfield) {
this.textfield = textfield;
}
public void actionPerformed(ActionEvent e) {
textfield.setText(textfield.getText().toUpperCase());
}
}
symbol : class MyActionListene r
location: class capitalizeme.Ma in
button.addActio nListener(new MyActionListene r(textfield));
1 error
Comment