Using a button to call a method

I am trying to get the button actionPerformed to call the connect method. But I get this error message on compile:
ras@2[nuvu]$ /usr/jdk/jdk1.6.0_04/bin/javac MonitorView2.java
MonitorView2.java:77: connectPort(java.lang.String) in MonitorView2 cannot be applied to ()
connectPort();
Can someone decipher this for me? Why can't this be done? thx
public class MonitorView2 extends JFrame {
     static SerialPort     serialPort;
     ByteArrayOutputStream asciiStream = new ByteArrayOutputStream();
     public MonitorView2()  {
          super("Monitor View 2");
     JPanel pane = new JPanel();
     setContentPane(pane);
     JButton testButton = new JButton("Test Comm On");
     pane.add(testButton);
     setSize(600, 300);
     setVisible(true);
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     class TestButtonHandler implements ActionListener  {
          public void actionPerformed(ActionEvent e) {
               System.out.println("Test button action works!");
               try
               String a = "33, 48, 48, 66, 67, 78, 49, 13"; //comm on;
               //ByteArrayOutputStream asciiStream = new ByteArrayOutputStream();
               byte[] buf = a.getBytes();
               asciiStream.write(buf);
               System.out.println("Buffer as a string");
               System.out.println(asciiStream.toString());
               System.out.println("Into array");
               byte[] b = asciiStream.toByteArray();
               for (int i=0; i<b.length; i++) {
               System.out.print((char) b);
               catch (Exception ex)
                    System.out.println("Exception has been thrown :" + ex);
               connectPort();
          testButton.addActionListener( new TestButtonHandler());
     public void connectPort ( String portName ) throws Exception {
     String defaultPort = "/dev/ttyS0";
     String                asciiString;
     Charset asciiCharset = Charset.forName("US-ASCII");
     CharsetDecoder decoder = asciiCharset.newDecoder();
     //byte[] b = {33, 48, 48, 66, 67, 78, 49, 13}; //comm on
     byte[] b = asciiStream.toByteArray();
     ByteBuffer asciiBytes = ByteBuffer.wrap(b);
     CharBuffer bChars = null;
     try {
          bChars = decoder.decode(asciiBytes);
     } catch (CharacterCodingException e) {
          System.err.println("Error decoding");
          System.exit(-1);
          System.out.println(bChars);
CommPortIdentifier portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
if ( portIdentifier.isCurrentlyOwned() )
System.out.println("Error: Port is currently in use");
else
CommPort commPort = portIdentifier.open(this.getClass().getName(),2000);
if ( commPort instanceof SerialPort )
SerialPort serialPort = (SerialPort) commPort;
serialPort.setSerialPortParams(4800,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
InputStream in = serialPort.getInputStream();
OutputStream out = serialPort.getOutputStream();
(new Thread(new SerialReader(in))).start();
(new Thread(new SerialWriter(out))).start();
          out.write(b);
          out.flush();
else
System.out.println("Error: Only serial ports are handled by this example.");

Seriously, learn the basics.
Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. Gosling is
the creator of Java. It doesn't get much more authoratative than this.

Similar Messages

  • Using Java Reflection to call a method with int parameter

    Hi,
    Could someone please tell me how can i use the invoke() of the Method class to call an method wiht int parameter? The invoke() takes an array of Object, but I need to pass in an array of int.
    For example I have a setI(int i) in my class.
    Class[] INT_PARAMETER_TYPES = new Class[] {Integer.TYPE };
    Method method = targetClass.getMethod(methodName, INT_PARAMETER_TYPES);
    Object[] args = new Object[] {4}; // won't work, type mismatch
    int[] args = new int[] {4}; // won't work, type mismatch
    method.invoke(target, args);
    thanks for any help.

    Object[] args = new Object[] {4}; // won't work, type
    mismatchShould be:
        Object[] args = new Object[] { new Integer(4) };The relevant part of the JavaDoc for Method.invoke(): "If the corresponding formal parameter has a primitive type, an unwrapping conversion is attempted to convert the object value to a value of a primitive type. If this attempt fails, the invocation throws an IllegalArgumentException. "
    I suppose you could pass in any Number (eg, Double instead of Integer), but that's just speculation.

  • Use a variable to call a method

    Hi
    I'm not very familiar with JAVA. I'm just doing different things in my free time at home.
    Now I try to write a abstract class so my mostly used methods are allways the same. but for that I have to call a method in a class but I know the method only at runtime.
    e.g.
       String[] methods = {"compare", "compareIgnoreCase"};
      // Here I like to call the method out of the above string:
      result = callMethod(class, methods[0], param1, param2);Is this possible in Java? If yes, how?
    By the way, I have J2SE 1.5 installed. And I'm working with NetBeans as my developing tool.
    Thanks for any help
    Cheers
    moba

    Classes can be dynamically loaded to invoke their methods using Java Reflection feature.
    The article http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html provides examples on using the reflection feature.
    In particular, the section "Invoking Methods by Name" in the article gives an example of invoking a method dynamically.
    The relevant APIs (in java.lang and java.lang.reflect packages) are documented at:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/package-summary.html
    and http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html.

  • Cannot use red button when calling a busy number o...

    On my 5800, when I call someone, and it gives the characteristic sound and screen message that the number I have dialed is currently busy, the usual function of the red button suddenly fails. Its attributed function, as told on the screen, has apparently been turned into a "Dialer", which, when I click on it, gives the message "Not allowed" after a couple of seconds in 100% of cases. Therefore, I'd highly appreciate if the usual function of the red button would remain, that is, to quit everything and bring me back to the home screen right away so that I could do something else. As it is now, my 5800 wastes several seconds of my life everytime I call a busy number. So, how to avoid the red button failing when calling busy numbers?

    Um, I'd like to inform you that from my experience, this is the same on ALL s60v5 phones. Its not a 5800 only thing. Plus, it wont change. Nokia's not gonna change it. They may change it for other phones but not the 5800. That phone's already past its lifespan in terms of updates.
    If you find my post helpful please click the green star on the left under the avatar. Thanks.

  • How to use a button in a required field

    Hi,
    this is my scenario:
    1) In a Form I have two Blocks
    2) In the first, I use a text Item for the customer code, with the required property set to true and with a trigger WHEN-VALIDATE-ITEM
    3) In the second block, I use a button that call the 'show_lov' function in order to display the list of the customers.
    If the focus is out of the first block, I can use the button without problems.
    If the focus is on the customer code Item and I try to use the serch button, the alert message "Field required" is displayed and I don't be able to use the function in the button.
    Exist a method in order to use my button when the focus is in the required customer item?
    If Yes, how can perform this ?
    I hope...
    Best Regards
    Gaetano

    When you set Required = Yes, you're telling Forms not to allow the user to navigate away from the item until they enter a required value. That's the way Forms is designed.
    If you don't like that behavior (and I'm one that doesn't), I rarely use Required = Yes. Instead, I write the code to check for a required value in the PRE-COMMIT trigger. If the item doesn't have a value, I set focus to the item, and then issue a RAISE Form_Trigger_Failure.
    I'm sure there are other ways to do this, but that is just one technique.

  • Using a button to open an SWF in the same player...

    Hello,
    I seem to be having some trouble figuring out the proper kind of script that would allow me to use a button to call up and play a new SWF in the exisiting player (in this case, the projector). I am working on an interactive presentation which is now complete. However, I need a splash screen that opens on launch which offer different langauges. Each langauge has its own swf. I need a menu on the splash screen that the user can use to select their langauge by clicking the respective button that lanches that particular swf. Right now, I just need one button as the other langauge versions are still in production.
    With that said, is there an easy way to launch an swf from the splash screen? I have tried a few different actionscripts but I seem to be always coming back to loadmovie script (which I havn't really mastered yet). My early attempts would load the new SWF but the current one stays in the player. It is kind of a mess.
    Anyway, I am hoping there is a simpler option. I am a beginner at actionscript 3, so I am still figuring things out. I have worked with AS1 and AS2 and it seems those versions were linked swfs easier that AS3. I just want the button to leave the existing player and open the new swf (but leave the splash screen behind). This would function like website navigation, so I am not needing anything fancy. Most of the documentation I have read so far either assumes you want the swf to import and be part of the internal navigation or want multiple swfs loaded internally. That is definitely not what I want.
    Anyway, thank you in advance for any help/insight.

    Well, I think I got it working. The code I came up with seems a lot more simple than what I was experimenting with. I am pretty sure I did something earlier that was similar to this code but the current swf stayed with the player when the new one loaded, I am pretty sure the old swf is hiding underneath the new one but after some testing, the actual presentation is working as intended so I am waving the AS3 white flag and am accepting how this functions in its present state. I nearly gave myself a heart attack trying to get this simple function to work
    Anyway, heres my "final" code. If anyone sees something that should be adjusted, please let me know.
    play_iv.addEventListener(MouseEvent.CLICK, loadmain);
    function loadmain(event:MouseEvent):void {
                var prevu_english:Loader = new Loader();
                prevu_english.load(new URLRequest("assets/PreVu - English.swf"));
                addChild(prevu_english);
    Also, Thankyou Ned. You pointed me in the right direction. If I didn't keep looking at the loader class, I probably would have spent days doing trial and error until I got somewhere.

  • Calling a method via String representation of instance

    Is it possible to call a method of a specific (and already existing) instance of a class using a string representation of the instance?

    By "String representation of an instance," I simply mean a string that has the same format as a normal method call would have. So where a method would normally be called like this:
    ClassX itsInstance = new ClassX();
    itsInstance.methodX();
    The string representation would be:
    String instanceName = "itsInstance";
    And there would be some way of using this string to call the method referred to by instanceName.
    The idea here is that I want to use the existing instance, whereas using reflection, as below, would create a new instance:
    String className = "X";
    String methodName = "print";
    Class xClass = Class.forName(className);
    Method xMethod = xClass.getMethod(methodName,null);
    Object object = xClass.newInstance();
    xMethod.invoke(object,null);

  • Calling a method with a html Submit button

    hi guys,
    is it possible to call a method from a JSP file using a HTML submit button. I know i can call another website easily doing it this way, is there a similar way available to call a method once the button is clicked?
    FYI
    The method is in a bean file named jdbc. The methods name is getUsername.
    Nice one.
    <form action = <%jdbc.getUsername()%> <input type="submit" value="Submit">

    Dear friend,
    you mentioned that u need to call a method when submit button is clicked. Is the method dynamically created. If not so, then you can include the method on the submit button html file itself.
    Regards,
    Rengaraj.R

  • How can we call the method of used controller?

    Hi All,
       i created two WDA Applications.( like YWDA1,YWDA2 ) . i am using the component WDA2 in WDA 1.and displaying the one view of WDA2 as popup window in WDA1 on action of one of the input element in the view of WDA1 by using the method l_window_manager->create_window_for_cmp_usage
    I have a button on the view of WDA2 which has appear in the popup window...how can i call the method which has binded to that button....and where should i code that...and i need to assign selected value in the popup window to input elemetn of view  WDA1
    Please help me to resolve this....
    Regards,
    Ravi

    You can not directly call view's event handler from other component.
    create a method in component controller of the second component and in the button click call the component controller method. ( also make the method as interface so that you can call it from other components )
    Now, you can call the interfacecontroller's method
    DATA: l_ref_INTERFACECONTROLLER TYPE REF TO ZIWCI__VSTX_REBATE_REQ_WD .
      l_ref_INTERFACECONTROLLER =   wd_This->wd_CpIfc_<comp usage name>( ).
      l_ref_INTERFACECONTROLLER->Save_Rr(
        STATUS = '01'                       " Zvstxrrstatus
    save_rr is the method of second component controller

  • Reg Vendor master upload using BDC Call Transaction Method

    Hi All,
    Thanks in advance.
    I am uploading vendor master data using bdc call transaction method for XK01. In that  i am getting an error message that the fields " smtp_addr" ( for email) and "time_zone" (for time zone) doesnot exist on the screen '0110' ( this is the second screen) . the field timezone will be displayed on the screen only when we go for communications button and select the URL field .
    Do anybody have the solution for this problem. if possible can you give me the code for that screen.

    Create a recording via SM35 (menu go to=>recording), this will generate automatically the code for filling your bdcdata-table...

  • How can i interact with the ALV if i am using the lvc_ and call method?

    i want to hide the last entry of a line when i click on the checbox of my ALV

    u want to hide or delete?
    instead of using check box, u can use a button to display there.
    it can be achived like below.
    data: ls_lvclayout type lvc_s_layo.
    LS_LVCLAYOUT-SEL_MODE = 'D'.
    now in set_table for_first_diaplay
    CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
          EXPORTING
          <b>  IS_LAYOUT            = LS_LVCLAYOUT</b>
    do like above.
    then u click on the row, and the row will be selected.
    now using the method GET_SELECTED_ROWS, u can get the data of the selected row and u can now manipulate what ever u needed.
    data:
    SEL_ROW TYPE LVC_S_ROID,
    SEL_T_ROW TYPE LVC_T_ROID.
    CALL METHOD GO_GRID->GET_SELECTED_ROWS
        IMPORTING
          ET_ROW_NO = SEL_T_ROW.
    LOOP AT SEL_T_ROW INTO SEL_ROW.
              read table <itab> index SEL_ROW-ROW_ID.
              check sy-subrc = 0.
    < now write the logic  like making the field blank and modify the itab>.       
            ENDLOOP.

  • Call java method from button in UIX page

    Greetings,
    I want to call a java method from a button on a uix page.
    Does it have to be a submit button or it maybe a simple button.
    If it was from a JSP page, it would be a much more different process ?
    This method should delete a row from another view (View2).
    delete from tableB ta where ta.field1 = &1
    My question is how do I build the method to delete a row and how do I invoke the method using the button ?
    Thanks

    This sounds like a JDeveloper/ADF issue that is not related to JHeadstart. Can you please log a TAR at MetaLink ( http://metalink.oracle.com/ ), or ask this question at the JDeveloper forum at http://otn.oracle.com/discussionforums/jdev.html ?
    Thanks,
    Sandra Muller
    JHeadstart Team
    Oracle Consulting

  • Doubt in uploading using call transaction method

    hi all
    i am uploading f-29 in call transaction method .. i have a problem in currency field, the currency field is not picking up it shows a error that input field is longer than screen field .. i have declared currency field as type BSEG-WRBTR(same as screen field ...how to go about
    thanks
    lokesh

    Hi,
    When you use the database value directly in your BDC, you will have this issue. It is always advisable to use character fields when doing BDC. so change it to charecter field and try it..
    Regards
    Sudheer

  • LVOOP "call parent method" doesn't work when used in sibling VI

    It seems to me that the "call parent method" doesn't work properly according to the description given in the LabVIEW help.
    I have two basic OOP functions I am doing examples for. I can get one to work easily and the other one is impossible.
    Background
    There are 3 basic situations in which you could use the "call parent method"
    You are calling the parent VI (or method) of a child VI from within the child VI
    You are calling the parent VI (or method) of a child VI from within a sibling VI
    You are calling the parent VI (or method) of a child VI from a different class/object.
    From the LabVIEW help system for "call parent method":
    Calls the nearest ancestor implementation of a class method. You can use the Call Parent Method node only on the block diagram of a member VI that belongs to a class that inherits member VIs from an ancestor class. The child member VI must be a dynamic dispatching member VI and have the same name as the ancestor member VI
    From my reading of that it means situation 3 is not supported but 1 & 2 should be.
    Unfortunately only Situation 1 works in LabVIEW 2012.
    Here is what I want
    And this is what I actually get
    What this means is that I can perform a classic "Extend Method" where a child VI will use the parent's implementation to augment it's functions BUT I cannot perform a "Revert Method" where I call the parent method's implementation rather than the one that belongs to the object.
    If you want a picture
    Any time I try and make operation2 the VI with the "call parent method" it shows up for about 1/2 sec and then turns into operation.
    So there are only 3 possibilities I can see
    Bug
    Neither situation 2 or 3 are intended to work (see above) and the help is misleading
    I just don't know what I am doing (and I am willing to accept this if someone can explain it to me)
    The downside is that if situation 2 above doesn't work it does make the "call parent node" much less usefull AND it's usage/application just doesn't make sense. You cannot just drop the "call parent node" on a diagram, it only works if you have an existing VI and you perform a replace. If you can only perform situation 1 (see above) then you should just drop the "call parent node" and it picks up the correct VI as there is only 1 option. Basically if situation 2 is not intended to work then the way you apply "call parent method" doesn't make sense.
    Attachements:
    For the really keen I have included 2 zip files
    One is the "Revert Method labVIEW project" which is of course not working properly because it wants to "call parent method" on operation not operation2
    The other zip file is all pictures with a PIN for both "Revert Method" and "Extend Method" so you can see the subtle but important differences and pictrures of the relavant block diagrams including what NI suggested to me as the original fix for this problem but wasn't (they were suggesting I implement Extend Method).
     If you are wondering where I got the names, concepts and PIN diagrams from see:
    Elemental Design Patterns
    By: Jason McColm Smith
    Publisher: Addison-Wesley Professional
    Pub. Date: March 28, 2012
    Print ISBN-10: 0-321-71192-0
    Print ISBN-13: 978-0-321-71192-2
    Web ISBN-10: 0-321-71255-2
    Web ISBN-13: 978-0-321-71255-4
     All the best
    David
    Attachments:
    Call parent node fault.zip ‏356 KB
    Call parent node fault.zip ‏356 KB

    Hi tst,
    Thankyou for your reply. Can you have a look at my comments below on the points you make.
    1) Have to disagree on that one. The help is unfortunately not clear. The part you quote in your reply only indicates that the VI you are applying "Call Parent Node" to must be dynamic dispatch. There is nowhere in the help it actually states that the call parent node applies to the VI of the block diagram it is placed into. Basically case 2 in my example fulfills all that the help file requires of it. The dynamic dispatch VI's operation are part of a class that inherits from a given ancestor. Operation 2 for Reverted behaviour is a child VI that is dynamic dispatch and has the same name as the ancestor VI (operation2). The help is missing one important piece of information and should be corrected.
    2) True it does work this way. I was trying to build case 2 and had not yet built my ancestor DD for operation so the function dropped but wasn't associated with any VI. I was able to do this via a replace (obviously once the ancestor Vi was built) so this one is just bad operator
    3) Keep in mind this is an example not my end goal. I have a child implementation because this is a case where I am trying to do a "reverse override" if you like.
    3a) The point of the example is to override an objects method (operation2) with it's parent's method NOT it's own. The reason there is a child implementation with specific code is to prove that the parent method is called not the one that relates to the object (child's VI). If I start having to put case structures into the child VI I make the child VI have to determine which code to execute. The point of Revert method is to take this function out of the method that is doing the work. (Single Use Principal and encapsulation)
    3b) The VI I am calling is a Dynamic Dispatch VI. That means if I drop the superclass's VI onto the child's block diagram it will become the child's implementation. Basically I can't use Dynamic Dispatch in this case at all. It would have to be static. That then means I have to put in additional logic unless there is some way to force a VI to use a particular version of a DD VI (which I can't seem to find).
    Additional Background
    One of the uses for "Revert Method" is in versioning.
    I have a parent Version1 implementation of something and a child Version2. The child uses Version2 BUT if it fails the error trapping performs a call to Version1.
    LabVIEW has the possibility of handling the scenario but only if both Case 1 and Case 2 work. It would actually be more useful if all 3 cases worked.
    The advantage of the call parent method moving one up the tree means I don't have the track what my current object is and choose from a possible list, if, for example the hierarchy is maybe 5 levels deep. (so V4 calls V3 with a simple application of "call parent method" rather than doing additional plumbing with case structures that require care and feeding). Basically the sort of thing OOP is meant to help reduce. Anything that doesn't allow case 2 or 3 means you have to work around the limitation from a software design perspective.
    If at the end of the day Case 2 and case 3 don't and won't ever work then the help file entry needs to be fixed.
    All the best
    David

  • There is no option to reject an incoming call in locked screen, there must be an icon on the screen for one who don't want to use lock button several times, i did'nt face this problem in last ios 6.1.3.

    There is no option to reject an incoming call in locked screen, there must be an icon on the screen for one who don't want to use lock button several times, i did'nt face this problem in last ios 6.1.3.

    A good read. Have you done anything at all to resolve your problem. Reset? Restore?
    By the way - "your products"... nobody here produced the iPhone, we are all just users. Apple is not here.

Maybe you are looking for