ah im in 1st year IT student, my project is about to make a Notepad and it should have an event to perform.
example:
is when i go to [B]"file"[/B] then click the [B]"save"[/B] and it will perform.. pls give some example of class that use an event..
Im new member here so this is my greetings to all...

TIA...

by the way this is my code.

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


public class Notepad extends JFrame 
{
    JMenuBar mb=new JMenuBar();
    JMenu menu=new JMenu("File");
    JMenu m2=new JMenu("Edit");
    JMenu m3=new JMenu("View");
    JMenuItem i3=new JMenuItem("Save");
    JMenuItem i1=new JMenuItem("New");
    JMenuItem i2=new JMenuItem("Open");
    JMenuItem o1=new JMenuItem("Cut");
    JMenuItem o3=new JMenuItem("Paste");
    JMenuItem o2=new JMenuItem("Copy");
    JMenuItem o4=new JMenuItem("Delete");
    JMenuItem p2=new JMenuItem("Status Bar");
    JMenuItem p1=new JMenuItem("Details");

    JTextArea txt=new JTextArea(50,50);

    JScrollPane scroll=new JScrollPane(txt);

    BorderLayout border=new BorderLayout();
    Container con;

    public Notepad() 
    {

    con=getContentPane();
    con.setLayout(border);
    con.add(scroll);
    menu.add(i1); menu.add(i2); menu.add(i3);
    m2.add(o1);
    m2.add(o2);
    m2.add(o3);
    m2.add(o4);
    mb.add(menu);
    mb.add(m2);
    mb.add(m3);
    m3.add(p1);
    m3.add(p2);
    con.add(mb,"North");
    con.add(txt);



    }
    public static void main(String [] a)

    {
        Notepad pn=new Notepad();
        pn.setSize(500,500);
        pn.setTitle("NotePad");
        pn.setVisible(true);
    } 
   //here is my problem thanks a lot..
   public void actionPerform(ActionEvent e)
   {

   }


}

Recommended Answers

All 8 Replies

Your class needs to implement ActionListener. Then ofcourse you will need to set actioncommands etc for each menu item.

Chris

Java has an Event Delegation Model.
In short this goes like this. There are Event sources which are components such as Button, Frames, Windows, Textboxes, Text Areas etc. There are Event Listeners which listen to events. Event Listeners need to register to an Event Source so that for any events that originate from that source the Listener will be notified. The Listener is notified by calling it's aprropriate method on the occurrence of an event. Then in this method, you check the event source (since this listener could be listening to multiple sources) and take appropriate action.

Please can u give me a class that use an event handling so that the i can copy the code..

Is programming so tedious an activity that so many people on so many occassions want to just by pass their way blindly copying what others give them ? It is supposed to be fun.

We will not give you the code whatsoever, read the forum rules about offering homework help. You have been given enough pointers on information figure your way out and show some effort.

Please can u give me a class that use an event handling so that the i can copy the code..

copy-paste is the last thing you want to do, especially if you don't understand the how-and-what.

Freaky_Chris, Verruckt and Ezzaral are not trying to hold you back ... they're telling you how to solve your problem by learning how to fix it right next time without having this kind of troubles

just follow the leads they gave you, and you'll be fine

copy-paste thats not what i mean, i need only example program... so that i can determine the codes.. we mis-understood each other..
by the way thanks for support guys.. now my project are running... God bless u all.

so that the i can copy the code

English isn't my first language, I wouldn't have come across it at all if the Brits hadn't stayed for close to 300 years. But from whatever impure version of it I know, I can only deduce one meaning from that, which is what others deduced too. And you weren't exactly hinting at copying the example code, so...

Okay if this has been solved, would you now care to mark it as one.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.