Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084216
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:24:42+00:00 2026-05-20T18:24:42+00:00

I’m reworking my code here and I get the following errors: Exception in thread

  • 0

I’m reworking my code here and I get the following errors:

Exception in thread "main" java.lang.Error: 

Unresolved compilation problem:     

The method addActionListener(new ActionListener(){}) is undefined for the type Component  
at SwimCalc.createCustomers(SwimCalc.java:87)  
at SwimCalc.<init>(SwimCalc.java:29)  
at SwimCalc.main(SwimCalc.java:275)  

Code:

import java.awt.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.event.*;
import java.util.*;
import java.io.*;

public class SwimCalc extends JFrame implements ActionListener{
private JTabbedPane jtabbedPane;
private JPanel General;
private JPanel Pools;
private JPanel HotTub;
private JPanel Customers;
private JPanel Contractors;

JTextField lengthTextPool, widthTextPool, depthTextPool, volumeTextPool,
lengthTextHotTub, widthTextHotTub, depthTextHotTub, volumeTextHotTub;

JTextArea NameTextCustomers, ExistTextCustomers, NameTextContractors, ExistTextContractors;

public SwimCalc(){
setTitle("Volume Calculator");
setSize(300, 200);

JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );

createCustomers();

jtabbedPane = new JTabbedPane();
jtabbedPane.addTab("General", General);
jtabbedPane.addTab("Pool", Pools);
jtabbedPane.addTab("Hot Tub", HotTub);
jtabbedPane.addTab("Customers", Customers);
jtabbedPane.addTab("Contractors", Contractors);
topPanel.add(jtabbedPane, BorderLayout.CENTER);
              }

/*        CREATE CUSTOMERS        */

public Container createCustomers(){
    Customers = new JPanel();
    Customers.setLayout( null );

    NameTextCustomers = new JTextArea();
    NameTextCustomers.setBounds(10, 10, 350, 150);
    NameTextCustomers.setLineWrap(true);
    Customers.add(NameTextCustomers);

    JButton Exit = new JButton("Exit");
    Exit.setBounds(30,170,80,20);
    Exit.addActionListener(this);
    Exit.setBackground(Color.white);
    Customers.add(Exit);

    JButton AddCustomers = new JButton("Add Customer");
    AddCustomers.setBounds(130,170,120,20);
    AddCustomers.setBackground(Color.white);
    Customers.add(AddCustomers);

    JButton Refresh = new JButton("Refresh");
    Refresh.setBounds(260,170,80,20);
    Refresh.setBackground(Color.white);
    Customers.add(Refresh);

    ExistTextCustomers = new JTextArea();
    ExistTextCustomers.setBounds(10, 200, 350, 60);
    ExistTextCustomers.setLineWrap(true);
    Customers.add(ExistTextCustomers);

    new Customer("Customer"); 

;
Container custPanel;
final Component custArea;
custPanel.add(custArea); 
Component addCustomer;
custPanel.add(addCustomer); 

Component custRefButton;
custPanel.add(custRefButton); 
final Component custMessage;
custPanel.add(custMessage); 
((AbstractButton) custRefButton).setMnemonic('R'); 

custRefButton.addActionListener(new ActionListener() 
{ 
public void actionPerformed(ActionEvent e) 
{ 
((JTextComponent) custMessage).setText(""); 
try
{ 
File custOpen = new File("customer.txt"); 
FileReader custAreaIn = new FileReader(custOpen); 
((JTextComponent) custArea).read(custAreaIn, custOpen.toString()); 
((JTextComponent) custMessage).setText("The file exists and can be read from."); 
} 
catch (IOException e3){ 
((JTextComponent) custMessage).setText("The file could not be read. " + e3.getMessage()); 
} 
} 
} ); 
return custPanel; 
} 

