Can't seem to add a clear button

Hi,
I'm new to java and I'm having problems creating a clear button. Basically I want to have a button once clicked that would clear some text fields and a JComboBox. Here's what I've got so far.
        JButton clear = new JButton("<html><b>CLEAR");
        clearFields.addActionListener();
        content.add(clear);This should add the button and attach it to the action listener.
        private void clearFields() {
        ProjectOfficer.setText("");
        }As you can see I'm only trying to clear one field at the moment. I've got 6 more textfields and one JComboBox to clear as well. Problem I'm getting is that on the clearFields.addActionListener(); line I get an error saying Cannot find symbol; variable clearFields.
I'm not sure why I'm getting this error because clearFields is clearly there?
Any help Please?

Thanks for both replies.
I'm very new to this which is why I've had so many problems. I've more or less been using the approach of learn as I go along. I know that isn't the best thing to do but at them moment its my only option. With your help cotton.m I've added the clear button but as you guessed it doesnt work. I've had a look through my code and with my basic knowledge I can't seem to figure out what the problem is. Here is my full code.
import java.awt.Container;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import javax.swing.UIManager;
import java.sql.*;
import javax.swing.table.*;
import javax.swing.event.*;
* heckley.java
* Created on 25 August 2007, 10:42
* @author Tahir Malik
public class heckley {
    //field variables - created here so all of our methods have access to them
    protected JFrame window;
    protected Container content;
    //these ones are for the form objects
    protected JTextField projectOfficer;
    protected JTextField projectName;
    protected JTextField projectDescription;
    protected JTextField paymentSchedule;
    protected JTextField banksInvestment;
    protected JTextField paymentsMade;
    protected JComboBox projectType;
     * Creates a new instance of heckley
    public heckley() {
        //draw the GUI
        drawGUI();
    /** Adds a standard menubar to the window*/
    private void menuBar() {
        //create a new menubar
        JMenuBar bar = new JMenuBar();
        //attach the menubar to the window
        window.setJMenuBar(bar);
        //create the file menu
        JMenu fileMenu = new JMenu("File");
        fileMenu.setMnemonic('F');
        bar.add(fileMenu);
        JMenuItem quit = new JMenuItem("Quit");
        quit.setMnemonic('Q');
        //quit.setIcon(new ImageIcon("images/quit.png"));
        quit.addActionListener(new QuitListener());
        fileMenu.add(quit);
    /** Draws the GUI **/
    private void drawGUI() {
        //set the user interface look and feel
        try {
            //if the user is using windows
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception ex) {
            try {
                //if the user is usisng Mac, Unix, OS/2, Solaris or Linux
                UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
            } catch(Exception xtc) {
                System.err.println("Unable to determine a UI look and feel");
        //create the main JFrame
        window = new JFrame("Heckley");
        //set close operation
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //add the menu bar
        this.menuBar();
        //create the container
        content = window.getContentPane();
        content.setLayout(new GridLayout(9,2,1,5));
        Font f = new Font( "Courier", Font.ITALIC, 18 );
        content.add(new JLabel("   Project Officer   "));
        projectOfficer = new JTextField();
        content.add(projectOfficer);
        content.add(new JLabel("   Project Name   "));
        projectName = new JTextField();
        content.add(projectName);
        content.add(new JLabel("   Project Description   "));
        projectDescription = new JTextField();
        content.add(projectDescription);
        content.add(new JLabel("   Payment Schedule   "));
        paymentSchedule = new JTextField();
        content.add(paymentSchedule);
        content.add(new JLabel("   Banks Investment   "));
        banksInvestment = new JTextField();
        content.add(banksInvestment);
        content.add(new JLabel("   Payments Made   "));
        paymentsMade = new JTextField();
        content.add(paymentsMade);
        content.add(new JLabel("   Project Type   "));
        projectType = new JComboBox();
        String [] comboOptions = new String[] {"Leasing", "Profit Sharing", "Trade Financing" };
        projectType.setModel(new DefaultComboBoxModel(comboOptions));
        content.add(projectType);
        JButton add = new JButton("<html><b>Add");
        add.addActionListener(new AddToDatabaseListener());
        content.add(add);
        JButton remove = new JButton("<html><b>REMOVE");
        remove.addActionListener(new RemoveFromDatabaseListener());
        content.add(remove);
        JButton clear = new JButton("CLEAR");
        clear.addActionListener(this);// assuming your class implements ActionListener
        content.add(clear);
        JButton search = new JButton("<html><b>SEARCH");
        search.addActionListener(new SearchFromDatabaseListener());
        content.add(search);
        //ALL MAIN GUI GENERATION HERE//
        protected JTextField projectName;
        protected JTextArea projectDescription;
        protected JTextField paymentSchedule;
        protected JTextField banksInvestment;
        protected JTextField paymentsMade;
        protected JComboBox projectType;*/
        //pack the window
        window.pack();
        //display the window
        window.setLocation(400,400);
        window.setVisible(true);
        //window.setResizable(false);
    /** addToDatabase - Adds a set of data to the database
     * @param project_officer The officers name
     * @param project_name The projects name
     * @param project_description The projects description
     * @param payment_schedule The payment schedule
     * @param already_paid The amount already paid
     * @param banks_investment The amount the bank has invested
     * @param project_type The type of project
     * @returns zero for failiure, 1 for addition
    public static int addToDatabase(String PROJECT_OFFICER, String PROJECT_NAME, String PROJECT_DESCRIPTION, String PAYMENT_SCHEDULE, int ALREADY_PAID, int BANKS_INVESTMENT, String PROJECT_TYPE) {
        int added = 0;
        Statement s = null;
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
            Connection connection = DriverManager.getConnection("jdbc:derby://localhost:1527/PROJECT;user=nbuser;password=nbuser");       
            s = connection.createStatement();
        } catch (SQLException se) {
            System.err.println("We got an exception while creating a statement:" +
                    "that probably means we're no longer connected.");
            se.printStackTrace();
            System.exit(1);
        } catch (ClassNotFoundException cnfex) {
            System.err.println("We got an exception while trying to import the Derby library. Check installation.");
            cnfex.printStackTrace();
        } catch (Exception ex) {
            System.err.println("We got an exception while trying to use the Derby library. Check installation.");
            ex.printStackTrace();
        int m = 0;
        try {
            m = s.executeUpdate("INSERT INTO \"NBUSER\".\"TABLE\" VALUES" +
                    "('"+PROJECT_OFFICER+"', '"+PROJECT_NAME+"', '"+PROJECT_DESCRIPTION+"', '"+PAYMENT_SCHEDULE+"', "+ALREADY_PAID+", "+BANKS_INVESTMENT+", '"+PROJECT_TYPE+"')");
        } catch (SQLException se) {
            System.err.println("We got an exception while executing our query:" +
                    "that probably means our SQL is invalid");
            se.printStackTrace();
        return added;
    /* Action listeners - we need 1 for every button or menu option we have */
    class AddToDatabaseListener implements ActionListener {
        public void actionPerformed(ActionEvent ent) {
            //add to database event - call the function with correct parameters
            System.out.println("This entry has been added to the database!");
            //because all of the form objects are protected, we can directly get thier contents
            String projectOfficerV = projectOfficer.getText();
            String projectNameV = projectName.getText();
            String projectDescriptionV = projectDescription.getText();
            String paymentScheduleV = paymentSchedule.getText();
            int banksInvestmentV = Integer.parseInt(banksInvestment.getText());
            int paymentsMadeV = Integer.parseInt(paymentsMade.getText());
            String projectTypeV = (String)projectType.getSelectedItem();
            //call method to add
            addToDatabase(projectOfficerV,projectNameV,projectDescriptionV,paymentScheduleV,banksInvestmentV,paymentsMadeV,projectTypeV);
   class QuitListener implements ActionListener {
        public void actionPerformed(ActionEvent ent) {
            //action for file>quit
            System.exit(0);
   public static int removeFromDatabase(String PROJECT_NAME) {
        int added = 0;
        Statement s = null;
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
            Connection connection = DriverManager.getConnection("jdbc:derby://localhost:1527/PROJECT;user=nbuser;password=nbuser");       
            s = connection.createStatement();
        } catch (SQLException se) {
            System.err.println("We got an exception while creating a statement:" +
                    "that probably means we're no longer connected.");
            se.printStackTrace();
            System.exit(1);
        } catch (ClassNotFoundException cnfex) {
            System.err.println("We got an exception while trying to import the Derby library. Check installation.");
            cnfex.printStackTrace();
        } catch (Exception ex) {
            System.err.println("We got an exception while trying to use the Derby library. Check installation.");
            ex.printStackTrace();
        int m = 0;
        try {
            m = s.executeUpdate("DELETE FROM \"NBUSER\".\"TABLE\" WHERE PROJECT_NAME = '" + PROJECT_NAME + "'");
        } catch (SQLException se) {
            System.err.println("We got an exception while executing our query:" +
                    "that probably means our SQL is invalid");
            se.printStackTrace();
        return added;
        /* Action listeners - we need 1 for every button or menu option we have */
        class RemoveFromDatabaseListener implements ActionListener {
        public void actionPerformed(ActionEvent ent) {
        //remove from database event - call the function with correct parameters
        System.out.println("This entry has been removed to the database!");
        //because all of the form objects are protected, we can directly get thier contents
        String projectNameV = projectName.getText();
        //call method to add
        removeFromDatabase(projectNameV);
        public static int searchFromDatabase(String PROJECT_NAME) {
        int added = 0;
        Statement s = null;
       // Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/PROJECT;user=nbuser;password=nbuser");
        try {
            Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
            Connection connection = DriverManager.getConnection("jdbc:derby://localhost:1527/PROJECT;user=nbuser;password=nbuser");       
            s = connection.createStatement();
        } catch (SQLException se) {
            System.err.println("We got an exception while creating a statement:" +
                    "that probably means we're no longer connected.");
           se.printStackTrace();
            System.exit(1);
        } catch (ClassNotFoundException cnfex) {
            System.err.println("We got an exception while trying to import the Derby library. Check installation.");
            cnfex.printStackTrace();
       } catch (Exception ex) {
            System.err.println("We got an exception while trying to use the Derby library. Check installation.");
            ex.printStackTrace();
        int m = 0;
        try {
            s.executeQuery("SELECT * FROM \"NBUSER\".\"TABLE\" WHERE PROJECT_NAME LIKE '" + PROJECT_NAME + "'");
      //      Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
      //                              ResultSet.CONCUR_READ_ONLY);
       //     ResultSet srs = stmt.executeQuery("SELECT * FROM \"NBUSER\".\"TABLE\"");
        } catch (SQLException se) {
            System.err.println("We got an exception while executing our query:" +
                    "that probably means our SQL is invalid");
            se.printStackTrace();
        return added;
        /* Action listeners - we need 1 for every button or menu option we have */
        class SearchFromDatabaseListener implements ActionListener {
        public void actionPerformed(ActionEvent ent) {
        //remove from database event - call the function with correct parameters
        System.out.println("SEARCHING THE DATABASE!");
        //because all of the form objects are protected, we can directly get thier contents
        String projectNameV = projectName.getText();
        //call method to add
        searchFromDatabase(projectNameV);
        public void actionPerformed(ActionEvent evt){
        if(evt.getActionCommand().equals("CLEAR")){
        projectOfficer.setText("");
   public static void main(String [] args) {
        //create a new instance of the object
      heckley h1 = new heckley();
}I'm getting this error on the following line.
AddActionListener (java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (heckley)
        clear.addActionListener(this);// assuming your class implements ActionListenerThanks for your help. I know I need to improve my java and I'm working towards that and have managed to fix most of my problems but for some reason I can't get this to work!

Similar Messages

  • Can't seem to add artwork to pdf files

    In the "Books" tab, I can add artwork to epub books, but I can't seem to add artwork to pdf files. Is this a normal thing? Or is there something I'm doing wrong?
    Also, do you know what I should be setting my page widths to if I want the pdf files I create to display nicely in Portrait mode on an iPhone? The ones I made seem to only look nice in Landscape mode.

    Devin,  If they end in .ogg, they are OGG Vorbis files.  This is a well-known open-source music format, but iTunes is unable to play it.
    Also, as you have just learned, when iTunes encounters a file that is not copmatible, it "errors silently," i.e. gives no indication of what they problem is.
    To resolve it, use a 3rd party conversion program such as Switch to convert the OGG files into MP3, and then they will add to iTunes.

  • I am walking through Apples tutorial getting started with iOS development. I am at the storyboard area and can't seem to drag the cancel button to the green exit. I am not sure why the exit button doesn't except it. Is anyone else having this issue?

    I am walking through Apples tutorial getting started with iOS development. I am at the storyboard area and can't seem to drag the cancel button to the green exit. I am not sure why the exit button doesn't except it. Is anyone else having this issue? Is there a work around? I have done this app twice and still cant get the exit to except the Cancel or Done  bar buttons

    Yes I checked it.  As far as I can see I did everything Apple said to do.  I took some screen shot so you can see how the screens are connected and what and where the code is, and what it does when I drag the cancel and done bar buttons to the exit

  • I can't seem to find a buy button.

    I can't seem to find a "buy" button on my wish list or anywhere after I updated iTunes.

    Hi,
    https://discussions.apple.com/thread/5244336?start=0&tstart=0

  • How can I hide the "Add Page Text" button in Lightroom 5 Book Module

    In Lightroom 5's Book Module, there is an "Add page text" button that appears when you are in either two-page or single-page view.
    More often than not, it sits right on top of my photo caption text causing that text to be unreadable.
    Is there an option to hide that button?

    If there is no specific reason that you have to use sendredirect...thne you can try request.forward.....
    RequestDispatcher rd = request.getRequestDispatcher("pathToResource");
      rd.forward(request, response);

  • Can a batch sequence add a simple button?

    Can anyone tell me if a batch sequence can be used to add a "close document" button to a group of Acrobat documents? I have 75 PDF documents that all need a button added. If I can do it using a sequence it will be a huge time saver.
    Thanks.

    Sure.
    The following includes some smaple code for something similar: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.435.html
    You just need to edit it so you only add one button, so get rid of the loop, and set the setAction code would be:
    f.setAction("MouseUp", "closeDoc()");

  • User can't seem to add a second email account

    I have a client whose device has until now activated on a BESX.  He now has a Z10.  He managed to get his email account added using Exchange & Active-Sync as email, contacts and appointments is really about the only things they need.
    The user with the Z10 cannot seem to add his personal account to the phone.  He has spoken with a Blackberry technician, (don't know how that was done without paying for it.) and he was told that although his Z10 is not activated on their BESX it is still using it and Blackberry Balance needs to be enabled for him to be able to add a personal account.
    I can't understand how that will work if it's not activated on the BESX let alone the version of BESX doesn't seem to have Blackberry Balance available as it's 5.0.2, and the Z10's aren't supposed to activate unless it's a BES10 server.
    Wondering if the data plan is set for a BES which might be preventing addition of personal accounts without first being activated on a BES.  However if that was the case then the account he got setup probably shouldn't have worked.
    I haven't even seen one of the Z10's so I have no idea how to walk him through instructions on adding a personal account.  I believe he is trying to add a GMail account which also is giving peopel a hard time.

    May or may not be  helpful...but I had the same problem on my Z10.  Make sure on the second account the 'SMPT Username' and 'Update SMTP Password' fields are blank. 
    When setting  up my second account these fields were auto-populated and I had to wipe them out in order for it to work. 

  • HT201077 I can't seem to "add invitees"

    I want to be able to share my photo stream with family.  I have never used photo stream before.  But the Help menu tells me once I have the photos uploaded I can "add invitees" by selecting the photo stream on the left and then clicking on the info button on the bottom right.  Then there should be a place to "add invitees" but there is not. When I click the info button the right side bar opens up but it just has the normal info that is there when you look at a picture- location, file name, etc.  The only difference is when no individual picture is selected it says "These photos were downloaded from the photo stream".  Please help me- I'm betting this one is user error and I just don't know how to do it, but the help menu isn't really helping. 
    Thanks!

    Sounds like you are looking at your photo stream album.  You first have to create a shared photo stream.  Search iPhoto help for "Create a shared photo stream" to see how.  After create your shared photo stream album, you can then select it, click on Info, then type the email address(es) of the people you want to invite in the "Shared With" section and press enter.  Note: click on Turn on Public Website if any of your subscribers do not have iCloud accounts.

  • I can't seem to ADD or even PLAY big files in iTunes

    Well this forum is my last resource, really. I've tried everything, even called Apple Technical Support twice, with no solution.
    The thing is I wanted to add an audio file, mp3, to itunes library. I noticed it wouldn't be added in any way (dragging or from the menu). I couldn't find out what was the problem but then I saw that another file, same size (65 MB), hadn't been added too. All the other files, which are much smaller, work fine. So I think the problem is the size of the mp3.
    Anyway, I tried everything I could think about, and also reinstalling itunes (which was suggested by the tech support). I checked the files and they're OK, they play regularly on WMP, winamp, VLC. Then i found out that don't even play on itunes. In fact, it doesn't recognize them: the SOLE rection it manifests is coming to the top when I try to open the files straight from the explorer. And that's all, no error msg, nthng, it just stays there, not even opening the player or addind to a playlist if I will.
    That's basically it... i really tried to circumvent this issue on my own, i tried hard and called support. When they couldn't help i gave up. I always think I'm doing smthng stupid and that the solution is obvious, right in frint of me, but I really can't see it. If you could help me, even telling me if you are also unable to deal with "huge" files in itunes, I'd be grateful...
    Any suggestions? Thanks!
    ps: i got windows XP pro SP 2, i have free disk space and my ipod is a shuffle 1 G (its not lack of space on it, i cant even manage to get to the stage of filling it)

    Just out of curiosity, try playing the song in a different program . . . maybe Windows Media Player to see if it works. I wonder if it's corrupted....

  • Can't seem to add Administrator (Other) to users login screen

    I recently had to reformat my hard drive and reinstall Tiger. Unfortunately at the time I did not have a way of backing up my hard drive. When I first setup user accounts using the "Users" preferences I seem to recall having the option of including the system administrator to the login window, and it would show up as "Other" and I would type "root" and the root password, and all was good. But since having to completely rebuild my hard drive (I now own a 500GB Firewire backup drive which I do backups religiously) I went to setup my list of users, and I could not figure out why "Other" system administrator will not show up on the login screen. How do I get the system administrator to show up in the login screen, and can it be called "System Administrator" or "root" instead of "Other"?

    Hi Eric, Welcome to Apple's Users Help Users Forums.
    From my read of your post in case gnarlodious misunderstands you I will remind you re adding new users.
    System Preferences / Accounts / Unlock / '+' and call it what you like. Enable it as admin rather than standard.
    [OT] For added security one should surf the web in a standard account. That gives you a pause before changing anything so you can think "Do I really want to do this." If you are currently surfing as "admin," post back or email and I'll run you thru how to change and keep preferences.

  • I can't seem to add my hotmail using the advanced set up on my new Z10

    When I go to add an account using the advanced setup (selecting the hotmail icon), the phone keeps telling me my login information is incorrect.  I can login to hotmail without any difficulties on my playbook and laptop.  What am I doing wrong?

    I found this problem was caused by the Microsoft Live Account "2-step verification process" (which is optional). I only discovered this after I had to log back into my Live account on the PC, and (silly me) decided I should opt for the 2-step verification process. 
    Using your computer:
    1. log into your Microsoft Live Services Account
    2. select Security Info
    3. switch off the two-step verification process
    Now go back to your Blackberry, set up your Live account with your email address and password by selecting Accounts /  Add Account / Email, Calendar and Contacts / <youremail_address> 
    Once it has connected, select Accounts / Edit Account / Advanced / check "Push" (or go for Sync), and note that you can select or deselect the option "Download Messages While Roaming"
    Worked for me on BBZ10. Hope that helps somebody else. 

  • How to download previous versions of photoshop, i can't seem to find the install button that leads you too the previous versions.

    I've tried to download previous versions but don't know how have followed the steps that adobe has given but my creative cloud doesn't come up with install but try and when i press it, it downloads and i just wanted to fins previous versions of photoshop such as cs6 and trial it thanks.

    You can access previous CC versions of Photoshop from the CC Desktop.
    First under "Find New Software", select "Previous versions"
    Then under Photoshop, click the arrow on the Install button to see and install Previous Photoshop versions.

  • Can't seem to add Airport Express unit to my Airport Extreme network

    Hello, I plugged in the Airport Express thing and it flashes between amber and green.  I went into Airport Utilities in my MacBook Pro, and it does not appear.  It was used in my old home, but I have no idea what it's name was or any password for it.  The new network has a different name, too.  How do I add it? Help!

    Do a factory reset, and start from scratch.
    Resetting an AirPort Base Station or Time Capsule FAQ
    http://support.apple.com/kb/HT3728

  • I just upgraded to the 6 plus; I can't seem to add it to my itunes account. Please help me!

    I just got a 6 plus. How do i add it to my itunes account?

    Where exactly do you want to add it ?
    If to register it to your account's support profile : https://supportprofile.apple.com/
    If you want it to show in the 'manage devices' section of your iTunes account then you will need to use iTunes Match, automatic downloads or redownload past purchases on it : Manage your associated devices in iTunes - Apple Support
    To log into your account on your phone : Settings > iTunes & App Store

  • HT5731 How do I purchase the music on my wish list? I can't seem to find a buy button??

    How do I purchase the music on my wish list? I do not see a 'cart' or a buy button??

    There used to be a 'buy all' button on the wish list screen, but for some reason that has been removed on the current version of iTunes. You will need to buy each item individually, there should be a 'buy' button to the right of each.
    If you'd like the 'buy all' button to be brought back then you could try leaving feedbackd for Apple and maybe it'll be added back in a future update : http://www.apple.com/feedback/ipad.html

Maybe you are looking for