Results 1 to 6 of 6

Thread: How to use Event class of java?

  1. #1
    Join Date
    Jan 2010
    Posts
    79

    How to use Event class of java?

    Hi friend,

    I need you help to get solution over my java query which is related to the inbuilt classes. There are some classes which sounds very complicated functionality. I am unable to understand the 'Event class' of java. I am not aware about it's constructors also. If anyone posses good knowledge about the Event class of java, then please let me know the same. Please also provide suitable example for the same.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: How to use Event class of java?

    Event is a platform-independent class that encapsulates events from the platform's GUI in the Java 1.0 event model. In Java 1.1 and later versions, the Event class is maintained only for backwards compatibility. The information in this class description is provided for to assist java programmers in the converting Java 1.0 programs to the new event model. In the Java 1.0 event model, an event contains an id field that indicates what type of event it is and which other Event variables are relevant for the event.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to use Event class of java?

    Hi,

    Please review following example which will demonstrate you the use of Event class:
    Code:
    import javax.swing.event.CaretListener;
    import javax.swing.event.CaretEvent;
    
    public class eventDM
     {
    
      public static void main(String[] anh) {
        JFrame ZT = new JFrame();
        ZT.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        JTextField textField1 = new JTextField();
    
        textField1.addCaretListener(new CaretListener() {
    
          public void caretUpdate(CaretEvent e) {
            System.out.println(e);
    
          }
        }
    
        ZT.add(new JScrollPane(textField1));
    
        ZT.setSize(400, 200);
        ZT.setVisible(true);
      }
    
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to use Event class of java?

    Hi friend,

    To use Event class, you should be aware about following it's constructors:
    • Event(Object target, long wn, int id, int x1, int y1, int key1, int modifier1, Object arg1)
    • Event(Object target, long wn, int id, int x1, int y1, int key1, int modifier1)
    • Event(Object target, int id1, Object arg1)

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How to use Event class of java?

    Example of Event class:
    Code:
    import java.awt.event.ActionEvent;
    import javax.swing.text.Element;
    import javax.swing.text.ElementIterator;
    
    public class EventSample {
      public static void main(String arygs[]) {
        JFrame GMQ = new JFrame("Element Example");
        GMQ.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        final JTextArea textArea = new JTextArea();
        JScrollPane scrollPane1 = new JScrollPane(textArea);
    
        JButton button004 = new JButton("Show Elements");
        ActionListener actionListener = new ActionListener() {
          public void actionPerformed(ActionEvent actionEvent) {
            Document document1 = textArea.getDocument();
            ElementIterator iterator = new ElementIterator(document);
            Element element1 = iterator.first();
            while (element != null) {
              System.out.println(element1.getStartOffset());
              element1 = iterator.next();
            }
          }
        };
        button004.addActionListener(actionListener);
    
        GMQ.add(scrollPane, BorderLayout.CENTER);
        GMQ.add(button004, BorderLayout.SOUTH);
    
        GMQ.setSize(200, 250);
        GMQ.setVisible(true);
      }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: How to use Event class of java?

    Hello friend,

    Following are some fields available with Event class of java:
    1. SCROLL_LINE_DOWN
    2. WINDOW_DESTROY
    3. WINDOW_DEICONIFY
    4. SCROLL_PAGE_UP
    5. KEY_ACTION_RELEASE
    6. SCROLL_PAGE_DOWN

Similar Threads

  1. Event handlers vs. base class method overrides
    By Tailapa in forum Software Development
    Replies: 5
    Last Post: 26-06-2011, 07:38 PM
  2. Converting java class to java bean class
    By Ucchal in forum Software Development
    Replies: 6
    Last Post: 09-08-2010, 10:24 AM
  3. How to create mouse event using Robot class in java?
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 03-02-2010, 08:03 PM
  4. How to create key press event using Robot class in java?
    By Kasper in forum Software Development
    Replies: 4
    Last Post: 03-02-2010, 06:33 PM
  5. Java Programming Language Basics: Reflection Basics and Class Class
    By mayuri_gunjan in forum Guides & Tutorials
    Replies: 6
    Last Post: 29-08-2005, 12:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,437,142.18667 seconds with 16 queries