class Customer extends JFrame 
{ 
private String[] states = {"AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", 
"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", 
"MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", 
"NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", 
"TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"}; 
private JComboBox StateList = new JComboBox(states); 
private JTextField NameText = new JTextField(25); 
private JTextField AddressText = new JTextField(25); 
private JTextField CityText = new JTextField(25); 
private JTextField ZipText = new JTextField(9); 
private JTextField PhoneText = new JTextField(10); 
private JTextField PopMessageText = new JTextField(30); 
private static final long serialVersionUID = 1L; 

private AddCustButtonHandler addCusHandler = new AddCustButtonHandler(); 

public Customer(String who) 
{ 
popUpWindow(who); 
} 
public void popUpWindow(final String who) { 

final JFrame popWindow; 
popWindow = new JFrame(who); 
popWindow.setSize(425, 350); 
popWindow.setLocation(100, 100); 
popWindow.setVisible(true); 
setDefaultCloseOperation(EXIT_ON_CLOSE); 

Container c = new Container(); 

popWindow.add(c); 

c.setLayout(new FlowLayout()); 

JPanel one = new JPanel(); 
JPanel two = new JPanel(); 
JPanel three = new JPanel(); 
JPanel four = new JPanel(); 
JPanel five = new JPanel(); 
JPanel six = new JPanel(); 

one.add(new JLabel(who + " Name ")); 
one.add(NameText); 
two.add(new JLabel("Address ")); 
two.add(AddressText); 
three.add(new JLabel("City ")); 
three.add(CityText); 
four.add(new JLabel("State ")); 
StateList.setSelectedIndex(0); 
four.add(StateList); 
four.add(new JLabel("ZIP")); 
four.add(ZipText); 
four.add(new JLabel("Phone")); 
four.add(PhoneText); 
JButton addwho = new JButton("Add " + who); 
addwho.setMnemonic('A'); 
JButton close = new JButton("Close"); 
close.setMnemonic('C'); 
JButton deleteFile = new JButton("Delete File"); 
deleteFile.setMnemonic('D'); 
five.add(addwho); 
five.add(close); 
five.add(deleteFile); 
PopMessageText.setEditable(false); 
PopMessageText.setHorizontalAlignment(JTextField.CENTER); 

six.add(PopMessageText); 
c.add(one); 
c.add(two); 
c.add(three); 
c.add(four); 
c.add(five); 
c.add(six); 

deleteFile.setToolTipText("Delete File"); 
addwho.setToolTipText("Add "+ who); 
close.setToolTipText("Close"); 

if (who == "Customer") 
addwho.addActionListener(addCusHandler);
close.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) { 
NameText.setText(""); 
AddressText.setText(""); 
CityText.setText(""); 
ZipText.setText(""); 
PhoneText.setText(""); 
PopMessageText.setText(""); 
popWindow.dispose(); 
} 
} ); 
deleteFile.addActionListener(new ActionListener() { 
public void actionPerformed(ActionEvent e) { 
PopMessageText.setText(""); 
if (who == "Customer") { 
File file = new File("Customer.txt"); 
boolean cusFileDeleted = file.delete(); 
if (cusFileDeleted) { 
PopMessageText 
.setText("Customer file has been deleted"); 
} else { 
PopMessageText 
.setText("There was an erron in deleting file"); 
} 
} 
} 
} ); 
}
class AddCustButtonHandler implements ActionListener { 
public void actionPerformed(ActionEvent addCusHandler) { 
int StateIndex; 
try { 
File file = new File("Customer.txt"); 

boolean success = file.createNewFile(); 

if (success) { 
PopMessageText 
.setText("Customer.txt file created file added"); 
} else if (file.canWrite()) { 
PopMessageText 
.setText("Writing data to Customer.txt, file added"); 
} else { 
PopMessageText.setText("Cannot create file: Customer.txt"); 
} 
try { 
FileWriter fileW = new FileWriter("Customer.txt", true); 
fileW.write(NameText.getText()); 
fileW.write(","); 
fileW.write(AddressText.getText()); 
fileW.write(","); 
fileW.write(CityText.getText()); 
fileW.write(","); 
StateIndex = StateList.getSelectedIndex(); 
fileW.write(states[StateIndex]); 
fileW.write(","); 
fileW.write(ZipText.getText()); 
fileW.write(","); 
fileW.write(PhoneText.getText()); 
fileW.write("\r\n"); 
fileW.close(); 
PopMessageText.setText("A new Customer has been added!"); 

FileReader fileR = new FileReader("Customer.txt"); 
BufferedReader buffIn = new BufferedReader(fileR); 

String textData = buffIn.readLine(); 
buffIn.close(); 
} 
catch (IOException e1) { 
JOptionPane.showMessageDialog(null, e1.getMessage(), "ERROR", 2);
} 
NameText.setText(""); 
AddressText.setText(""); 
CityText.setText(""); 
ZipText.setText(""); 
PhoneText.setText(""); 
} catch (IOException e1) { 
} 

} 
} 
} 

public static void main(String[] args){
JFrame frame = new SwimCalc();
frame.setSize(380, 350);
frame.setVisible(true);
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:24:43+00:00Added an answer on May 20, 2026 at 6:24 pm

    Class Component doesn’t define a method addActionListener(). Usually that would be the method on AbstractButton/JButton/Button classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.