*ACTUAL* event handling mechanism in java

Hi there! Could someone please help me find resources that explain how EXACTLY the event handling mechanism works in java?
My searches on google and java.sun take me to pages that explain how to code or something close to that. But what I actually want to know is how is all this handled BY Java- how does the event source or VM know how/when to fire and event? how the event is fired? how do objects keep track of the listener objects?...and all the background stuff like that.
I've downloaded the Java source code, too. But it seems like an ocean to me to wade through. Would be a great help if someone could 'point out the right path'.
Thank you very much!

Hi there! Could someone please help me find
resources that explain how EXACTLY the event
handling mechanism works in java?My counter question is why do you care how EXACTLY the mechanism works? It works, and that's all most people need to know.
How it works is an implementation issue, likely to change from release to release, or as more efficient mechanisms are discovered.
But what I actually want to know is how is all this
handled BY Java- how does the event source or VM
know how/when to fire and event?Native peers attached to a component (AWT) or the frame (Swing) notify Java that an event has occurred in some way. (This will likely change somewhat from platform to platform)
An AWTEvent is created to represent the native event (Swing requiring more overhead to locate the source of the event) which is added to the EventQueue.
how the event is fired? how do objects keep track of
the listener objects?...and all the background stuff like
that.The above is done on a native thread - not the event thread. The event thread is sitting in the event queue waiting for an event to come along. It processes events in the queue and sends them to the object which "generated" them. This object informs each of its listeners in turn about the event.
Objects keep track of listeners however they want. AWT objects seem to use java.awt.AWTEventMulticaster. Swing objects seem to use an javax.swing.event.EventListenerList. I tend to use multiple ArrayLists.
Note that native events are sent through the EventQueue because they originate from non-event-thread threads. Often when specialising events, in particular sending custom events in response to, say, a button press, the event firing will be done in-place, since it is already in the event thread. Custom events that originate from outside the event thread are customarily added to the EventQueue with EventQueue.invokeLater or invokeAndWait.
This is from inspection of the Java 1.3 source (specifically java.awt.Button and javax.swing.JComponent) and knowledge of the APIs.

