Forums Register Login

"...not abstract and does not override abstract method..."

+Pie Number of slices to send: Send
Thanks for all the help from the experienced Java folks that I have received on this forum so far. I am still working on getting a text string from the user into my code. Since I am using J-Link with Pro/Engineer CAD software I cannot use "JOptionPane.showInputDialog" or similar because the window always shows up behind my main application window.

As a result I am forced to build my own dialog from scratch. This successfully displays the dialog window; but, the text from the text field is not successfully read into the string variable. In order to alleviate this problem I am attempting to implement an ActionListener.

At compile time, I receive the error message: "Jerry_Test is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener"

Any help would be greatly appreciated. Here is my code:

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class Jerry_Test implements ActionListener
{

public static void start()
{

JFrame parentFrame = new JFrame();
JLabel new_label = new JLabel("New part number");
final JTextField new_text = new JTextField(50);
JPanel new_panel = new JPanel();
new_label.setLabelFor(new_text);
new_panel.add(new_label);

JOptionPane new_pane = new JOptionPane(new_panel);
new_pane.setWantsInput(true);

JDialog new_dialog = new_pane.createDialog(parentFrame, "Test dialog");
new_dialog.setModal(false);
new_dialog.setVisible(true);
new_dialog.toFront();

new_text.addActionListener
(
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String new_name = new_text.getText();
}
}
);

}

public static void stop()
{
}

}
+Pie Number of slices to send: Send
As the error message says, Jerry_Test declares that it "implements ActionListener", but it does not; the class JerryTest doesn't implement the method "actionPerformed" declared in that interface.

Since you're using an anonymous class as your actual listener, Jerry_Test doesn't need to implement this interface for any reason, anyway, so just remove those two words "implements ActionListener" and you'll be good.

Do you have an intro Java programming text? Java isn't a scripting language where you can copy a line from here and a line from there; it really, really helps to have some understanding of what you're writing.
Create symphonies in seed and soil. For this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 15346 times.
Similar Threads
ActionListener illegal start of expression
getText() doesn't work
Adding a text field to JDialog with JTextField
OK button does not dispose of parent frame within ActionListener
Why doesn't my WindowListener work?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:42:12.