JSpinner - Increment or decrement button pressed?

Hi Folks,
I have a JSpinner component which can only be updated through the increment/decrement buttons.
To validate the value before updating the UI, I need to verify the next value. So how do I determine if the user clicked the increment or the decrement button?
Also, the sequence of valid values that the JSpinner can display is not linear but changes based on the previous value.
For eg, the valid values are 4, 5, 8, 12, 17.. to a max of 300
Thanks

Thanks for that link Michael. It helped a bit.. However, I'm stuck in the checkChange method. My slightly modified code is as follows:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
     JSpinner spinner;
     final int MIN = 0, MAX = 100;
     public void buildGUI()
          JPanel p = new JPanel();
          spinner = new JSpinner(new SpinnerNumberModel(MIN,MIN,MAX,1));
          ((JSpinner.DefaultEditor)spinner.getEditor()).getTextField().setEditable(false);
          spinner.setUI(new ChangeVerifierUI());
          p.add(spinner);
          JFrame f = new JFrame();
          f.getContentPane().add(p);
          f.pack();
          f.setLocationRelativeTo(null);
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setVisible(true);
     class ChangeVerifierUI extends javax.swing.plaf.basic.BasicSpinnerUI
          protected Component createNextButton()
               JButton nextButton = (JButton)super.createNextButton();
               nextButton.removeMouseListener(nextButton.getMouseListeners()[0]);
               nextButton.addMouseListener(new MouseAdapter(){
                    public void mousePressed(MouseEvent me){
                         if(((Integer)spinner.getValue()).intValue() < MAX) checkChange(+1);
               return nextButton;
          protected Component createPreviousButton()
               JButton previousButton = (JButton)super.createPreviousButton();
               previousButton.removeMouseListener(previousButton.getMouseListeners()[0]);
               previousButton.addMouseListener(new MouseAdapter(){
                    public void mousePressed(MouseEvent me){
                         if(((Integer)spinner.getValue()).intValue() > MIN) checkChange(-1);
               return previousButton;
     public void checkChange(int direction)
//          int result = JOptionPane.showConfirmDialog(null,"Are you sure you want to row setting ?",
//                    "Setup", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
          System.out.println("Verification code comes here");
//Only to create delay for standalone testing
          for(int i=0; i<1000; i++) {
               for (int j=0; j<10000; j++) {
                    int ttemp = i*j;
//          if (result == JOptionPane.YES_OPTION) spinner.setValue(
//                    ((Integer)spinner.getValue()).intValue()+
//                    (((Number)((SpinnerNumberModel)spinner.getModel()).getStepSize()).intValue())*direction);
     public static void main(String[] args)
          SwingUtilities.invokeLater(new Runnable(){
               public void run(){
                    new Testing().buildGUI();
}I noticed that the sys-out prints only once and then the JSpinner value continues to increment. How would one modify that behavior to say print (or in the actual case, make a call on a library for verification of the value) for each increment before the value is set on the UI?
Thanks a lot for your help so far :)

Similar Messages

  • Increment and decrement buttons on a ring control are greyed out

    Hello,
      The check box for showing the increment and decrement buttons on a ring control are greyed out. Does anyone know why? I have verified that the ring is a control as opposed to a indicator.
    Regards,
    Kaspar
    Regards,
    Kaspar

    "the controls are greyed out because they do not exist on the Menu ring control."
    Errr... yes, I believe that's exactly what I said in my last response.
    "This is different from what I saw in another part of this forum about using event structures on a Menu ring."
    Don't know what you could be referring to, as there is no event specific to the increment/decrement controls. All that they would do (if they existed) is to change the value of the control, and the applicable event would be the "Value changed" event. Where exactly did you read this?

  • With Traditional NI-DAQ Compatibility VI's the acquisition locks when I press the increment or decrement button of a numeric control.

    Hello all.
    I´m using a PCI-6220 and the Traditional NI-DAQ Compatibility VI's to make the acquisition that is in the attached VI. But when I click the increment/decrement button on the numeric controls my acquisition stops. In the same PC I made the same experience with a 6040 and I could not see this problem. I tried with the PCI-6220 with the DaqMX VI's and I could not see this problem too, for these reasons I believe that the problem has something to do with the Traditional NI-DAQ Compatibility VI's.
    I built machines that can have one or the other board (depending if it is low-end or normal). Does somebody knows the solution for this problem?
    Thanks in advance.
    Paulo Carmo
    Attachments:
    experiencia.vi ‏49 KB

    Hello
    For what I’ve seen on National web site, using the “Traditional compatibility VI’s”, it sould be possible to control a NI-DAQmx using code written in NI-DAQ Traditional. This information was obtained from the following NI link:
    http://digital.ni.com/softlib.nsf/954feaeea92d90918625674b00658b83/9d67f671bcc6850586256e630059308b?...
    Please read this information and then tell me something please.
    Best regards!

  • The acquisition locks when I press the increment or decrement button of a numeric control

    Hello all.
    I´m using a PCI-6220 and the Traditional NI-DAQ Compatibility VI's to make the acquisition that is in the attached VI. But when I click the increment/decrement button on the numeric controls my acquisition stops. In the same PC I made the same experience with a 6040 and I could not see this problem. I tried with the PCI-6220 with the DaqMX VI's and I could not see this problem too, for these reasons I believe that the problem has something to do with the Traditional NI-DAQ Compatibility VI's.
    I built machines that can have one or the other board (depending if it is low-end or normal). Does somebody knows the solution for this problem?
    Thanks in advance.
    Paulo Carmo
    Attachments:
    experiencia.vi ‏49 KB

    Hello
    For what I’ve seen on National web site, using the “Traditional compatibility VI’s”, it sould be possible to control a NI-DAQmx using code written in NI-DAQ Traditional. This information was obtained from the following NI link:
    http://digital.ni.com/softlib.nsf/954feaeea92d90918625674b00658b83/9d67f671bcc6850586256e630059308b?...
    Please read this information and then tell me something please.
    Best regards!

  • Increment once per key press

    I'm trying to find the 'proper' method to do this basic concept of incrementing a value (in this example) once per key press:
    Is there a more efficient (using less cpu and/or less code) way to do this?
    I am also curious why you can't add shift registers to the case structure.
    Solved!
    Go to Solution.
    Attachments:
    Feedback node run once per button press.vi ‏9 KB

    martinv wrote:
    (Note I posted this before seeing the 2 replys that snuck in before this post)
    I think I get it.  Is this what you described (Pic Below)?
    I first thought the loop would be running continuously, but after putting on an indicator I see it does nothing until the case inside is finished. 
    Glad to see you figured it out.  Slight edits I recommend:
    1) Make a case in your event structure for the Stop:Value Change and put the stop terminal inside of that case.  You will then wire the value of the stop button (or a true constant) from that event case to the loop conditional terminal.  This will allow you to stop your loop immediately instead of being forced to wait for another event (or possibly 2) before actually stopping.
    2) I would use a shift register for the value.  This way other cases can affect/read the value without the use of a local variable.  Be sure to wire the value through all of the other cases.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Error -- No Such Trigger('when-button-pressed')

    Hi,
    I am getting the error ""No Such Trigger('when-button-pressed')"",
    when I am executing the code EXECUTE_TRIGGER( 'WHEN-BUTTON-PRESSED' );
    on some item(Key-Next-Item), although WHEN-BUTTON-PRESSED trigger exists.
    What could be the problem ?. It worked till yesterday, giving error from today, I havent
    changed any thing.
    Thanks in Advance
    Devender

    Steve's tip is the only good solution for this case.
    The problem in your case for example is:
    Let's say you have a block-trigger, which fires after your execute-trigger.
    Now a colleague of you, which don't know your code, create a WHEN-BUTTON-PRESSED on an item, then the new code is started and not the block-trigger-code.
    So, don't ever do this. Write your code in a package-function or -procedure and call it from the trigger. So you can re-user the functionality
    Gerd

  • Change control values on button press

    Hi, I've got a situation where I have several numeric controls where you can change different values. I also have several subVIs with control references (as described in this article: http://labviewwiki.org/Control_References) that takes in references to these numeric controls on the mainVI. These subVIs continously read the values in their own threads.
    So whenever I change a value on any of the controls, the values does of course change in the subVIs, since they reference to the value of the control.  How would I make the actual value only change only after I clicked the ok button?
    To illustrate this I made a VI with an event structure and a separate while loop that continoulsy reads a reference to the control and updats an indicator. I can think of a few cumbersome solutions, whereas I have two controls for every value. The second control would then be hidden and only written to in case of the Ok button press. But having two controls to do something simple as this seems superfluous.
    Message Edited by Siniz on 10-20-2009 10:36 AM
    Solved!
    Go to Solution.
    Attachments:
    ValueChangeOnButtonPress.vi ‏19 KB

    Given what you want to do then I would suggest that you use an Action Engine to contain your data. This has the advantage of decoupling the UI from the subtasks. I would recommend that your action engine consist of an array of clusters. Each cluster would contain the data values, in your case Ki, Kd and Kp for each controller. This has the advantage of reducing the individual values you are dealing with and treats the data for a given controller as a whole. The subtasks could either poll the data looking for a value change. You could even keep track of that in your Action Engine so you would only need to poll to see if the data changed. If it did, then read the data. You would need an index or ID to specify which controller's data you would want to access. The action engine allows you to grow your application if more controllers are added. You should use a typedef to define the cluster. If you wanted to make this more event driven you could use a single notifier shared by your subtasks that would simply indicate a data change event. Part of the data for the notifier could specify which data. That way only interested subtasks would take action. This type of architecture wouldn't add lots of wires to your diagram especially if you used a named notifier.
    Regardless of the way you choose to pass the data to the subtasks I would take a look at your UI. I haven't seen it so I can't comment on it specifically. However is you have 40 controls on the front panel at the same time it most likely is a confusing interface. There are ways to reduce the complexity and still provide the same functionality. If you haven't already looked at I would recommend getting the book The LabVIEW Style Book by Peter Blume. If you did reduce your UI to only work with a single controller or a couple of related controllers at a time the Action Engine approach would work nicely since you take your data from the FP and only update the data that has changed. From a UI perspective you have less controls to worry about on your UI and it will probably be easier for the user to understand. From the application's perspective you have decoupled the subtasks from the UI in a very clean way. Another approach would be to use LVOOP for your controller data and processing. Then you simply instantiate a new instance of the class (an object) for each controller that your system is using. This has an added benefit of allowing you to use different controllers and load them at runtime using dynamic dispatching.
    PS You are good for the overall Kudo count. Thanks.
    Message Edited by Mark Yedinak on 10-20-2009 12:33 PM
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • Calling a report from forms - FRM-40735 when-button-pressed raised unhandle

    Hi,
    I created a form to generate a pdf report.
    its not going too well, so i need some help.
    my form only has one button , when pressed I want it to generate a report in pdf format.
    i created a when-button-pressed trigger and the following code is below:
    I also create a web service proxy jar file,
    the jar file is in the FORMS_BUILDER_CLASSPATH, and the jar file is imported from forms builder without any issues.
    As of now I am hard coding everything in the code below to see if it works.
    The error I am getting  FRM-40735 when-button-pressed raised unhandled exception ORA-105100 i dont know why ?
    This error is occurring at this line of code, please help, this is my first time doing something like this.
    obj := publicreportserviceclient.new(); DECLARE
    param_name varchar2(200);
    un varchar2(200);
    pw varchar2(200);
    out_file varchar2(200);
    obj ORA_JAVA.JOBJECT;
    BEGIN
    obj := publicreportserviceclient.new();
    param_name := 'EMP';
    un := 'Administrator';
    pw := 'Oracle123';
    out_file := 'D:\DevSuiteHome_1\j2ee\home\default-web-app'||'output';
    publicreportserviceclient.callRunReport(obj,'/~administrator/Learn/Test1/Test1.xdo','EMP','141414',un,
    pw,'pdf','New_Template',out_file);
    web.show_document('http://jmenge-de.de.oracle.com:8889/j2ee/' || 'output');
    exception
      --check for ORA-105101
      when ORA_JAVA.EXCEPTION_THROWN then
         message('Java Exception : '
          || Exception_.toString(ORA_JAVA.LAST_EXCEPTION));
          ORA_JAVA.CLEAR_EXCEPTION;
          return;
      --check for ORA-105100
      when ORA_JAVA.JAVA_ERROR then
                   message('Unable to call out to Java, ' ||ORA_JAVA.LAST_ERROR);
              return;
    END;This is my java function
        public void callRunReport (String reportPath, String paramName, String  paramValue, String
        username, String password, String format, String template, String outFile) {
        try {
                bip_webservice.proxy.PublicReportServiceClient myPort = new bip_webservice.proxy.PublicReportServiceClient();
                // Calling runReport
                ReportRequest repRequest = new ReportRequest();
                repRequest.setReportAbsolutePath(reportPath);
                repRequest.setAttributeTemplate(template);
                repRequest.setAttributeFormat(format);
                repRequest.setAttributeLocale("en-US");
                repRequest.setSizeOfDataChunkDownload(-1);
               ParamNameValue[] paramNameValue = new ParamNameValue[1];
                paramNameValue[0] = new ParamNameValue();
                paramNameValue[0].setName(paramName);
                String[] values = new String[1];
                values[0] = paramValue;
                paramNameValue[0].setValues(values);
                repRequest.setParameterNameValues(paramNameValue);
                ReportResponse repResponse = new ReportResponse();
                repResponse = myPort.runReport(repRequest,username,password);
                byte[] baReport = repResponse.getReportBytes();
                FileOutputStream fio = new FileOutputStream(outFile);
                fio.write(baReport);
                fio.close();
            } catch (Exception ex) {
                        ex.printStackTrace();
        }Thanks - please help

    If there is a way to make it work with Bi publisher, Please let me know.
    I need to something to make it work with BI publisher.
    thanks,
    Edited by: Rooney on May 27, 2010 1:27 PM

  • How can I call my chart in Forms6i on When Button Press Trigger?

    Hi Friends,
    I have make a chart in Graphic Builder 6i and save on path C:\graph\test.ogd
    Now I want to run this Chart from Form6i on When Button Press trigger.
    I have call my report in forms using this command on When Button Press trigger.
    Run_Product(reports,'C:\Cheema\Qdir_store\reports\pmms\sec_backlog',asynchronous,runtime,filesystem,TO_CHAR(NULL));
    So tell me How can I call my chart in Forms6i?
    Please reply me on urgent.
    Thanks,
    Shahzad

    Just to recall after a long break of couple of years..... Pls check out if not wrong.
    First of all you need to embeed the chart object on your layout window and make it visible = FALSE. This is a design time work. In the button press event, show the chart object by setting the visible property = TRUE.
    Note, i could not paste u the sample code as i don't have forms installation on my PC. The above states is a logic you can apply.

  • Help-I Need to hold a Abstract button pressed

    hi,
    I have captured a button instance from abbot. I need to hold the button pressed for 2 seconds without releasing.
    I need to know, how to do it?
    Pressing the button for more than 2 seconds without releasing will popup a menu.. i need to get the instance of the menu too...
    How can i do that, either through Java or with Abbot.
    Thanks,
    With Regards,
    Priyaa.

    what the heck is Abbot?I thought everyone knew about [url http://www.jahozafat.com/TV_Shows/Abbott_And_Costello/hey_abbott.wav]Abbot.

  • Why am I getting this error?  How do I add confirm message to button press?

    Using Java Studio Creator.
    I do not understand why I am getting the following page error:
    Description: An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
    Exception Details: java.lang.IndexOutOfBoundsException
    Index: 0, Size: 0
    Possible Source of Error:
    Class Name: java.util.ArrayList
    File Name: ArrayList.java
    Method Name: RangeCheck
    Line Number: 546
    ======================================================================
    I have a page that works.
    It has a button that is created in the session bean code with the following java:
    button = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
    button.setActionListener( application.createMethodBinding("#{ScheduleEditSessionBean.mainApply}", new Class[]{ActionEvent.class} ));
    button.setId( "applyUndates" );
    button.setType( "submit" );
    button.setTitle( "Apply updates.");
    button.setValue( "Apply" );
    button.setStyle(style);
    children.add(button);
    When the button is pushed, it calls the following session bean method:
    public void mainApply(ActionEvent actionEvent)
    updateScheduleData();
    scheduleAdjustFlag = 1;
    dataApplied = true;
    dataSaved = false;
    addControls();
    This all works just fine - no errors
    ====================================================================
    I wanted to add confirmation to the button press, so I removed the action listener for this button and added
    a javascript function call for the onclick method
    button = (HtmlCommandButton)application.createComponent(HtmlCommandButton.COMPONENT_TYPE);
    style = "text-align: center; font-family: 'Arial','Helvetica',sans-serif; " + font + " height: 22px; width: 115px";
    // Commented out this line button.setActionListener( application.createMethodBinding("#{ScheduleEditSessionBean.mainApply}", new Class[]{ActionEvent.class} ));
    button.setOnclick("confirmApply()"); // Added this line.
    button.setId( "applyUndates" );
    button.setType( "submit" );
    button.setTitle( "Apply updates.");
    button.setValue( "Apply" );
    button.setStyle(style);
    children.add(button);
    I added a dummy button to the page that has the following call to execute the mainApply method in the sessioon bean.
    The button action just calls the mainApply() method in the session bean
    public String mainApplyBtn_action() {
    seb.mainApply();
    return null;
    Added the javascript to the page that simply pushes the dummy button if confirmed.
    function confirmApply()
    if( confirm( 'Are you sure you want to Apply these changes?' ) )
    form1["form1:mainApplyBtn"].click();
    The session bean method looks like this it is the same method as before, but without the action event argument.
    public void mainApply()
    lsb.logMsg( "<ScheduleEditBean.mainApply> Main apply pushed" );
    updateScheduleData();
    scheduleAdjustFlag = 1;
    dataApplied = true;
    dataSaved = false;
    addControls();
    ==================================================================================
    Now, when I push the original 'Apply' button, I get the confirmation box just like I expected.
    But when I confirm the question, I get the error at the top of this post.
    If I push the 'dummy button' directly, I do not get the error.
    I do not understand why I should be gettng this error.
    Can anyone give me a clue as to why this change would cause the problem?
    The error is related to an ArrayList.
    I use several of these on the page, but they should be filled with data in the preRender method of the page.
    Can anyone suggest a way that I can add confirmation to a button that is created under program control?
    Thanks

    Make use of the fact that when an onclick event of a button returns 'false', the action will not be taken.
    Pseudocode:<h:commandButton value="submit" action="#{myBean.action}" onclick="return confirm('Are you sure?');" />

  • How to call a dynamic URL on 'button press' event, in MVC-based BSP

    Hi,
    My requirement is as below:
    On selecting a row in table view, and pressing a button, I need to open a browser.
    The Browser URL depends on the row selected.
    The key field from table view, is added at the end of the URL string.
    Shortly, I can say that, I am getting a value on row selection & want to pass it to button event.
    In Views Section, there are 2 tags- (1)table view & (2)button.
    Right now, I have put the code for getting the key field, in DO_HANDLE_DATA method.
    In Button's OnClientClick method, I have called the Javascript to open the browser.
    If I now write the code to concatenate the key field value to form the dynamic URL in 'OnClick' method,
    it will be called only after the browser is opened.
    (as OnClick event is executed only after OnClientClick event is executed)
    Could anyone please tell me what event (and in which tag) can be used to solve this.
    Is there any event which is triggered, as soon as the row is selected, &  before the button press event is triggered ?
    Would really appreciate responses made to this query.
    Thanks,
    Nisha Vengal.

    Hi Nisha,
    The crux of your issue here is that you want to call the event triggered with onClick before calling the event triggered on onClientClick. This can be achieved by the following code in the function called on the onClientClick.
    function fn_button()
               htmlbSL(this,2,'b_row_selection:onInputProcessing()');
               window.open("new_page",target="BLANK");
    Here, fn_button is the javascript function called on button click, and b_row_selection is the event triggered on the onClick event of row selection.
    Try this out and let us know if it works for you.
    Regards,
    Saurabh

  • I have reached out  to this community as my Iphone display gone black and got the solution to keep home and power button pressed. It worked but I would like to know why it went black

    I have reached out  to this community as my Iphone display gone black and got the solution to keep home and power button pressed. It worked but I would like to know
    1. Why it went black and is there a permanent fix for this
    2.Will the IOS gets automatically updated as I feel the IOS was 5 when I got the phone in 2012 december
    3.Do you suggest 7.1 for Iphone 4

    1. There is no way of knowing. These things happen.
    2. The iOS only gets updated when you want it to be.
    3. You should always update to the latest iOS your phone will support. Apple do not write the updates to make your experience worse.

  • Problem while hide a block on selection screen on button press

    Hi,
    I have added two buttons on the application toolbar of the selection screen. I have input fields under two blocks on the selection-screen. Initially the second block is hidden. If I press the button 1 the second block should be made visible.
    For this to happen, I captured the button 1 click event using the following statement.
    IF sscrfields-ucomm = 'FC01'.
    Inside the if ... endif, I looped at the screen and made the second block visible. It was working fine.
    loop at screen.
      if screen-group4 = '013'.
         screen-invisible = 1.
         screen-active    = 0.
      endif.
    endloop.
    Later the second button was added. Now when i run the report for the first time, if button 2 is clicked the hidden block appears on the selection screen even though i have not added any code for it.
    Just to check, i commented the logic to display the hidden block on button 1 click event. Even without any code the first time i press any of the two buttons added on the application toolbar the hidden block is displayed.
    I saved a variant for the report.
    During execution of the report, if i select any variant then the hidden block is displayed.
    Can anyone please tell me how to fix this problem.
    Regards,
    T2.

    Hi All,
    The problem is solved.
    Everyone was confusing between the pushbutton on the selectio-screen and on apllication toolbar
    (where you have the execute icon).
    Please find the code below. Thanks for you time and help. I appreciate it.
    REPORT ztest.
    INCLUDE <icon>.
    *  TABLES                                                              *
    TABLES: t001,              " Company Codes
            lfa1,              " Vendor Master (General Section)
            sscrfields.        " Fields on selection screens
    * To capture button press event.
    DATA: gv_button_press       TYPE c.
    * Menu Painter: Program interface for dynamic texts
    DATA: gs_dyntxt             TYPE smp_dyntxt.
    *  SELECTION SCREEN                                                    *
    SELECTION-SCREEN FUNCTION KEY 1.
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-s01.
    * Company Code.
    SELECTION-SCREEN BEGIN OF BLOCK ccode WITH FRAME TITLE text-s02.
    SELECT-OPTIONS: s_bukrs FOR t001-bukrs OBLIGATORY MEMORY ID buk.
    SELECTION-SCREEN END OF BLOCK ccode.
    SELECTION-SCREEN END OF BLOCK blk1.
    SELECTION-SCREEN BEGIN OF BLOCK dsel WITH FRAME TITLE text-s04.
    * Vendor Master.
    SELECTION-SCREEN BEGIN OF BLOCK vend WITH FRAME TITLE text-s07.
    SELECT-OPTIONS: s_konzs FOR lfa1-konzs MODIF ID aw1.
    SELECT-OPTIONS: s_txcd1 FOR lfa1-stcd1 MODIF ID aw1.
    SELECT-OPTIONS: s_txcd2 FOR lfa1-stcd2 MODIF ID aw1.
    SELECTION-SCREEN END OF BLOCK vend.
    SELECTION-SCREEN END OF BLOCK dsel.
    * INITIALIZATION                                                       *
    INITIALIZATION.
    * Populate the Application toolbar button attributes.
      PERFORM populate_app_toolbar_buttons.
    * Hide the dynamic screen intially.
      PERFORM hide_screenfields.
    * AT SELECTION SCREEN                                                  *
    AT SELECTION-SCREEN.
    * Capture the button press event.
      PERFORM capture_button_press.
    * AT SELECTION-SCREEN OUTPUT.                                          *
    AT SELECTION-SCREEN OUTPUT.
    * Show/Hide the dynamic selection screen based on button press.
      PERFORM adapt_screen.
    *&  Form  populate_app_toolbar_buttons                                 *
    *   Display Icon on the application toolbar buttons. Also set the      *
    *   function codes for these buttons.                                  *
    FORM populate_app_toolbar_buttons.
      CLEAR gs_dyntxt.
      WRITE icon_fencing     TO gs_dyntxt-icon_id AS ICON.
      MOVE  text-b01         TO gs_dyntxt-quickinfo.   " Dynamic Selections
      MOVE gs_dyntxt         TO sscrfields-functxt_01.
    ENDFORM.                    " populate_app_toolbar_buttons
    *&  Form  hide_screenfields                                            *
    *   Initially hide the Dynamic selection screen.                       *
    FORM hide_screenfields.
      LOOP AT SCREEN.
        IF screen-group1 = 'AW1'.
          screen-invisible = '1'.
          screen-active    = '0'.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    ENDFORM.                    " hide_screenfields
    *&  Form  capture_button_press                                         *
    *   Set the flag based on button press event. Appication bar button    *
    *   tcode is available only at 'At Selection-screen' event.            *
    *   Use the captured data at 'At Selection-screen Output' event.       *
    *   Screen adjustments is possible only under this event.              *
    FORM capture_button_press.
      IF sscrfields-ucomm = 'FC01'.
        IF gv_button_press IS INITIAL.
          gv_button_press = 'X'.
        ELSEIF gv_button_press EQ 'X'.
          CLEAR gv_button_press.
        ENDIF.
      ENDIF.
    ENDFORM.                    " capture_button_press
    *&  Form  adapt_screen                                                 *
    *   Show/Hide the dynamic selection screen based on button press       *
    *   captured at 'At selection-screen' event.                           *
    FORM adapt_screen.
    * If button press flag is initial hide the dynamic selection screen.
      IF gv_button_press IS INITIAL.
        LOOP AT SCREEN.
          IF screen-group1 = 'AW1'.
            screen-invisible = '1'.
            screen-active    = '0'.
          ENDIF.
          MODIFY SCREEN.
        ENDLOOP.
    * Elseif button press flag is 'X' show the dynamic selection screen.
      ELSEIF gv_button_press EQ 'X'.
        LOOP AT SCREEN.
          IF screen-group1 = 'AW1'.
            screen-invisible = '0'.
            screen-active    = '1'.
          ENDIF.
          MODIFY SCREEN.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " adapt_screen
    Regards,
    T2
    Message was edited by: Titu Joseph

  • Sending an object from client to server always on button press

    What I need is to send an object from client to server but I need to make server wait until another object is sent. What I have is the JFrame where you put the wanted name and surname, then you create a User object with these details and on button press you send this object to the server. I just can't hold the connection because when I send the first object, server doesn't wait for another button click and throws EOFexception. Creating the while loop isn't helpfull as well because it keeps sending the same object again and again. The code is here
    public class ClientFrame extends JFrame {
        private JButton btnSend;
        private JTextField txfName;
        private JTextField txfSurname;
        public ClientFrame() {
            this.setTitle(".. ");
            Container con = this.getContentPane();
            con.setLayout(new BorderLayout());
            txfName = new JTextField("name");
            txfSurname = new JTextField("surname");
            btnSend = new JButton(new AbstractAction() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    SSLSocketFactory f =
                            (SSLSocketFactory) SSLSocketFactory.getDefault();
                    try {
                        SSLSocket c =
                                (SSLSocket) f.createSocket("localhost", 8888);
                        c.startHandshake();
                        OutputStream os = c.getOutputStream();
                        ObjectOutputStream oos = new ObjectOutputStream(os);
                        InputStream is = c.getInputStream();
                        ObjectInputStream ois = new ObjectInputStream(is);
                        boolean done = false;
                        while (!done) {
                            String first = txfName.getText();
                            String last = txfSurname.getText();
                            User u = new User();
                            u.setFirstName(first);
                            u.setLastName(last);
                            oos.reset();
                            oos.writeObject(u);
                            String str = (String) ois.readObject();
                            if (str.equals("rcvdOK")) {
                                System.out.println("received on the server side");
                            } else if (str.equals("ERROR")) {
                                System.out.println("ERROR");
                        //oos.writeObject(confirmString);
                        oos.close();
                        os.close();
                        c.close();
                    } catch (ClassNotFoundException ex) {
                        Logger.getLogger(ClientFrame.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
                        System.err.println(ex.toString());
            btnSend.setText("send object");
            con.add(btnSend, BorderLayout.PAGE_START);
            con.add(txfName, BorderLayout.CENTER);
            con.add(txfSurname, BorderLayout.PAGE_END);
            this.pack();
            setSize(200, 150);
            setVisible(true);
    public class TestServer {
        public static void main(String[] args) {
            try {
                KeyStore ks = KeyStore.getInstance("JKS");
                ks.load(new FileInputStream(ksName), ksPass);
                KeyManagerFactory kmf =
                        KeyManagerFactory.getInstance("SunX509");
                kmf.init(ks, ctPass);
                SSLContext sc = SSLContext.getInstance("TLS");
                sc.init(kmf.getKeyManagers(), null, null);
                SSLServerSocketFactory ssf = sc.getServerSocketFactory();
                SSLServerSocket s = (SSLServerSocket) ssf.createServerSocket(8888);
                printServerSocketInfo(s);
                SSLSocket c = (SSLSocket) s.accept();
                InputStream is = c.getInputStream();
                ObjectInputStream ois = new ObjectInputStream(is);
                OutputStream os = c.getOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(os);
                boolean done = false;
                User u;
                  while(!done){
                    u = (User) ois.readObject();
                    String confirmString = "rcvdOK";
                    String errorString = "ERROR";
                    if (u != null) {
                        System.out.println(u.getFirstName() + " " + u.getLastName());
                        oos.writeObject(confirmString);
                    } else if (u == null) {
                        oos.writeObject(errorString);
                is.close();
                s.close();
                c.close();
            } catch (Exception e) {
                    System.err.println(e.toString());
    }Thanks for any help, btw this doesnt need to be via ssl, the problem would be the same using only http. Please anyone help me:)
    Edited by: Vencicek on 7.5.2012 2:19
    Edited by: EJP on 7/05/2012 19:53
    Edited by: Vencicek on 7.5.2012 3:36

    Current code fails because it's sending still the same entity again(using while loop)No it's not. You are creating a new User object every time around the loop.
    which makes the system freezeWhich means that you are executing network code in the event thread. Don't do that, use a separate thread. At the moment you're doing all that sending inside the constructor for ClientFrame which is an even worse idea: you can never get out of there to the rest of your client program. This is a program design problem, not a networking problem.
    and doesn't allow me to set new parameters of the new entityI do not understand.
    I need to find a way to keep Server running even when the client doesn't send any data and wait until the client doesnt press the send button again to read a new object.That's exactly what happens. readObject() blocks until data is received.

Maybe you are looking for