473,473 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with activeListener interface

8 New Member
Hi friends ..
i was writing a program that use three buttos and change its color when we click on a particuler button... but its not working their is some problem with activeListener interface i am giving code with it please help....



Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class buttonTest {
  5.  
  6.     /**
  7.      * @param args
  8.      */
  9.     public static void main(String[] args) {
  10.         // TODO Auto-generated method stub
  11.         fr f=new fr();
  12.         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  13.         f.setVisible(true);
  14.     }
  15. }
  16. class fr extends JFrame
  17. {
  18.     public fr()
  19.     {
  20.         setTitle("Rawinder Dhillon");
  21.         setSize(500,500);
  22.         pa p=new pa();
  23.         add(p);
  24.     }
  25. }
  26. class pa extends JPanel
  27. {
  28.     public pa()
  29.     {
  30.         JButton yb=new JButton("Yellow");
  31.         JButton bb=new JButton("Blew");
  32.         JButton rb=new JButton("Red");
  33.  
  34.         add(yb);
  35.         add(bb);
  36.         add(rb);
  37. // now button actions 
  38.         ColorAction ya=new ColorAction(Color.YELLOW);// patrameter in costr. 
  39.         ColorAction ba=new ColorAction(Color.BLUE);
  40.         ColorAction ra=new ColorAction(Color.RED);
  41.  
  42.     // associate action with buttins 
  43.  
  44.         yb.addActionListener(ya);
  45.         bb.addActionListener(ba);
  46.         rb.addActionListener(ra);
  47.     }
  48. }
  49. public class ColorAction implements ActionListener
  50. {
  51.     private Color bg;
  52.     public ColorAction(Color c)
  53.     {
  54.         bg=c;
  55.     }
  56.     public void actonPerformed(ActionEvent event)
  57.     {
  58.         setBackground(bg);
  59.  
  60.     }
  61. }
Mar 1 '09 #1
2 1723
JosAH
11,448 Recognized Expert MVP
@rawinder dhillon
Why don't you at least tell us what the problems are? You don't want us to blindy guess do you? btw, the name of the method is not ActonPerformed.

kind regards,

Jos
Mar 1 '09 #2
rawinder dhillon
8 New Member
thanks for checking but i have found the problem iin the code the class color acrtion was a inner class and " { }" are the problemmm... thanks
Mar 2 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Brad Quinn | last post by:
Friday, no brain power remains... I have three assemblies; Client, Interface and Implementation. The Client uses Implementation through remoting. Client has a reference to Interface, but not...
3
by: Pol Bawin | last post by:
A class has a private field of type IWizard (An interface) and a public property to access it. When I try to serialize the Geometry class in XML, i have an error but it works in Binary Can...
0
by: Nadav | last post by:
Hi, Introduction: **************** I am writing a component based application, the application is built of several Native COM objects and some .NET classes exposed as COM objects by 'COM...
7
by: Stephan Rose | last post by:
Ok here is my scenario I have an interface called IScalar which describes a one dimensional number that has a certain unit of measurement. This interface is used to create multiple structures,...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
10
by: Bryce Calhoun | last post by:
Hello, First of all, this is a .NET 1.1 component I'm creating. SUMMARY ----------------------- This component that I'm creating is, for all intents and purposes, a document parser (I'm...
1
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a...
2
by: Paul W | last post by:
Hello, My problem concerns the shell. If there's a better forum for this post, please let me know. I'm trying to create a ListView control that displays the contents of a folder with all the...
7
by: raknin | last post by:
Hi I have a carousel script. I want to load the carousel with a new set of pictures every time I press a button. The problem that I have that the script append the new pictures to the olds one...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.