Similar Messages

  • OO event handling mechanism

    Java2 handles event with oo event handling mechanism , can anybody here tell me some deficiency of this mechanism , and some thing about in VC ++?

    Java2 handles event with oo event handling mechanism ,
    can anybody here tell me some deficiency of this
    mechanism , and some thing about in VC ++?They're all based on variations of the MVC architecture. This stands for Model, View and Controller. The principle is simple. The idea is that you separate the internal program logic (the models) from what the users actually see on the screen (the views). The controller is the mechanism which ties models and views together reacting to user wishes (in the form of events like mouse clicks and pressed keys). It's often also called a listener.
    You'll have to draw a picture of how MVC is implemented in Java Swing and Visual C++ and then compare the implementations. You only benefit from the exercise if you do it yourself. Remember that MVC isn't part of Java or C++ but rather an OO design patter implemented on top of the language to handle the GUI.

  • Having an issue with event handling - sql database  & java gui

    HI all, have posted this on another forum but I think this is the correct one to post on. I am trying to construct this hybrid of java and mysql. the data comes from a mysql database and I want it to display in the gui. this I have achieved thus far. However I have buttons that sort by surname, first name, ID tag etc....I need event handlers for these buttons but am quite unsure as to how to do it. any help would be much appreciated. Thanks in advance.
    /* Student Contact Database GUI
    * Phillip Wells
    import java.awt.BorderLayout;     
    // imports java class. All import class statements tell the compiler to use a class that is defined in the Java API.
    // Borderlayout is a layout manager that assists GUI layout.
    import javax.swing.*;               // imports java class. Swing enables the use of a GUI.
    import javax.swing.JOptionPane;     // imports java class. JOptionPane displays messages in a dialog box as opposed to a console window.
    import javax.swing.JPanel;          // imports java class. A component of a GUI.
    import javax.swing.JFrame;          // imports java class. A component of a GUI.
    import javax.swing.JButton;          // imports java class. A component of a GUI.
    import javax.swing.JScrollPane;     // imports java class. A component of a GUI.
    import javax.swing.JTable;          // imports java class. A component of a GUI.
    import java.awt.*;               // imports java class. Similar to Swing but with different components and functions.
    import java.awt.event.*;          // imports java class. Deals with events.
    import java.awt.event.ActionEvent;     // imports java class. Deals with events.
    import java.awt.event.ActionListener;     // imports java class. Deals with events.
    import java.sql.*;               // imports java class. Provides API for accessing and processing data stored in a data source.
    import java.util.*;               // imports java class. Contains miscellaneous utility classes such as strings.
    public class studentContact extends JFrame {     // public class declaration. The �public� statement enables class availability to other java elements. 
    private JPanel jContentPane; // initialises content pane
    private JButton snam, id, fname, exit; // initialises Jbuttons
    String firstname = "firstname"; //initialises String firstname
    String secondname = "secondname"; //initialises String
    public studentContact() {
    Vector columnNames = new Vector();      // creates new vector object. Vectors are arrays that are expandable.
    Vector data = new Vector();
    initialize();
    try {
    // Connect to the Database
    String driver = "com.mysql.jdbc.Driver"; // connect to JDBC driver
    String url = "jdbc:mysql://localhost/Studentprofiles"; //location of Database
    String userid = "root"; //user logon information for MySQL server
    String password = "";     //logon password for above
    Class.forName(driver); //reference to JDBC connector
    Connection connection = DriverManager.getConnection(url, userid,
    password);     // initiates connection
    // Read data from a table
    String sql = "Select * from studentprofile order by "+ firstname;
    //SQL query sent to database, orders results by firstname.
    Statement stmt = connection.createStatement
    (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    //statement to create connection.
    //Scroll sensitive allows movement forth and back through results.
    //Concur updatable allows updating of database.
    ResultSet rs = stmt.executeQuery(sql); // executes SQL query stated above and sets the results in a table
    ResultSetMetaData md = rs.getMetaData();     // used to get the properties of the columns in a ResultSet object.
    int columns = md.getColumnCount(); //
    for (int i = 1; i <= columns; i++) {
    columnNames.addElement(md.getColumnName(i));     // Get column names
    while (rs.next()) {
    Vector row = new Vector(columns);          // vectors data from table
    for (int i = 1; i <= columns; i++) {     
    row.addElement(rs.getObject(i));     // Get row data
    data.addElement(row);     // adds row data
    rs.close();     
    stmt.close();
    } catch (Exception e) {     // catches exceptions
    System.out.println(e);     // prints exception message
    JTable table = new JTable(data, columnNames) {     //constructs JTable
    public Class getColumnClass(int column) {     
    for (int row = 0; row < getRowCount(); row++) {
    Object o = getValueAt(row, column);
    if (o != null) {
    return o.getClass();
    return Object.class;
    JScrollPane scrollPane = new JScrollPane( table ); // constructs scrollpane 'table'
    getContentPane().add(new JScrollPane(table), BorderLayout.SOUTH); //adds table to a scrollpane
    private void initialize() {
    this.setContentPane(getJContentPane());
    this.setTitle("Student Contact Database");     // sets title of table
    ButtonListener b1 = new ButtonListener();     // constructs button listener
    snam = new JButton ("Sort by surname");     // constructs Jbutton
    snam.addActionListener(b1);     // adds action listener
    jContentPane.add(snam);          //adds button to pane
    id = new JButton ("Sort by ID");     // constructs Jbutton
    id.addActionListener(b1);     // adds action listener
    jContentPane.add(id);          //adds button to pane
    fname = new JButton ("Sort by first name");     // constructs Jbutton
    fname.addActionListener(b1);     // adds action listener
    jContentPane.add(fname);          //adds button to pane
    exit = new JButton ("Exit");     // constructs Jbutton
    exit.addActionListener(b1);     // adds action listener
    jContentPane.add(exit);          //adds button to pane
    private JPanel getJContentPane() {
    if (jContentPane == null) {
    jContentPane = new JPanel();          // constructs new panel
    jContentPane.setLayout(new FlowLayout());     // sets new layout manager
    return jContentPane;     // returns Jcontentpane
    private class ButtonListener implements ActionListener {     // create inner class button listener that uses action listener
    public void actionPerformed (ActionEvent e)
    if (e.getSource () == exit)     // adds listener to button exit.
    System.exit(0);     // exits the GUI
    if (e.getSource () == snam)
    if (e.getSource () == id)
    if (e.getSource () == fname)
    public static void main(String[] args) {     // declaration of main method
    studentContact frame = new studentContact();     // constructs new frame
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);     //exits frame on closing
    frame.setSize(600, 300);          // set size of frame
    frame.setVisible(true);     // displays frame
    }

    OK, so you've got this code here:
    private class ButtonListener implements ActionListener {
      public void actionPerformed (ActionEvent e) {
        if (e.getSource () == exit) {
          System.exit(0); // exits the GUI
        if (e.getSource () == snam) {
        if (e.getSource () == id) {
    }Perfect fine way to do this; although I think creating anonymous would be a bit cleaner:
    snam.addActionListener(new actionListener() {
      public void actionPerformed(ActionEvent ae) {
    });But I think that the real question you have is "what do I put for logic when the JButtons are hit?", right?
    I would answer that you want to dynamically build your SQL statement changing your ordering based on the button.
    So you'd have a method that builds the SQL based on what you pass in - so it takes one argument perhaps?
    private static final int NAME = 1;
                             ID = 2;
    /* ... some code ... */
    snam.addActionListener(new actionListener() {
      public void actionPerformed(ActionEvent ae) {
        buildSQL(NAME);
    /* ... some code ... */
    private void buildSQL(int type) {
      if ( type == NAME ) {
    /* ... build SQL by name ... */
      else if ( type == ID ) {
    /* ... build SQL by id ... */
    }That kind of thing.
    Or you might choose to have several build methods with no parameter type; each building the SQL differently, and calling whichever one you need. I did not read your entire pgm, so I don't know how you'd want to organize it. You need to ask more specific questions at that point.
    ~Bill

  • Unexpected Behaviour of flash event handling mechanism

    I am implementing my own selection manager in flash. When
    ever you have key down the mouse events for movieclips onRelease()
    is called even though you have'nt yet released it. ( if any one
    knows how to handle please reply

    Dear Khedar Prasad,
                     Thank you so much for your wonderful suggestion.
                     I included your following suggestion at BSVW under system settings(system status events).
    1. I0001: CRTD in create event which is the system status set when you create any project ( see basic data tab)
    in this way the event created will get triggered only when you create any project.
                     My workflow now behaves as expected.
                     I am extremely thankful to you.
    Thanks and regards,
    S.Suresh

  • Java 1 vs. Java 2 Event Handling

    Prelude: This question relates to writing code for event handling.
    Java 1 is based on a hierarchy model to handle events, ie. inheritance from superclasses. Java 2 uses delagation event handling method. Java 2 code will not compile if it includes Java 1 code still modeled according to Java 1 event handling.
    Question:
    Is it generally easier to start completely over in trying to convert Java 1 code into Java 2 code by not retaining any Java 1 code and begin reconceptualizing what is needed for a conversion to Java 2?

    From what I understand java2 should support both models, however not both at the same time, you cant mix the modles...
    I also think that the older models methods or at least most have been depreciated, meaning that the old model will, if it hasnt allready in the latest release, dissapear.. For that single reason I would recommend updating the event model to the delegation model if you hope to keep it around and running for years to come. You gain a bit by doing this since the newer model is much faster!!!

  • Difference in event handling between Java and Java API

    could anyone list the differences between Java and java-API in event handling??
    thanks,
    cheers,
    Hiru

    the event handling mechanisms in java language
    features and API (java Application Programming
    Features)features .no library can work without a
    language and no language has event handling built in.
    I am trying to compare and contrast the event
    handling mechanisms in the language and library
    combinations such as java/ java API.
    all contributions are welcome!
    thanks
    cheersSorry, I'm still not getting it. I know what Java is, and I know what I think of when I hear API. (Application Programming Interface.) The API is the aggregation of all the classes and methods you can call in Java. If we agree on that, then the event handling mechanisms in Java and its API are one and the same.
    So what do you want to know?
    %

  • Event-handling mechanisms

    Hi All,
    I am looking for tutorials on the following and related topics:
    creating custom gui components that extend from JComponent
    event-handling mechanism STFWed and all I got was some examples on how to create them
    Look they give an idea on how to do it but that leaves me/you stranded
    in situations where you need to create one that is out of the scope of the example.
    + the examples don't always work.
    Links to preferably tutorials and even more examples would be much appreciated
    thanx
    gtRpr

    Sorry I thought I was in the New to Java Forum
    Only realized that I was in Java Programming Forum after I had created the Thread
    My Bad --- I will be more careful next time

  • Getting error in event handler method onPlugFromStartView

    Hi,
           I am getting error in event handler method onPlugFromStartView java coding. The error message is u201CThe method wdGetwelcome componentcontroller() is undefined for the IPrivatevieew.
    Plese explain how to resolve this error to deploy the webdynpro application successfully.
    Thanks,
    Kundan.

    Hi
    1.It seems some thing corrupt or some problem .
    2. Do one exercise Create one new Dc --component -View ,In component write one method.
        a)  Open the view and then try to add that component.
    Let us know the result
    Best Regards
    Satish Kumar

  • Passing an array into an Event Handler?

    An inventory project I am working on is requiring me to create JButtons (First, Last, Next, and Previous) which are supposed to cycle through and display (in JTextFields) the contents of an array of objects. I can make the buttons work if I do this:
    numberfield.setText("This works when used in the event handler");
    but it does not work when I try to do this:
    numberfield.setText(dirtbikes[0].getNumber());
    When I try this, I get this error:
    InventoryGUITest2:java:124:cannot find symbol
    symbol : variable dirtbikes
    location : class InventoryGUITest2
    numberfield.setText(dirtbikes[0].getNumber());
    ^
    I'm not sure if what I am trying to do is possible, but any guidance would be greatly appreciated. I have included the code for the main class below. Thank you for your time.
    import javax.swing.*; // imports all javax.swing classes
    import java.awt.event.*; // imports event handling components
    import java.awt.*;
    public class InventoryGUITest2 extends JFrame implements ActionListener // class tests an instance of class Inventory using a GUI to display data
         JTextArea textArea;
         JLabel numberlabel, namelabel, speedlabel, pricelabel, stocklabel, restocklabel, valuelabel, totalvaluelabel; // creates JLabels
         JTextField numberfield, namefield, speedfield, pricefield, stockfield, restockfield, valuefield, totalvaluefield; // creates JTextFields
         JButton firstbutton, lastbutton, previousbutton, nextbutton; // creates JButtons for navigation
         public static void main( String args[] ) // begins Java execution
              Dirtbikes dirtbikes[]; // declares array variable
            dirtbikes = new Dirtbikes[4]; //declares array with length of 4
            // populate array
              dirtbikes[0] = new Dirtbikes( "11", "49cc Dirt Bike", 4, 199.99, "25 mph"  );
              dirtbikes[1] = new Dirtbikes( "12", "90cc MotoX Bike", 7, 1299.99, "45+ mph" );
              dirtbikes[2] = new Dirtbikes( "13", "70cc Pit Bike", 3, 359.99, "35+ mph" );
              dirtbikes[3] = new Dirtbikes( "14", "50cc Street Rocket", 5, 879.99, "55+ mph" );
            // end populate array
            new InventoryGUITest2(dirtbikes); // creates new instance of itself
         } // end main method
        // constructor creates and runs GUI
         public InventoryGUITest2(Dirtbikes[] dirtbikes)
            this.setSize(500,300);
              this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              this.setTitle("Dirt Bike Inventory");
              JPanel panel1 = new JPanel(); // creates panel to imbed buttons into bottom of frame
              firstbutton = new JButton("First");
              firstbutton.addActionListener(this);
              panel1.add(firstbutton);
            lastbutton = new JButton("Last");
            lastbutton.addActionListener(this);
            panel1.add(lastbutton);
            previousbutton = new JButton("Previous");
            previousbutton.addActionListener(this);
            panel1.add(previousbutton);
            nextbutton = new JButton("Next");
            nextbutton.addActionListener(this);
            panel1.add(nextbutton);
            this.add(panel1, BorderLayout.SOUTH);
            JPanel panel2 = new JPanel(); // creates panel to imbed labels and fields into frame
            panel2.setLayout(new FlowLayout(FlowLayout.RIGHT));
            numberlabel = new JLabel("Item Number:                                      ");
            numberfield = new JTextField(25);
            numberfield.setEditable(false);
            panel2.add(numberlabel);
            panel2.add(numberfield);
            namelabel = new JLabel("Item Name:                                          ");
            namefield = new JTextField(25);
            namefield.setEditable(false);
            panel2.add(namelabel);
            panel2.add(namefield);
            speedlabel = new JLabel("Top Speed:                                           ");
            speedfield = new JTextField(25);
            speedfield.setEditable(false);
            panel2.add(speedlabel);
            panel2.add(speedfield);
            pricelabel = new JLabel("Price:                                                     ");
            pricefield = new JTextField(25);
            pricefield.setEditable(false);
            panel2.add(pricelabel);
            panel2.add(pricefield);
            stocklabel = new JLabel("# in Stock:                                            ");
            stockfield = new JTextField(25);
            stockfield.setEditable(false);
            panel2.add(stocklabel);
            panel2.add(stockfield);
            restocklabel = new JLabel("Restock Fee (5%):                              ");
            restockfield = new JTextField(25);
            restockfield.setEditable(false);
            panel2.add(restocklabel);
            panel2.add(restockfield);
            valuelabel = new JLabel("Total Value with fee:                          ");
            valuefield = new JTextField(25);
            valuefield.setEditable(false);
            panel2.add(valuelabel);
            panel2.add(valuefield);
            totalvaluelabel = new JLabel("Total Value with fee (for all items):");
            totalvaluefield = new JTextField(25);
            totalvaluefield.setEditable(false);
            panel2.add(totalvaluelabel);
            panel2.add(totalvaluefield);
            this.add(panel2);
            this.setVisible(true); // makes frame visible
              this.setLocationRelativeTo(null); // centers window on screen
         } // end constructor
                   public void actionPerformed(ActionEvent e)
                        if (e.getSource() == firstbutton)
                             numberfield.setText(dirtbikes[0].getNumber());
                   }

    bwilde wrote:
    I appreciate the help as everything I thought I had learned about Java has seemed to fall by the wayside in the shadow of making Swing/AWT work properly.You're not the first person to write this, or code like this in the forum. But realize it isn't true. GUI coding isn't a special case -- it's just another example of object-oriented programming. What's really happening is that the training wheels have come off: Writing a simple Swing example is often the first time one is writing anything that is not trivial.

  • Call to pl/sql from java event-handler

    How can I call pl/sql procedure or function from java-script event handler
    Thanks,
    Anna

    Anna,
    You cannot call any arbitrary PLSQL code from the forms, only "standard"/custom event handlers can be called through do_event Javascript fuction, syntax :
    do_event(this.form,this.name,1,'ON_CLICK,'');
    where:
    1 - button intstance, if you have more than one instance of the same button on the screen this should be 2,3,4.....
    'ON_CLICK' - is the predefined event type
    '' - the last argument is any user defined string which will passed down to the PLSQL event handler.
    Thanks,
    Dmitry
    null

  • Event Handling with Java API.: Adding to a hierarchy table throws 2events

    I´m having some problems with the event handling. I´ve registered a Class with extends AbstractDataListener as EventListener. When there are changes in the product hierarchy table, some extra work should be done. However if i add a new record into the hierarchy, two events are fired.
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R17;Getra?nke, SEW
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R17;32 Zoll, B&R
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R18;56 Zoll, Lenze
    DEBUG DataEventListener.java:123 - Added:Development;PRODUCT_HIERARCHY;R18;20 Zoll, allgemein
    In this case, i added the records "32 Zoll, B&R" and then "20 Zoll, allgemein". As you can see in both cases two events are fired and the first event seems to come with wrong data. The reported id for the newly created record is R17. For the logging, i did lookup the entry in the hierarchy table by id and use the displayvalue of the record. But the first event always shows the displayvalue from some already existing entry.
    How can i avoid duplicate events or if this is not possible, how i can recognize that the display value of the first event is not valid.

    I have not tetsted it yet, because I'm waiting for my server to be updated, but SAP told me that the API version 5.5.42.67 should fix the problem.
    Thanks for your post.

  • Java Event Handling in JSP Pages

    Dear All:
    This is what I wanna do. when user enters text in my <input type="text" ... > in my JSP page, I want to take this user entered data and convert it in another language simultaneously as the user is inputting text in another textarea.
    Right now the only choice I have is onChange="convert()" Javascript function.
    But I dont want to use Javascript as I already have a Java class which does that for the Swing GUI client.
    Is their a way i can embed java for event handling in jsp.
    thanks,
    Chetan

    only if you use an applet, javascript, etc.
    remember, jsp is server-side, not client-side
    what the client sees is html or whatever (i.e. static content)

  • Event handling in seperate class

    hello... i have a gui w/ a series of combo boxes, text fields, etc. (call this the GUI file)
    upon pressing a button, i need to run a series of event handling that will use info from many of these components
    i would like to create a separate java file for the button event handling, but need this file to have access to many componets in the GUI file - does anyone know a nice way to do this?

    i'm not quite sure how to do that... in my GUI class,
    I construct the actuall gui within the constructor..
    then i have a simple driver that creates an instance
    of class GUI and calls the constructor... how can I
    pass a reference of the GUI to the handler in that
    scenario??it would be better if you post your code. Some people like me can't just imagine.

  • Event Handling in Fullscreen Exclusive Mode???????

    WIndows XP SP2
    ATI 8500 All-In-Wonder
    JDK 1.6
    800x600 32dpi 200 refresh
    1-6 buffer strategy.
    the graphic rendering thread DOESN'T sleep.
    Here's my problem. I have a bad trade off. In fullscreen exclusive mode my animation runs <30 fps and jerks when rendering. i.e. stop and go movement (not flickering/jittering just hesitant motion) when the animation is running. I solved this problem by raising the thread priority of the rendering (7-8). . . this resulted in latency/no activity for my input events both key and mouse. For instance closing the program alt-f4 will arbitrarily fail or be successful when the thread priority is raised above 6.
    How does one accomplish a >30 fps and Instant event handling simultaneously in Fullscreen Exclusive Mode?
    Is there a way to raise thread priority for event handling?
    Ultimately I want to be able to perform my animations and handle key and mouse input events without having a visible 'hiccups' on the screen.
    Much Appreciated!

    If I remember correctly the processor is a 1.4(or)6ghz AMD Duron
    Total = 1048048kb
    Available = 106084kb
    Sys Cache = 211788kb
    PF Usage = 1.01 GB
    I solved some of the problem after posting this thread. . . .
    I inserted a thread.sleep(1) and my alt-f4 operation worked unhindered with the elevated thread priority.
    I haven't tested it with mouse event or any other key event but at the moment it looks I may have solved the problem.
    If so, my next question will be is there a way to reduce the amount of cpu power needed to run the program.
    I'm afraid that the other classes that I'm adding will actually become even more process consuming than the actually rendering thread.
    public class RenderScreen extends Thread
      // Screen Rendering status code
      protected final static int RUNNING = 0,
                                 PAUSED = -1;
      // frames per second and process time counters
      protected long now = 0, fps = 0, fpsCount = 0, cycTime = 0;
      // thread status
      protected int status = 0;
      protected Screen screen;
      public void setStatus(int i){ status = i; };
      public void setTarget(Screen screen){ this.screen=screen; };
      public void run()
        setName("Screen Render");
        screen.createBufferStrategy(1);
        screen.strategy = screen.getBufferStrategy();
        for(;;)
          if(status == RUNNING)
            now = System.currentTimeMillis();
            while(System.currentTimeMillis() <= now+1000)
              // call system processes
              // fps increment / repaint interface
              fpsCount++;
              screen.renderView();
              try { Thread.sleep(1);}catch(InterruptedException ie){ ie.printStackTrace(); }
            fps = fpsCount;
            cycTime = System.currentTimeMillis() - (now + 1000);
            fpsCount=0;
      public RenderScreen(){};
      public RenderScreen(Screen screen){ this.screen=screen; };
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class Screen extends Window
      BufferedImage image = new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB);
      Graphics2D gdd = image.createGraphics();
      MediaTracker tracker = new MediaTracker(this);
      Image bground = getToolkit().getImage("MajorityRule.jpg"),
            bawl = getToolkit().getImage("bawl.gif");
      RenderScreen rScreen = new RenderScreen(this);
      BufferStrategy strategy;
      Graphics g;
      Rectangle rect = new Rectangle(400,0,150,150);
      //Game game = new Game();
      public void renderView()
        g = strategy.getDrawGraphics();
        //--------- Game Procedures [start]
        gdd.drawImage(bground,0,0,this);
        gdd.drawString("fps: ["+rScreen.fps+"] Cycle Time: ["+rScreen.cycTime+"]",0,10);
        //--------- Game Procedures [end]
        //---------test
        gdd.drawImage(bawl,rect.x,rect.y,rect.width,rect.height,this);
        rect.translate(0,1);
        g.drawImage(image,0,0,this);
        //g.dispose();
        strategy.show();
      public Screen(JFrame frame)
        super(frame);
        try
          tracker.addImage(bground,0);
          tracker.addImage(bawl,1);
          tracker.waitForAll();
        catch(InterruptedException ie){ ie.printStackTrace(); }
        setBackground(Color.black);
        setForeground(Color.white);
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class MajorityRule extends JFrame
      // Graphic System Handlers
      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice gd = ge.getDefaultScreenDevice();
      GraphicsConfiguration gc = gd.getDefaultConfiguration();
      Screen screen = new Screen(this);
      Paper paper = new Paper();
      public void windowed()
        paper.setSize(getWidth(),getHeight());
        getContentPane().add(paper);
        setResizable(false);
        setVisible(true);
      public void fullscreen()
        DisplayMode dMode = new DisplayMode(800,600,32,200);
        screen.setBounds(0,0,800,600);
        if (gd.isFullScreenSupported()) gd.setFullScreenWindow(screen);
        if (gd.isDisplayChangeSupported()){ gd.setDisplayMode(dMode); };
        screen.setIgnoreRepaint(true);
        screen.setVisible(true);
        screen.rScreen.setPriority(Thread.MAX_PRIORITY);
        screen.rScreen.start();
        screen.requestFocus();
      public MajorityRule(String args[])
        setTitle("Majority Rule [Testing Block]");
        setBounds(0,0,410,360);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        getContentPane().setLayout(null);
        if (args.length > 0 && args[0].equals("-window")) windowed();
        else fullscreen();
      public static void main(String args[])
        new MajorityRule(args);
    };

  • Event handler switch creation (for repeated use )

    Im creating a hyperterminal like application which reads from serial port and  writes into serial port.
    The reading and writing works almost fine..I also wants to create some custom "Key controls" that will send some prestored commands to the serial port.
    I currently implemented two commands "ESC" and "FLASH " in the Key controls menu..
    I want to send these commands ESC and FLASH each time i click a button in the menu.
    I used event handler for it..and put the event handler inside an always running while loop.
    But the problem is I can send only these commands only for one time during execution.
    Repeated pressing of switches doesnt cause any effects..
    Can somebody help please???
    Im using labview 6.1. If u modify VIs using higher versions i cant open here..kindly include a jpg screenshot inthat case.
    Thanking you.
    Stephen.
    Attachments:
    Serial Port(stable release)1.2.vi ‏113 KB
    Init.vi ‏32 KB
    Write.vi ‏44 KB

    Hi Stephen,
    in LV7.1 your events will be executed whenever I press one of the according switches...
    Notes:
    -Don't make several event structures. Instead make one event structure with several event cases. Read the context help for the event structure!
    -I would suggest to set the mechanical action of both switches to "latch when pressed" instead of "switch..." to give a feedback to the user as the switch will be reset after reading it...
    -Generally be more styleguide-conform! Use right-click on terminals to create controls/constants to avoid coercion dots (spot the red colored dots in the image?). Make error in/out in the lower left/right of the connector pattern. Avoid block diagrams larger than the screen (or what kind of monitor do you use?).
    Edited:
    Sorry for weird display. I have to get used to the new image gallery feature of the forum (and will use "image to the left" only on rare conditions). Btw. the preview looks different to the actual post
    Message Edited by GerdW on 05-28-2009 06:59 AM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

Maybe you are looking for

  • DB adapter polling in OSB

    1. In a clustered environemnt, we need to use "Distributed polling" in DB adapter to make sure the multiple cluster instances are not polling for the database at the sametime. If "Distributed polling" can achieve that, what is the need to have single

  • Updating base table with Materialized View's data

    Hi, In order to update base table with MVs data, I am trying real time data transfer between two databases. One is Oracle 8i and other is Oracle 9i. I have created an updatable MV in 9i on a base table using database link. The base table is in 8i. Ma

  • What is Worksafe Mode and how do I disable it?

    I am attempting to view photos on several websites and some of them are blocked with the message IMAGE NOT VIEWABLE WORKSAFE MODE ON

  • Change Notification Service  for Detla functionality in DM

    Hi All, We are implementing DM(Deposit Management ) for BI.For extracting data from the standard extractor we have to do some Prerequisites(refer the link). Can anyone help me to explain the functionality of change notification service for extraction

  • Faield to run Batch Risk Analysis BG JOB in RAR

    Dear Expert, While doing batch risk analysis (Including all User/Role/Profile  Action and Permission level analysis with Management Report), often we are getting the following error , that we found from the log. Feb 7, 2009 8:32:23 AM com.virsa.cc.xs