Event Handling without GUI!!!!

Hi everybody,
I want to design a mult-threaed application which will process Key events without displaying any GUI components! (I know it is stupid but these are the requirements). I tried to use java.awt.event.*; but it seems that it is not working without displaying anything. Is there any method to capture keyboard events without using GUI components?
Thank you very much in advance,

Do you mean you want your program running on the
console? while having Events dispatched!!Yes, I am also stuck in a similar problem.
I want to detect mouse move system wide. The problem is that, my code recognizes mouse move only on components those are added in my program.
i.e., if I add a frame then MouseMove (or any AWTEvent)will be listened by the AWTEventListener on that frame only. And I want such a Listener which can listen to System-wide Mouse events so that I can capture mouse position throught the System at any random time.
I hope someone will have any link to my topic and will provide me any kind of knowledge.

Similar Messages

  • Event handling without new class

    I'm new to Java, so please bear with me.
    I'm working with a file management software called Intralink which allows automating tasks by recording keystrokes or writing instructions in Java. A typical recorded script would look like:
    // Start Macro Recording
    import com.ptc.intralink.client.script.*;*
    *import com.ptc.intralink.script.*;
    public class newpn2 extends ILIntralinkScript {
    ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();
    private void run0 () throws Exception {
    IL.deselectAll( "WSPI" ); // recorded step: 1
    IL.select( "WSPI", "New_Generic/template_sm.prt" ); // recorded step: 2
    } // End of run0
    public void run () throws Exception {
    run0 (); // recorded
    } // End of function
    } // End Macro RecordingI don't know why but the run0() function has to be called from the run() function. (to clarify that, the run0() can be called from anywhere but all the statements beginning with "IL." are ignored unless it was called from the run() function) I'm trying to write something that uses a dialog box created with JFrame, contains a few combo boxes, and has a JButton to then start the run0() function. This fails because the run0() ends up being called from the actionPerformed class, similar to below.
    public void actionPerformed(ActionEvent e)
    try
    run0();
    catch (Exception ex)
    System.out.println("Error..." + ex);
    }I've tried doing it with an anonymous inner class but the result is the same. Is there any way to detect a button click and act on it within the same function that creates the button?

    Vmtr wrote:
    I understand what you're suggesting but this would still require me to call the run0() function from within the listener class and (for whatever reason) the "IL." commands are ignored if they are not in a run0() function called directly from a run() function. I'm assuming that this is a quirk built in by the makers of Intralink and I am just trying to find a way around it.Something is happening behind the scenes, something that I don't see evidenced by your current code. Since Intralink is not your class, I guess it is impossible to create a true SSCCE. When I created an SSCCE based on your code, there were no problems:
    //import com.ptc.intralink.client.script.*;
    //import com.ptc.intralink.script.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    //import javax.swing.border.*;
    //import java.util.*;
    //import java.text.*;
    //import java.io.*;
    //import java.sql.*;
    //import com.ptc.intralink.ila.*;
    public class forum extends ILIntralinkScript
      ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface) getScriptInterface();
      private void run0() throws Exception
        JOptionPane.showMessageDialog(null, "In the run0 function!");
        IL.openWindow("Workspace", null, null); // recorded step: 1
        IL.selectTree("FTLOCALDB", "Local Database"); // recorded step: 2
      } // End of run0
      public void run() //throws Exception
        JButton button1 = new JButton("Done");
        button1.setPreferredSize(new java.awt.Dimension(310, 18));
        JFrame f = new JFrame("New Part Number");
        // add this so it exits nice:
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(360, 300);
        f.setResizable(false);
        Container content = f.getContentPane();
        content.add(button1);
        button1.addActionListener(new ActionListener()
          public void actionPerformed(ActionEvent ee)
            try
              run0();
            catch (Exception ex)
              System.out.println("Error..." + ex);
              ex.printStackTrace();
        f.setVisible(true);
      // get this all to run
      public static void main(String[] args)
        SwingUtilities.invokeLater(new forum());
    // dummy classes to allow for compilation
    abstract class ILIntralinkScript implements Runnable
      public ILIntralinkScriptInterface getScriptInterface()
        return new ILIntralinkScriptInterface();
    class ILIntralinkScriptInterface
      public void openWindow(String string, Object object, Object object2)
        JOptionPane.showMessageDialog(null, "in method openWindow(" + string + ", " + object + ", "
            + object2 + ")");
      public void selectTree(String string, String string2)
        JOptionPane.showMessageDialog(null, "in method selectTree(" + string + " ," + string2 + ")");
    }

  • GUI event handling problems appear in 1.4.1 vs. 1.3.1?

    Hi,
    Has anyone else experienced strange event handling problems when migrating from 1.3.1 to 1.4.1? My GUI applications that make use of Swing's AbstractTableModel suddenly don't track mouse and selection events quickly anymore. Formerly zippy tables are now very unresponsive to user interactions.
    I've run the code through JProbe under both 1.3 and 1.4 and see no differences in the profiles, yet the 1.4.1 version is virtually unusable. I had hoped that JProbe would show me that some low-level event-handling related or drawing method was getting wailed on in 1.4, but that was not the case.
    My only guess is that the existing installation of 1.3.1 is interfering with the 1.4.1 installation is some way. Any thoughts on that before I trash the 1.3.1 installation (which I'm slightly reluctant to do)?
    My platform is Windows XP Pro on a 2GHz P4 with 1GB RAM.
    Here's my test case:
    import javax.swing.table.AbstractTableModel;
    import javax.swing.*;
    import java.awt.*;
    public class VerySimpleTableModel extends AbstractTableModel
    private int d_rows = 0;
    private int d_cols = 0;
    private String[][] d_data = null;
    public VerySimpleTableModel(int rows,int cols)
    System.err.println("Creating table of size [" + rows + "," + cols +
    d_rows = rows;
    d_cols = cols;
    d_data = new String[d_rows][d_cols];
    int r = 0;
    while (r < d_rows){
    int c = 0;
    while (c < d_cols){
    d_data[r][c] = new String("[" + r + "," + c + "]");
    c++;
    r++;
    System.err.println("Done.");
    public int getRowCount()
    return d_rows;
    public int getColumnCount()
    return d_cols;
    public Object getValueAt(int rowIndex, int columnIndex)
    return d_data[rowIndex][columnIndex];
    public static void main(String[] args)
    System.err.println( "1.4..." );
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    Dimension size = new Dimension(500,500);
    panel.setMinimumSize(size);
    panel.setMaximumSize(size);
    JTable table = new JTable(new VerySimpleTableModel(40,5));
    panel.add(table);
    window.getContentPane().add(panel);
    window.setSize(new Dimension(600,800));
    window.validate();
    window.setVisible(true);
    Thanks in advance!!
    - Dean

    Hi,
    I've fixed the problem by upgrading to 1.4.1_02. I was on 1.4.1_01.
    I did further narrow down the symptoms more. It seemed the further the distance from the previous mouse click, the longer it would take for the table row to highlight. So, clicking on row 1, then 2, was much faster than clicking on row 1, then row 40.
    If no one else has seen this problem -- good! I wouldn't wish the tremendous waste of time I've had on anyone!
    - Dean

  • Question on program structure about event handling in nested JPanels in GUI

    Hi All,
    I'm currently writing a GUI app with a wizard included in the app. I have one class that acts as a template for each of the panels in the wizard. That class contains a JPanel called contentsPanel that I intend to put the specific contents into. I also want the panel contents to be modular so I have a couple of classes for different things, e.g. name and address panel, etc. these panels will contain checkboxes and the like that I want to event listeneres to watch out for. Whats the best way of implementing event handling for panel within panel structure? E.g for the the checkbox example,would it be a good idea to have an accessor method that returns the check book object from the innerclass/panel and use an addListener() method on the returned object in the top level class/panel. Or is it better to have the event listeners for those objects in the same class? I would appreciate some insight into this?
    Regards!

    MyMainClass.main(new String[] { "the", "arguments" });
    // or, if you defined your main to use varags (i.e. as "public static void main(String... args)") then you can just use
    MyMainClass.main("the", "arguments");But you should really extract your functionality out of the main method into meaningful classes and methods and just use those from both your console code and your GUI code.

  • GUI event handling of 1.4.1 vs. 1.3.1

    Hi,
    Has anyone else experienced strange event handling problems when migrating from 1.3.1 to 1.4.1? My GUI applications that make use of Swing's AbstractTableModel suddenly don't track mouse and selection events quickly anymore. Formerly zippy tables are now very unresponsive to user interactions.
    I've run the code through JProbe under both 1.3 and 1.4 and see no differences in the profiles, yet the 1.4.1 version is virtually unusable. I had hoped that JProbe would show me that some low-level event-handling related or drawing method was getting wailed on in 1.4, but that was not the case.
    My only guess is that the existing installation of 1.3.1 is interfering with the 1.4.1 installation is some way. Any thoughts on that before I trash the 1.3.1 installation (which I'm slightly reluctant to do)?
    Here's my test case:
    import javax.swing.table.AbstractTableModel;
    import javax.swing.*;
    import java.awt.*;
    public class VerySimpleTableModel extends AbstractTableModel
    private int d_rows = 0;
    private int d_cols = 0;
    private String[][] d_data = null;
    public VerySimpleTableModel(int rows,int cols)
    System.err.println("Creating table of size [" + rows + "," + cols +
    d_rows = rows;
    d_cols = cols;
    d_data = new String[d_rows][d_cols];
    int r = 0;
    while (r < d_rows){
    int c = 0;
    while (c < d_cols){
    d_data[r][c] = new String("[" + r + "," + c + "]");
    c++;
    r++;
    System.err.println("Done.");
    public int getRowCount()
    return d_rows;
    public int getColumnCount()
    return d_cols;
    public Object getValueAt(int rowIndex, int columnIndex)
    return d_data[rowIndex][columnIndex];
    public static void main(String[] args)
    System.err.println( "1.4..." );
    JFrame window = new JFrame();
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    Dimension size = new Dimension(500,500);
    panel.setMinimumSize(size);
    panel.setMaximumSize(size);
    JTable table = new JTable(new VerySimpleTableModel(40,5));
    panel.add(table);
    window.getContentPane().add(panel);
    window.setSize(new Dimension(600,800));
    window.validate();
    window.setVisible(true);
    Thanks in advance!!
    - Dean

    Hi,
    I've fixed the problem by upgrading to 1.4.1_02. I was on 1.4.1_01.
    I did further narrow down the symptoms more. It seemed the further the distance from the previous mouse click, the longer it would take for the table row to highlight. So, clicking on row 1, then 2, was much faster than clicking on row 1, then row 40.
    If no one else has seen this problem -- good! I wouldn't wish the tremendous waste of time I've had on anyone!
    - Dean

  • Where can I find an event handling for non gui purposes good tutorial

    Hello to all, I am searching the net for a good tutorial about java Event and Event handling that is not GUI related.
    All I find on the net are tutorial and examples that are related to GUI components the has pre defined events and handlers.
    please help me find good material to learn from.
    Appreciate it a lot.
    Dan

    I'd say goto the Java tutorial (www.thejavatutorial.com) and check up from there. Just because most event handleing is done in GUI's (swing comes to mind) doesn't imply its limited to that. For an example, check out the JavaBeans trail. Beans have ways to communicate with each other when (for example) a change in the bean occurs. Thats done through an event yet isn't related to GUI's in any way.

  • Mouse click on graph without event handling

    Is there a way to detect mouse click on a graph without the event handling? My base version of LabVIEW does not have event handling features.
    Thanks,
    Ryan
    Solved!
    Go to Solution.

    Leaving out the Event Structure seems like cruel and unusual punishment.  My scorn is divided about 80/20 between NI for selling it and whoever tried to save a few bucks by buying it and then sticking it to you to workaround.  Perhaps you are a student in which case you are free labor and it is all good.
    Maybe your boss is a purist and dislikes Event Structures because they break the dataflow paradigm.  The alternative is of course polling, and in this case you have plenty of data flowing!  Unfortunately 99.9% of it is worthless.  Here is a little example in LV8.2 (don't know your version) that uses polling to check on the mouse button.  I only added a simple check for the button being pressed, if you want to know click (down/up) you can add a shift register and look for transitions in the button.  I do check that the front panel is up front, otherwise it will still register clicks even though you may be surfing the web.
    Hopefully everything is in the base package.
    Attachments:
    MouseClickNoEvent.vi ‏26 KB

  • Event handling using CAN?

    I am aware of how to make LabView respond to user interface events (keyboard presses, button presses, mouse moves, etc) and I'm also aware that the same event handling structure can be used to handle external (non-GUI) events- like those generated by a digital edge on a DAQmx input.  My question is whether the same event handling structure can be used to handle external events coming in on a CAN network- via NI-CAN or otherwise?
    Is there a good reference which summarizes ALL general types of events that can be handled in this way- not just the standard GUI events?  I have a feeling that ActiveX and VISA are other ways to generate events, but can't find a good resource in general - or specifics on the NI-CAN side.
    Thanks!
    Nate 

    Thanks Mike-   still not sure I understand.  What should I wire to the Create User Event block in order for available events to show up in the dialog which allows me to configure events in a given frame?  For example, I have an external micro-controller communicating with LabVIEW using a CAN network.  Usually the communication is started by LabVIEW and sends commands out- but I also want to be able to handle asynchronous messages generated by this micro-controller in an event fashion without having do any polling.   Is there some reference I can wire to the Create User Event block which will make an event like "Incoming CAN Network Traffic" available to be handled in an event structure?
    Thanks again! 

  • The reflection answer to event handling?

    I have been playing with reflection answers to the question of how to handle ActionEvent events in Swing... like using a single instance of one member class as a reflection switch:
    private class Listener implements ActionListener {
         public void actionPerformed (ActionEvent action) {
              try {this.getClass().getMethod(action.getActionCommand(), new Class[0]).invoke(this, new Object[0]);}
              catch(Exception exception) {/* error handling code */}
         public void one() {/* do something */}
         public void two() {/* do something */}
    }No more hideous if/then structures and only one inner class. Just match the method names to the action commands and the two line switch handles everything. Much cleaner code and directories.
    I wrote a small example program that you can get the source for here:
    http://www.immortalcoil.org/drake/SmartFrameExample.java
    I can think of only two reasons not to do this right now:
    1) Event / listener mismatches you would have caught at compile time before (if using inner classes) become runtime errors, or if you improve upon the above with Class.getMethods() then dead actions (as with a classic switch).
    2) Inability to look yourself in the mirror or partake of Jesus's love.
    Still, the result is much prettier code and as long as you code it right it will work flawlessly. I am honestly considering using this.
    Thoughts?

    For simple GUIs with very few actions, your approach is obviously overkill. You want to preserve simplicity whenever possible without affecting performance.
    For mildly complex GUIs, I think your approach is good, but still doesn't solve the bigger problem of managing multiple components that use the same action. If you've got so many actions that you need reflection to reduce code, you probably have a GUI with menubars, toolbars, popup menus, and buttons that all perform the same set of actions. Now you have to register an ActionListener with each component, not to mention disabling an action, which involves finding every menu item and button corresponding to this action and disabling/enabling it. I realize this is a different problem than you were trying to solve, but it's worth considering.
    Well, Swing provides javax.swing.Action to handle just this problem, which more or less alleviates the need for your approach because you have an Action subclass for each action. But maybe the best solution for very complex GUIs is a combination of your approach with the Action approach by providing an ActionSet class, which centralizes event handling for all components. The ActionSet class would define for each action:
    1) a static String for the action command
    2) a static String for the tooltip
    3) a static Icon for the icon
    Now, when a new ActionSet is created, it uses reflection to read each of it's fields, creating a new Action subclass for that action and storing it in a HashMap using the action command for the key. The Action subclass just handles the event by forwarding it to a registered ActionListener on the ActionSet class. The ActionListener would implement your approach for reflection event-handling, thereby eliminating if/else/switch clauses.
    The GUI code can call a method "getAction(String actionCommand)" on the ActionSet to retrieve the Action subclass when creating the JMenuBar, JButton, JToolBar, JPopupMenu, etc. Then at any time in the application, you can call ActionSet.getAction(...).setEnabled(...) to enable/disable all components using that action.

  • Editable ALV: value transport before event handling

    Hi everybody,
    I'm really going crazy over this one: I'm developing an editable ALV using CL_GUI_ALV_GRID and I'm trying to check the entered data both on pressing enter and on pressing SAVE.
    Since I want to use the error log protocol I'm doing all of these check in the data_changed event handling. Now this is where it gets tricky: When a user enters a value and presses the SAVE button without pressing enter first, the following code is executed:
    CALL METHOD GOB_D1100_ALV02_GRID->CHECK_CHANGED_DATA
    So since I registered the data_changed event, will trigger the event handling BEFORE transporting the value from the GUI to the internal table. The value is only transfered after the data_changed event (where I want to make my checks because of the error protocol) is executed.
    How do I get my internal table updated before event handling?
    Best wishes,
    Ben

    YEHAW! I found a solution to my problem in this thread: editable alv: add custom validation and display "errors" in protocol list
    What you need to do is change your internal table yourself accordingly to the changes that you did on the ALV GRID.
    You can find the modified rows in table MP_MOD_ROWS of object P_ER_DATA_CHANGED.
    Then all you need to do is modify your internal table accordingly. Works like a charm (:
    FORM ALV_EVENT_DATA_CHANGED  USING P_ER_DATA_CHANGED TYPE REF TO CL_ALV_CHANGED_DATA_PROTOCOL
                                                                              P_SENDER.
      DATA: LTA_MOD_CELLS TYPE LVC_T_MODI.
      DATA: LST_MOD_CELLS TYPE LVC_S_MODI.
      FIELD-SYMBOLS: <LFS_MOD_ROWS> TYPE TABLE.
      LOOP AT P_ER_DATA_CHANGED->MT_MOD_CELLS INTO LST_MOD_CELLS.
        ASSIGN P_ER_DATA_CHANGED->MP_MOD_ROWS->* TO <LFS_MOD_ROWS>.
        READ TABLE <LFS_MOD_ROWS> ASSIGNING <FS_D1100_ALV02_DATA> INDEX LST_MOD_CELLS-TABIX.
        MODIFY GTA_D1100_ALV02_DATA FROM <FS_D1100_ALV02_DATA> INDEX LST_MOD_CELLS-ROW_ID.
      ENDLOOP.
    Thank you very much for your assitance
    Ben

  • Problem with event handling

    Hello all,
    I have a problem with event handling. I have two buttons in my GUI application with the same name.They are instance variables of two different objects of the same class and are put together in the one GUI.And their actionlisteners are registered with the same GUI. How can I differentiate between these two buttons?
    To be more eloborate here is a basic definition of my classes
    class SystemPanel{
             SystemPanel(FTP ftp){ app = ftp};
             FTP app;
             private JButton b = new JButton("ChgDir");
            b.addActionListener(app);
    class FTP extends JFrame implements ActionListener{
               SystemPanel rem = new SystemPanel(this);
               SystemPanel loc = new SystemPanel(this);
               FTP(){
                       add(rem);
                       add(loc);
                       pack();
                       show();
           void actionPerformed(ActionEvent evt){
            /*HOW WILL I BE ABLE TO KNOW WHICH BUTTON WAS PRESSED AS THEY
               BOTH HAVE SAME ID AND getSouce() ?
               In this case..it if was from rem or loc ?
    }  It would be really helpful if anyone could help me in this regard..
    Thanks
    Hari Vigensh

    Hi levi,
    Thankx..
    I solved the problem ..using same concept but in a different way..
    One thing i wanted to make clear is that the two buttons are in the SAME CLASS and i am forming 2 different objects of the SAME class and then putting them in a GUI.THERE IS NO b and C. there is just two instances of b which belong to the SAME CLASS..
    So the code
    private JButton b = new JButton("ChgDir");
    b.setActionCommand ("1");
    wont work as both the instances would have the label "ChgDir" and have setActionCommand set to 1!!!!
    Actually I have an array of buttons..So I solved the prob by writting a function caled setActionCmdRemote that would just set the action commands of one object of the class differently ..here is the code
    public void setActionCommandsRemote()
         for(int i = 0 ; i <cmdButtons.length ; i++)
         cmdButtons.setActionCommand((cmdButtons[i].getText())+"Rem");
    This just adds "rem" to the existing Actioncommand and i check it as folows in my actionperformed method
         if(button.getActionCommand().equals("DeleteRem") )          
                        deleteFileRemote();
          else if(button.getActionCommand().equals("Delete") )
                     deleteFileLocal();Anyway thanx a milion for your help..this was my first posting and I was glad to get a prompt reply!!!

  • Event Handler/Cr​eate User Event bug

    This is a problem I've run into a few times on my system (Win2k) so I finally went back and reproduced it step by step since it wasn't too hard. It causes LabVIEW to crash and exit without saving.
    - Create an Event Handler
    - Place 'Register Events', wire output to dynamic event terminal
    - Place 'Create User Event', wire output to 'Register Events'/User Event
    - Place an Empty String Constant [""], wire to input of 'Create User Event'
    - Set empty string property -> Visible Items > Label = True
    - Rename label from "Empty String Constant" to other such as "Event"
    OR
    - Create a cluster constant with something in it
    OR
    - Place a boolean constant
    - Set boolean property -> Visible Items > Label = True
    - Name label something su
    ch as "Event"
    - 'Add Event Case...' to the Event Handler, select Dynamic / : User Event
    - Delete the constant wired to 'Create User Event'.
    - Place a constant of a different data type and wire it to the input of 'Create User Event'
    LabVIEW immediately disappears (all changes are lost) and this error is displayed:
    ================================
    LabVIEW.exe has generated errors and will be closed by
    Windows. You wlil need to restart the program.
    An error log is being created.
    ================================
    If there is a more appropriate place to post things of this nature that don’t really add to the discussion group, but need to be brought to the attention of NI, please post a URL or submittal method. Thanks...

    Thanks for the detailed request. We are aware of this exact issue, and the problem was actually fixed for LabVIEW 7.0 for Mac/Unix. Unfortunately, it did not get fixed for the initial release of LabVIEW 7.0 for Windows, but we have plans to include the fix in the first LabVIEW patch for 7.0.
    Also, the Discussion Forum is great for notifications of this kind. For future reference, you also have the options of emailing NI engineers directly, or calling us with suspected bug fixes, if you would like more direct communication.
    Thanks again, and have a great day!
    Liz Fausak
    Applications Engineer
    National Instruments
    www.ni.com/support

  • 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 handling in Dynpage

    Hi all,
    This is my first post in SDN.
    Can any one tell me how to submit a form in DYNPAGE via radio button. If I check the radio button on, it should submit the form and should return the same page.
    Appreciate you help.
    Thanks,
    Karthik

    Hi,
    The following code regarding Event Handling for Dynpage. May be this example code useful for you.
    package com.customer.training;
    import com.sapportals.htmlb.Button;
    import com.sapportals.htmlb.Component;
    import com.sapportals.htmlb.DropdownListBox;
    import com.sapportals.htmlb.Form;
    import com.sapportals.htmlb.FormLayout;
    import com.sapportals.htmlb.GridLayout;
    import com.sapportals.htmlb.InputField;
    import com.sapportals.htmlb.Label;
    import com.sapportals.htmlb.TextView;
    import com.sapportals.htmlb.enum.ButtonDesign;
    import com.sapportals.htmlb.enum.TextViewDesign;
    import com.sapportals.htmlb.event.Event;
    import com.sapportals.htmlb.page.DynPage;
    import com.sapportals.htmlb.page.PageException;
    import com.sapportals.htmlb.rendering.IPageContext;
    import com.sapportals.portal.htmlb.page.PageProcessorComponent;
    public class Suresh_SearchDynPage extends PageProcessorComponent {
      public DynPage getPage() {
        return new Suresh_SearchDynPageDynPage();
      public static class Suresh_SearchDynPageDynPage extends DynPage {
         public int flag ;
         public final static int disp_info = 1;
         public final static int read_info = 2;
         public final static int error_info = 3;
         public static String flag_info = "MyFlag";
         public static String disp_drop = " ";
         public String errorMessage;
           String firstName ;
           String lastName ;
           String Email ;
           String dropsel;
    Initialization code executed once per user.
        public void doInitialization() {
                        flag = read_info;          
                        IPageContext ctx = this.getPageContext();
                        ctx.setAttribute("FirstName","");
                        ctx.setAttribute("LastName","");
                        ctx.setAttribute("email","");     
    Input handling code. In general called the first time with the second page request from the user.
        public void doProcessAfterInput() throws PageException {
              Component comp;
              comp = this.getComponentByName("FirstName");
              if (comp instanceof InputField)
                        firstName = ((InputField) comp).getString().getValue();
              comp = this.getComponentByName("LastName");
              if (comp instanceof InputField)
                                  lastName = ((InputField) comp).getString().getValue();
              comp = this.getComponentByName("email");
                        if (comp instanceof InputField)
                                            Email = ((InputField) comp).getString().getValue();
              comp = this.getComponentByName("DisplayType");
                        if (comp instanceof DropdownListBox)
                             dropsel = ((DropdownListBox) comp).getSelection();          
    // Store the selected values in corresponding field name for nextScreen                         
              IPageContext ctx = this.getPageContext();
              flag = new Integer(ctx.getAttribute(flag_info).toString()).intValue();
              ctx.setAttribute("FirstName",firstName);
              ctx.setAttribute("LastName",lastName);
              ctx.setAttribute("email",Email);
              ctx.setAttribute("DisplayName",dropsel);                                   
    Create output. Called once per request.
        public void doProcessBeforeOutput() throws PageException {
          Form myForm = this.getForm();
           this.getPageContext().setAttribute(flag_info,new Integer(flag));
         switch(flag)
          case read_info:
                    FormLayout f1 = new FormLayout();
                    TextView t1 = new TextView();
                    t1.setDesign(TextViewDesign.HEADER2);
                    t1.setText("This is the Info U Entered................");
                    TextView t2 = new TextView();
                    t2.setText(firstName);
                    Label dispFname = new Label("dispFirstName");
                    dispFname.setText("First Name");
                    dispFname.setLabelFor(t2);
                    TextView t3 = new TextView();
                    t3.setText(lastName);
                    Label dispLname = new Label("dispLastName");
                    dispLname.setText("Last Name");
                    dispLname.setLabelFor(t3);
                    TextView t4 = new TextView();
                    t4.setText(Email);
                    Label dispEmail = new Label("dispEmail");
                    dispEmail.setText("Email");
                    dispEmail.setLabelFor(t4);
                    TextView t5 = new TextView();
                    t5.setText(dropsel);
                    Label dispType = new Label("dispInfo");
                    dispType.setText("Display Info");
                    dispType.setLabelFor(t5);
                    Button btnback = new Button("Back");
                    btnback.setText("Back");
                    btnback.setOnClick("Back");
                    f1.addComponent(1,1,t1);
                    f1.addComponent(2,1,dispFname);
                    f1.addComponent(2,2,t2);
                    f1.addComponent(3,1,dispLname);
                    f1.addComponent(3,2,t3);
                    f1.addComponent(4,1,dispEmail);
                    f1.addComponent(4,2,t4);
                    f1.addComponent(5,1,dispType);
                    f1.addComponent(5,2,t5);
                    f1.addComponent(6,1,btnback);
                    myForm.addComponent(f1);
               break;
          case error_info:
                    FormLayout f2 = new FormLayout();
                    IPageContext ctx = this.getPageContext();
                    TextView t6 = new TextView();
                    t6.setText("Error : ");
                    t6.setDesign(TextViewDesign.HEADER2);
                    t6.setText(errorMessage);
                    f2.addComponent(3,1,t6);
                    myForm.addComponent(f2);
               break;
                default:
                              // create your GUI here....
                                        GridLayout g1 = new GridLayout();
    //                                    IPageContext ctx1 = this.getPageContext();
                                        Label first_l = new Label("First Name");
                                        InputField first_if = new InputField("FirstName");
                                        Label last_l  =  new Label("Last Name");
                                        InputField last_if = new InputField("LastName");
                                        Label email_l = new Label("E-Mail Address");
                                        InputField email_if = new InputField("email");
                                        Label info_l = new Label("Display Info for");
                                        DropdownListBox displayType = new DropdownListBox("DisplayType");
                                        displayType.addItem("userinfo", "User Info");
                                        displayType.addItem("groupinfo", "Group Membership");
                                        displayType.addItem("roleinfo", "Role Assignment");     
    //                                    displayType.setSelection(ctx1.getAttribute("DisplayType").toString());
                                        Button btn = new Button("submit");            
                                        btn.setText("Get Info");
                                        btn.setDesign(ButtonDesign.EMPHASIZED);
                                        btn.setOnClick("Get");
    //                                    add the ui controls to grid
                                        g1.setCellPadding(4);
                                        g1.addComponent(1,1,first_l);
                                        g1.addComponent(1,2,first_if);
                                        g1.addComponent(2,1,last_l);
                                        g1.addComponent(2,2,last_if);
                                        g1.addComponent(3,1,email_l);
                                        g1.addComponent(3,2,email_if);
                                        g1.addComponent(4,1,info_l);
                                        g1.addComponent(4,2,displayType);
                                        g1.addColSpanComponent(5,1,btn,2);
                                        g1.setHeightPercentage(50);
                                        g1.setColumnSize(50);
                                        myForm.setFocusedControl(displayType);
                                        myForm.setMessageBarAtFormEnd(true);
                                        myForm.setWidthInHundredPercent(true);
                                        myForm.addComponent(g1);     
                                        break;
        public void onGet(Event e)
         if(firstName.length()== 0)
              flag = error_info;
              errorMessage = "Invalid Input..............";
         else
              flag = read_info;
          public void onBack(Event e1)
                flag = disp_info;

Maybe you are looking for

  • Returning a string from one class to another

    I have a file from where i creating an object of another class and calling the fuctionsl This is how i am doing public login() String input =new String (passwordField.getPassword());      input= input.trim(); tempuser= userField.getText();           

  • Payment budget not checked in MIGO against last years PO

    We are using Former Budgeting. We have customised specific tolerance (OF23) to generate error message when budget exceeds 100% against payment budget. (not commitment budget). Now we have a scenario: Purchase order was created in the last year. Good

  • Oracle BAM server doesn't start up

    Hi, I have a BAM server in a cluster and start up sometimes and not others. When started shuts down unexpectedly. Logs files doesn't show errors. ============================================================================================= startWebLo

  • Increasing Output Volume?

    Hello all, I have a 15" macbook pro that I purchased over the summer. I've noticed that my volume doesn't go nearly as high as my friend's macbook pro, and he has an 13" model that is older than mine. Is there any way I can increase my maximum output

  • Formbuilder where does it work for sure?

    I am finding that it is not true that formbuilder (11.1.1.4) is not compatible with 2008 r2 64 bits.... yet. I fear I will find out why it's not certified... sooner or later... But it is working with everything that should not work. 2008 r2 64 bits a