473,320 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

ActionListener

176 100+
I have an action listener question. What goes in the parameters when adding an action listener to a button. Here is my code:
Expand|Select|Wrap|Line Numbers
  1. package NumberAverager;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JButton;
  5. import javax.swing.JTextField;
  6. import javax.swing.JLabel;
  7. import java.awt.Container;
  8. import java.awt.FlowLayout;
  9. import java.awt.event.ActionListener;
  10. import java.awt.event.ActionEvent;
  11.  
  12. class NumberAverager
  13. {
  14.     public static void main(String[] args)
  15.     {
  16.         //create and set the title for a new frame
  17.         JFrame frame = new JFrame();
  18.         frame.setTitle("Number Averager");
  19.  
  20.         //create a container
  21.         Container contentPane = frame.getContentPane();
  22.  
  23.         //create a layout and apply it to the contentPane
  24.         FlowLayout layout = new FlowLayout();
  25.         frame.setLayout(layout);
  26.  
  27.         //create components
  28.         JTextField num1 = new JTextField("Number 1");
  29.         JTextField num2 = new JTextField("Number 2");
  30.  
  31.         JButton calculate_average = new JButton("Calculate average");
  32.  
  33.         JLabel average = new JLabel("Average");
  34.  
  35.         //add the components
  36.         contentPane.add(num1);
  37.         contentPane.add(num2);
  38.  
  39.         contentPane.add(calculate_average);
  40.  
  41.         contentPane.add(average);
  42.  
  43.         //create action listeners
  44.         calculate_average.addActionListener(WHATGOESHERE?);
  45.  
  46.         //frame settings
  47.         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  48.         frame.pack();
  49.         frame.setVisible(true);
  50.  
  51.     }
  52. }
May 28 '08 #1
1 1161
JosAH
11,448 Expert 8TB
Why are you asking this very same question again in another thread? Please
keep one subject to one thread; if you feel your message is being ignored, you
can bump it. I'm closing this duplicate thread.

kind regards,

Jos
May 28 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Hal Vaughan | last post by:
I have a "wizard" type program with a series of panels that are placed in a JPanel. When the "Next >" button is pressed, I put in a new panel (in other words, the ActionListener for "Next >"...
1
by: Patrick Vanhoof | last post by:
Hi, I have a small program to test the ActionListener, but it gives errors. Here's part of the code: class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent...
0
by: linux newbie | last post by:
is there any java expert could tell me what the problem below and explain the code to me, your explanation is greatly appreciated :) static Class class$java$awt$event$ActionListener; ...
1
by: cnixuser | last post by:
Hello, I am currently attempting to implement a simple actionlistener for a button in a JFrame that was created via "drag and drop" with the Netbeans 5.0 IDE, the code that I am using to implement...
1
by: Phil Latio | last post by:
Quite a while back I used Java Swing (for Uni project) which allowed the developer to a create form and on the "Submit" button I recall adding something called an ActionListener. I was thinking of...
3
by: shailajaanand | last post by:
can we add Actionlistener to textarea?
3
by: stmfc | last post by:
KeyListener listens keyboard strokes, MouseListener listens mouse events, etc. My question is about ActionListener. what kind of events does ActionListener listen? its name does not give...
1
by: carlos123 | last post by:
if (bathroom.isSelected()){ bathroom is a jcheckbox, why doesnt that work.
4
Stubert
by: Stubert | last post by:
Hi there just a quick question, if I have multiple JMenuItems do I need to create an inner class ActionListener for each and every JMenuItem I create? Or is there a more efficient way of doing it? ...
7
by: Kid Programmer | last post by:
Hey guys. Once again I am making a calculator like I do so much. I ran into an error with this program though. I just couldn't figure out how to make the operators work. I want this calculator to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.