Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't make JTextField ActionListener
    primarykey
    data
    text
    <p>I'm trying to add an <code>ActionListener</code> to a <code>JTextField</code> and make that text field the action listener itself. Whenever I do that I get an error, saying </p> <pre><code>The method addActionListener(ActionListener) in the type JTextField is not applicable for the arguments (JTextField) </code></pre> <h2>Code</h2> <pre><code>String strBox1; JTextField textBox1, textBox2, textBox3; JTextArea textArea1, displayArea; public textBoxes() { setLayout (new GridLayout(10,2)); JLabel query1 = new JLabel("Daily Savings:"); add(query1); textBox1 = new JTextField("Dsave", 5); add(textBox1); textBox1.addActionListener(textBox1); //textBox1.getDocument().addDocumentListener(new MyDocumentListener()); JLabel query2 = new JLabel("Current Age:"); add(query2); textBox2 = new JTextField("Cage", 5); add(textBox2); JLabel query3 = new JLabel("Initial Savings amount:"); add(query3); textBox3 = new JTextField("ISA", 5); add(textBox3); JLabel query4 = new JLabel("Age of Retirement:"); add(query4); JTextField textBox4 = new JTextField("AoR", 5); add(textBox4); JLabel query5 = new JLabel("Annual Retirement Income:"); add(query5); JTextField textBox5 = new JTextField("ARI", 5); add(textBox5); JLabel query6 = new JLabel("Life Expectancy:"); add(query6); JTextField textBox6 = new JTextField("LR", 5); add(textBox6); JLabel query7 = new JLabel("Interest Rate on Return of Savings:"); add(query7); JTextField textBox7 = new JTextField("IRoRoS", 5); add(textBox7); JLabel query8 = new JLabel("Inflation %:"); add(query8); JTextField textBox8 = new JTextField("I%", 5); add(textBox8); } class MyDocumentListener implements DocumentListener { public void insertUpdate(DocumentEvent e) { } public void removeUpdate(DocumentEvent e) { System.out.println("change -" + e); } public void changedUpdate(DocumentEvent e) { } } class MyTextActionListener implements ActionListener { public void actionPerformed(ActionEvent e) { } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload