Button Event Help

Hi, I have created a Frame that the user can draw in. It is a separate class that I call in my main program from a different file. I have a button on my frame that I want to run a method to save the graphical contents of the frame as a type Image. This works fine, and I have created the image. Now I need to return the image to my main program somehow. I want it only to return to my main when the button is pressed. The actionPerformed cannot contain a return statement, and I cannot call a getImage (from the frame) in my main anyway, because I want it to be initiated by the button push, which is located in the Frame file and not in the main. Can anyone help me? I will post the code. Ignore the Picture and InterruptedException in my actionPerformed class, they just convert the image in other classes, but they're not important. An explanation to return the image would be perfect.
Here is my main:
class LoadPictures
    public static void main (String [] args) throws IOException, InterruptedException, AWTException
        PaintArea pa = new PaintArea ();
        pa.loadArea (pa);
Picture pic= pa.getPic() //<---false method. This is what I want to happen when you click the button in the frame.
    }}Here is my frame, entitled PaintArea:
import java.awt.*;
import java.awt.event.*;
import java.io.*;
class PaintArea extends Frame
    static int x, y;
    static Graphics g;
    PaintArea ()
        addWindowListener (new WindowAdapter ()
            public void windowClosing (WindowEvent e)
                hide ();
        setSize (400, 400);
        setVisible (true);
        g = getGraphics ();
    public void loadArea (PaintArea pa)
        Button button = new Button ("Save");
        // pa.add (button);
        button.setSize (2, 2);
        pa.show ();
        final PaintArea pa2 = pa;
        button.addActionListener (new ActionListener ()
            public void actionPerformed (ActionEvent ae)
                try
                    Image image = pa2.saveScreen (pa2);
                    //Picture pic = new Picture (pa2);
                catch (AWTException e)
                    System.err.println (e);
                    System.exit (1);
                // catch (InterruptedException ie)
                //     System.err.println (ie);
                //     System.exit (1);
        pa.addMouseListener (new MouseAdapter ()
            public void mousePressed (MouseEvent me)
                x = me.getX ();
                y = me.getY ();
                g.fillOval (x - 5, y - 5, 10, 10);
        pa.addMouseMotionListener (new MouseMotionAdapter ()
            public void mouseDragged (MouseEvent me)
                x = me.getX ();
                y = me.getY ();
                g.fillOval (x - 5, y - 5, 10, 10);
    public Image saveScreen (PaintArea pa) throws AWTException
        Image image = createImage (new Robot ().createScreenCapture (pa.getBounds ()).getSource ());
        return image;
}Thank you very much, everyone!!

When you open the frame, use wait() to suspend action in the main program. When the button is pressed, call notify() on the same object. Then the focus is back in the main program's code.

Similar Messages

  • Opening dbs thru button events, help, i`m a newbie..

    i have the following fn for opening the db
    public static void main(String args[]) throws Exception
    new login(new javax.swing.JFrame(), true).show();
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    open();
    select();
    static void open() throws SQLException
    // ODBC data source name
    String dsn = "jdbc:odbc:dslogin";
    String user = "";
    String password = "";
    // Connect to the database
    con = DriverManager.getConnection(dsn, user, password);
    // Shut off autocommit
    con.setAutoCommit(false);
    static void select() throws SQLException
    Statement stmt; // SQL statement object
    String query; // SQL select string
    ResultSet rs; // SQL query results
    boolean more; // "more rows found" switch
    query = "select user,password from dblogin";
    stmt = con.createStatement();
    rs = stmt.executeQuery(query);
    // Check to see if any rows were read
    more = rs.next();
    if (!more) {
    System.out.println("No rows found.");
    return;
    // Loop through the rows retrieved from the query
    while (more)
    // System.out.println("kkkk");
    System.out.println("umm" + rs.getString("user"));
    System.out.println("ummmm" + rs.getString("password"));
    more = rs.next();
    rs.close();
    stmt.close();
    now my problem is this..while the above open and select fns work fine in void main, i`m trying to open the db upon clicking a button..heres what i tried to do :
    cmdsubmit.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    cmdsubmitActionPerformed(evt);
    private void cmdsubmitActionPerformed(java.awt.event.ActionEvent evt) {
    open();
    seelct();
    when i try it i get the error message exceptions must be caught or throw or sumthing like that and i`m new to java so i`ve no idea how to go about doing it..help please..

    On JDBC:
    You only need to register a driver with the DriverManager once, and this is done (by JDBC conform drivers) when the driverclass is loaded. You may want to do this in a static initializer:
    import java.sql.*;
    class MyClass{
        static {
            try {
                // load driver class, which automatically registers itself
                Class.forName("sun.jdbc....");
            } catch(Exception ex) { /* handle it, throw error */ }
        // later
        Connection con = DriverManager.getConnection(...);
    }Even better is NOT to hard-code the driver at all. Use
    java -Djdbc.drivers=sun.jdbc.odbc.JdbcOdbcDriver;oracle.jdbc.OracleDriver MyClassinstead.
    Fritz

  • How to Capture Button event on TrainBean navigation

    Hi All
    i m being required to capture a button event in train bean Navigation, i m doing customization in Iexpense Module,here in Create IExpenseReport i need to capture the events of Remove,Return etc.how is it possible any clue would be very helpful.
    Thanx
    Pratap

    try this..
    if (GOTO_PARAM.equals(pageContext.getParameter(EVENT_PARAM))
    "NavBar".equals(pageContext.getParameter(SOURCE_PARAM))
    // This condition checks whether the event is raised from Navigation bar
    // and Next or Back button in navigation bar is invoked.
    int target = Integer.parseInt(pageContext.getParameter(VALUE_PARAM));
    // We use the parameter "value" to tell use the number of
    // the page the user wants to visit.
    String targetPage;
    switch(target)
    case 1: targetPage = "/oracle/apps/dem/employee/webui/EmpDescPG"; break;
    case 2: targetPage = "/oracle/apps/dem/employee/webui/EmpAssignPG"; break;
    case 3: targetPage = "/oracle/apps/dem/employee/webui/EmpReviewPG"; break;
    default: throw new OAException("ICX", "FWK_TBX_T_EMP_FLOW_ERROR");
    HashMap pageParams = new HashMap(2);
    pageParams.put("empStep", new Integer(target));
    pageContext.setForwardURL("OA.jsp?page=" + targetPage,
    null,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    pageParams,
    true, // Retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO, // Do not display breadcrumbs
    OAWebBeanConstants.IGNORE_MESSAGES);
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Not able to capture button event in extended controller

    Hi Gurus,
    I am not able to capture the button event (of seeded controller) in extended controller.
    I have written code in extended controller like below:
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean){
        String str = pageContext.getParameter("event"); // copied from seeded controller for the button event //
          if ("editLines".equals(str)) {
            //cutom validation
      super.processFormRequest(pageContext, webBean);
    Please help me in resolving the issue.
    Thanks,
    Srinivas
        ///my cutom validateion

    Hi Bm,
    Thanks for your response.
    I have tried the same but no luck.
    Please help in getting this resolved.
    Thanks,
    Srinivas

  • How to get a form field valud in delete PL/SQL Button Event Handler

    Hi Friend,
    I have a form. when user clicks delete button. we want to remove system dodelete function
    and add a delete script
    Under delete-top category,
    how can I get value of form EVENT_NUMBER field in form at delete PL/SQL Button Event Handler?
    DELETE FROM PTEAPP.PTE_EVENTS WHERE eventnumber = EVENT_number
    But when I try to save this form and get message as
    1721/15 PLS-00201: identifier 'EVENT_NUMBER' must be declared
    Thanks for any help!
    newuser

    I did something similar but wasn't using a stored procedure. Couldn't you set a flag variable once you know you're not doing the insert and in the "before displaying the form" section put an IF to check if your flag was set, and if so do an HTP.Print('You are overpaid buddy!');
    Then just reset your flag.

  • Few seconds of processing & button events

    Hi,
    i have a 'theory' question -
    some feature of my app has a bit long processing time, about a few seconds, in which there's an activity indicator running.
    this processing should start after the user pressed some "start process" button.
    my question is -
    is it good or bad or neither to do this large processing issue from within the button's event method (the one connected to "TouchUpInside" event for example, or there's a better way to use events to signal other parts of the application to do that processing.
    the reason i ask this is when i do the processing from within the buttons event method, the button is highlighted and than remains highlighted until all the process is done.it seems that the highlight is there until the button's event method finished.
    i hope i explained myself clearly enough.
    thanks a lot.

    nkobik wrote:
    is it good or bad or neither to do this large processing issue from within the button's event method
    The problem in this case isn't which method starts the long process. No matter where you run that task, it's going to freeze the UI until you get it out of the main thread. Running the process in the action method makes the problem more noticeable since the button's state can't change until the process completes, but freezing the UI is never acceptable even if some users don't notice it. I.e. even if the app has nothing useful to do until the long process completes, the controls should still respond normally, if only to pop up an alert asking the user to be patient. Generally the user should also have the opportunity to cancel a long process, which isn't going to be possible with a frozen UI.
    So it looks like you need to bite the bullet and use some kind of concurrent operation. I think the choice will depend in part on your experience and preference. If you're comfortable with threaded programming, starting a helper thread to run the long process might be the easiest for you. However the SDK supports higher level concurrency management, and if you're not familiar with the NSOperation classes you might want to look over the Concurrency Programming Guide.
    Whatever approach you decide on, let us know if you need help with it, and I'm sure someone around here will be able to advise you.
    \- Ray

  • PPR AND Button EVENT

    Dear All
    When I do exercises of OAF, I have one problem and can not deal with it. Any one can help me?
    I make a page, there are a messageTextInput component and a button named help in the page.
    I add a ppr to messageTextInput. When input many words seperated by comma(123,123), when cursor click any other places in the page except [help], I want to make the [help] button disabled. When input only one word, I could click the [help] to forward to another page.
    But after I input many words into messageTextInput, and directly click [help], then the [help] come to disable and next forward to another page.
    In order to avoid forward to another page, I add a error message in the help event.
    Now The strange thing happened. Sometimes the message appears and the [help] is disabled. Sometimes the [help] is disabled but message does not appear.
    Why this happens and how to fix it?

    Alex,
    Share the Steps & the code you have done.
    Regards,
    Gyan

  • Button AS help!

    Hi.
    I've tried numerous ways but I cant seem to find the right
    script to make a movie clip play on release of a button in a
    different movie clip.
    Thanks in advance for any help!

    make sure that the motion tween goes from frame 2 ->
    whatever frame you want.
    make a key frame in frame 1 & in action script put
    "stop()". when you do a button event use the
    gotoAndPlay()
    call.

  • Loading Flash Paper swf causes all other button events to fail

    Hi Everyone,
    I have created a project with Flash which I am using Zinc to publish as a projector for both Macs and Pcs. Now, in this app I am loading a pdf document converted to a Flash Paper swf. The moment I load this swf file into my project, it appears as though all other button events fail. If I remove the code which loads in the flash paper swf, all buttons function as expected.
    Can anyone please help me with a reason / solution for this?
    Any help is greatly appreciated!
    Cheers!

    Did that and there were no errors shown at any point, such as when publishing the .apk file.
    I found a solution. I was under the impression I needed to use touch events for it to work on a tablet, and changing those to normal mouse events solved the problem. Still not sure why it wouldn't work the other way, but for now it works as needed.
    Thanks!

  • How can a new button Event open sales order

    CRM WEB UI issue.
    On assignment Block there is a New button , on New button Event i have to open sales order .
    Please help me.
    Thanks in advance .
    Kumar6

    Hi Kumar,
    Whenever you got any requirement then find out on Web UI how they have done it. As now you want to show sales order then first find out Component name for Sales order.
    So Go to transaction u2018CRM_UIu2019. Chose u2018SalesProu2019 as a Role.  In Navigation Bar click on u2018Sales Cycleu2019  and in Second level link there is u2018Sales Orderu2019. Click on it. Check  it is a screen you want on your button click.
    If yes then you need to find its Technical Data (details). So click inside Work Area and press u2018F2u2019 key.
    Then you will get UI component name, View name , Context name, Role key, etc. So you have to pick that UI Component name and give it in Transaction Code  u2018CMP_WD_BSPWBu2019.
    Now Go To  u2018Run Time Repositoryu2019 , In Component Interface They have created u2018Component Interfaceu2019 that you need to call in your Button click event. If you donu2019t know use of u2018Component Interfaceu2019 then first read it else its good for you.
    Well next time when you will write any Question, In Subject write it in One line so that all can see in list and answer you quickly.
    Thanks,
    Durgesh Pagar.

  • On Browsers refresh/ back button event   terminate user session

    I have a problem pls help me to solve this.
    Requirement is :
    I need to catch browser's [b]refresh back button event.
    Actually I need to terminate his session/login
    when user clicks on browser's refresh button
    and send user on Login page something like banking application(e.g. ICICI Bank) when u logged in ICICI bank side in between if u click on browser's refresh it shows message "Your session terminated " something like that.
    So i want same functinality after user click on Refresh terminate his session

    in my page i am inserting new data and updating existing data
    so for inserting data againe page get submitted so for inserrion time alos these onload & Onunload events get fired
    i tried this but still proble is unsolved..
    give some more ways to solve this

  • A button event ????

    in a button event ,i invoke the thread method strat() ,but it give me these wrong.help.plz!!
    java.lang.NullPointerException
         at com.sun.PlayerApplet.jButton1_actionPerformed(PlayerApplet.java:239)
         at com.sun.PlayerApplet_jButton1_actionAdapter.actionPerformed(PlayerApplet.java:388)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
         at java.awt.Component.processMouseEvent(Component.java:5134)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    The stack trace tells you the exact line where your null pointer exception (NPE) occurred.
    An NPE means that you tried to reference a member from a null reference.
    Look in your source file PlayerApplet.java at line 239 and see if you can tell which reference has never been initialized, or has been initialized to null, or set to null.
    � {�                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Creating button event

    Hi there,
    1) I have button and I want to create WhenClikMouse event occurs when click on it from the forms. I'm trying to create button event in PJC, ANYBODY can help?!,,
    2) and where should I save the JavaBean class to call it successfuly from the forms (I'm working on oracle 9i and Jdeveloper 9.2).

    Hi there,
    1) I have button and I want to create WhenClikMouse
    event occurs when click on it from the forms. I'm
    trying to create button event in PJC, ANYBODY can
    help?!,,
    2) and where should I save the JavaBean class to call
    it successfuly from the forms (I'm working on oracle
    9i and Jdeveloper 9.2).Hi - I'd post this to the "Forms" forum on OTN since this is a question about Pluggable Java Components which are a specific (and mighty cool) feature of forms.
    There's also some viewlets and documentation from the Forms section on OTN (http://otn.oracle.com/products/forms) and the how-to debug PJC technical note (http://otn.oracle.com/products/forms/htdocs/howto_debug_pjc.html).
    -steve-

  • Unable to capture button event in pageLayout Controller

    Hi Guys,
    I have the following layout
    pageLayout
    pageLayoutCO (controller)
    ----header (Region)
    ----------messageComponentLayout (Region)
    -----------------MessageLovInpurt
    -----------------MessageChoice(Item)
    -----------------MessageTextInput
    -----------------MessageLayout
    ----------HideShow (Region)
    -----------------MessageLovInpurt(Item)
    -----------------MessageChoice(Item)
    -----------------MessageTextInput(Item)
    -----------MessageComponentLayout (Region)
    -----------------MessageLayout
    ------------------------SubmitButton(ID:SearchBtn)
    ------------------------SubmitButton(ID:ClearBtn, fires partial action named clear)
    -----------header(Region)
    I am not able to capture the event fired by the button ClearBtn in the controller of the pagelayout.....
    The two methods I used as follows aren't worked:
    if ("clear".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM)))
    if (pageContext.getParameter("ClearBtn") != null) {
    what should i do in order to capture the button event in the pageLayout Controller
    Thanks in advance
    Mandy
    Edited by: user8898100 on 2011-8-2 上午7:49

    Mandy,
    Its really strange that its not able to caputure the event in CO.
    Below is the way in which we handle to Submit action at CO level.
    /Check whether ClearBtn is same in case too.
    if(pageContext.getParameter("ClearBtn")!=null){
    System.out.println("Inside the Clear Btn Action");
    Regards,
    Gyan

  • Not able to capture button event in pageLayout Controller

    Hi Guys,
    I have the following layout
    pageLayout ------------------------ pageLayoutCO (controller)
    ----messageComponentLayout (Region)
    ----------messageComponentText (item)
    ----------messageComponentText (item)
    ----------messageComponentText (item)
    ----------messageLayout (Region)
    ----------------header(Region)
    ----------------------button (item) (say BTN1) (fires partial action)
    I am not able to capture the event fired by the button BTN1 in the controller of the pagelayout..... but if i set a controller at the messageComponentLayout iam able to capture the event.
    what should i do in order to capture the button event in the pageLayout Controller
    Thanks in advance
    Tom.

    Tom,
    Two things:
    1)The button ur using is of type submitbutton or button?.In this scenario it should be button.
    2)The correct coding practice is using:
    if("QUERY".equals(pageContext.getParameter(OAWebBeanConstants.EVENT_PARAM)))
    instead of
    String _event = pageContext.getParameter("event");
    if("QUERY".equals(_event))
    because you never know if Oracle in any upgrade or patch change the value of the constant EVENT_PARAM in class OAWebBeanConstants.
    3)If first point is followed by you, just match the exact event name in code and in property inspector for the button.
    --Mukul
    --Mukul                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • HD options?

    so, HD camcorders are in an affordable range (thinking the canon HV30) and iMovie can edit HD (i assume that since iMovie 6 HD could, that iMovie 8 can). what are the options to output HD? it seems as if iM 8 is geared to web production, can it produ

  • Creation of an ERP Sales Order or ERP Quotation from CRM Opportunity

    Hello Experts, The scenario is as follows: I have done the cross-system copy control of transaction types and item categories to enable ERP Quotation and ERP Sales Order creation from CRM Opportunity.  However, after saving the CRM Opportunity, when

  • How to set default JPEG options?

    In Photoshop Elements 10, is it possible to configure the JPEG options to default settings so that the JPEG Options dialog box does not open each time I rename a JPG file using FILE-SAVE AS?

  • What is the Charging time for 4th generation iPad when fully discharged?

    Hi, I just want to know the 4th generation iPad charging time with 12 volts Charger when fully discharged? Thanks, Srinivas

  • Oracle Process Manufacturing Release 11i

    Hi there, Is there a free version of Oracle Process Manufacturing 11i for download? If so what is the site? Thanks. Regards, Leon