How to pass params to another class which accepts keyboard input?

How can I pass params to a stand-alone Java class that, when executed, gathers params using readLine()?
In other words, MyClass, when executed from the command-line, uses readLine to gather params for program execution. I'd like to test this class by calling it from another class using Runtime.exec("java MyClass") or calling MyClass.main(args) directly. But, how can I simulate the input expected from the keyboard?
Thanks!

Alright, so it looks like this:
proc = Runtime.getRuntime().exec("java Client");
br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
bw = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
bw.write("test");
bw.newLine();
But, how can write doesn't seem to be passed to the original client class.
Suggestions?

Similar Messages

  • TS3280 How can i enable both paired bluetooth and ios keyboard input at the same time?

    How can i enable both paired bluetooth and ios keyboard input at the same time?
    This is needed for the app im working on. Need some user input via keypad as well as scanner input via a paired bluetooth scanner.

    You probably should not be using a keyboard bluetooth profile for a scanner, I am not a developer for apple so do not know the location for you to find out the correct profile you should be using for an input device that is not a keyboard. Sorry,
    I am sure if you navigate the apple developer site you will probaly finmd what you're looking for.
    https://developer.apple.com

  • How to pass string from a class to another on button click

    Hai forum i'm developing an application in which i have frame1(seperate class without main) where i get a excel files and get the tablenames of it(sheets).
    There i choose a sheet from availabe sheets and i have to pass it frame2 on clicking a button on frame1.
    The sheet name is chosen from a JComboBox in frame1:(code)
    sheetcombo.addActionListener(new java.awt.event.ActionListener()     
                        public void actionPerformed(java.awt.event.ActionEvent e)
                                  JComboBox cb = (JComboBox)e.getSource();
                                  String sheetname = (String)cb.getSelectedItem();
    I dont get how to pass this String sheetname to frame2 where i call the constructor of frame1 initialize it. Help me out. Thanks in advance...

    1 write a set method in frame 2 class
    2 create a instance of frame 2 class in frame 1
    3 in actionaPerformed method write code as follows
    frame2obj.set(sheetname)
    this should work :-)

  • JRC with JavaBeans datasrc - how to pass params into javabean.getResultSet?

    Hi.
    I'm developing javabeans data sources for crystal reports for the java/JRC engine.  I've seen the document entitled Javabeans Connectivity for Crystal.  It TALKS ABOUT passing params into the methods that return java.sql.ResultSets but there is absolutely no example code anywhere that I can find on how to do it.
    What I don't understand is:  Since the JRC engine is basically controlling the instantiation of the javabean, other than calling some type of fetch method in the constructor, how the heck am I supposed to pass in db connection info and a sql string? 
    Anybody got sample code for how to call/where to call parameters that I would put in a custom getResultSet method??
    Thanks.

    I don't think that a Connection Pool class would be an ideal candidate for becoming a JavaBean. One of the most prevalent use of a JavaBean class it to use it as a data object to collect data from your presentation layer (viz. HTML form) and transfer it to your business layer. If the request parameter names match the Bean's property names, a bean can automatically get these values and initialize itself even though it has a zero argument ctor. Then a Bean could call methods in the business layer to do some processing, to persist itself etc.

  • Passing array to another class?

    I have this code which reads in a text file and stores the data in the race array.
    import java.io.*;
    import java.util.*;
    public class Runner {
        public static void main(String[] args) throws IOException {
            BufferedReader in = new BufferedReader(new FileReader("race1.txt"));
            String line;
            while ((line = in.readLine()) != null) {
                String[] race = line.split(",");
                int position = Integer.parseInt(race[0]);
                String name = race[1];
                String team = race[2];
                System.out.println("position=" + position + ", name=" + name + ", team=" + team);
                   in.close();
       }What I want to do is use the race array in another class called Results to perform some calculation methods with the results. So far I haven't been able to get anything to work. Anyone got any advice?

    I was mistaken. Your array isn't of type Race[] or Runner[], but of String[]. Change the declaration accordingly.
    It's not difficult to understand. At one point, you declare a method and define the parameters (in this case a String[]). Once you do that, you have to make sure that you actually do pass a String[] if the method needs one.
    There's no difference in handling parameters, regardless if it's an object, an array, or a primitive value.

  • Adding a JPanel from one class to another Class (which extends JFrame)

    Hi everyone,
    So hopefully I go about this right, and I can figure out what I'm doing wrong here. As an exercise, I'm trying to write a Tic-Tac-Toe (TTT) game. However, in the end it will be adaptable for different variations of TTT, so it's broken up some. I have a TTTGame.java, and TTTSquareFrame.java, and some others that aren't relavent.
    So, TTTGame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              addPanel = startSimple();
              if(!addPanel.isValid())
                   System.out.println("Something's wrong");
              contents.add(addPanel);
              setSize(300, 300);
              setVisible(true);
         public JPanel startSimple()
              mainSquare = new TTTSquareFrame(sides);
              mainSquarePanel = mainSquare.createPanel(sides);
              return mainSquarePanel;
    }and TTTSquareFrame:import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import joshPack.jUtil.Misc;
    public class TTTSquareFrame
         private JPanel squarePanel;
         private JButton [] squares;
         private int square, index;
         public TTTSquareFrame()
              System.out.println("Use a constructor that passes an integer specifying the size of the square please.");
              System.exit(0);
         public TTTSquareFrame(int size)
         public JPanel createPanel(int size)
              square = (int)Math.pow(size, 2);
              squarePanel = new JPanel();
              squarePanel.setLayout(new GridLayout(3,3));
              squares = new JButton[square];
              System.out.println(MIN_SIZE.toString());
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setRolloverEnabled(false);
                   squares[i].addActionListener(bh);
                   //squares[i].setMinimumSize(MIN_SIZE);
                   squares[i].setVisible(true);
                   squarePanel.add(squares[i]);
              squarePanel.setSize(100, 100);
              squarePanel.setVisible(true);
              return squarePanel;
    }I've successfully added panels to JFrame within the same class, and this is the first time I'm modularizing the code this way. The issue is that the frame comes up blank, and I get the message "Something's wrong" and it says the addPanel is invalid. Originally, the panel creation was in the constructor for TTTSquareFrame, and I just added the mainSquare (from TTTGame class) to the content pane, when that didn't work, I tried going about it this way. Not exactly sure why I wouldn't be able to add the panel from another class, any help is greatly appreciated.
    I did try and cut out code that wasn't needed, if it's still too much let me know and I can try and whittle it down more. Thanks.

    Yea, sorry 'bout that, I just cut out the parts of the files that weren't relevant but forgot to compile it just to make sure I hadn't left any remnants of what I had removed. For whatever it's worth, I have no idea what changed, but something did and it is working now. Thanks for your help, maybe next time I'll post an actual question that doesn't somehow magically solve itself.
    EDIT: Actually, sorry, I've got the panel working now, but it's tiny. I've set the minimum size, and I've set the size of the panel, so...why won't it respond to that? It almost looks like it's being compressed into the top of the panel, but I'm not sure why.
    I've compressed the code into:
    TTTGame.java:
    import java.awt.*;
    import javax.swing.*;
    public class TTTGame extends JFrame
         private Integer sides = 3;
         private TTTSquareFrame mainSquare;
         private TTTGame newGame;
         private Container contents;
         private JPanel mainSquarePanel, addPanel;
         public static void main(String [] args)
              TTTGame newGame = new TTTGame();
              newGame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public TTTGame()
              super("Tic-Tac-Toe");
              contents = getContentPane();
              contents.setLayout(new FlowLayout());
              mainSquare = new TTTSquareFrame(sides.intValue());
              contents.add(mainSquare);
              setSize(400, 400);
              setVisible(true);
    }TTTSquareFrame.java
    import java.awt.*;
    import javax.swing.*;
    public class TTTSquareFrame extends JPanel
         private JButton [] squares;
         private int square, index;
         private final Dimension testSize = new Dimension(50, 50);
         public TTTSquareFrame(int size)
              super();
              square = (int)Math.pow(size, 2);
              super.setLayout(new GridLayout(size, size));
              squares = new JButton[square];
              for(int i = 0; i < square; i++)
                   squares[i] = new JButton();
                   squares.setMinimumSize(testSize);
                   squares[i].setVisible(true);
                   super.add(squares[i]);
              setSize(200, 200);
              setVisible(true);
    I've made sure the buttons are smaller than the size of the panel, and the panel is smaller than the frame, so...
    Message was edited by:
    macman104

  • Creating a Set  containing instances of another Class, which type?

    Hi All,
    I'm stuck trying to create a set which contains instances of another Class.
    When I created my instance method, it takes an argument which is the instance of another Class.
    It errors as I've used the Class as the type rather than String> or Integer.
    Can someone point my in the right direction?
    WebPageData wpd1 = new WebPageData("this is a sentence for a test", "www.test.com");
    WebPageData wpd2 = new WebPageData("this sentence is shorter", "www.short.com");
    WebPageData wpd3 = new WebPageData("this is very short", "www.very.com");
    Finder f1 = new Finder();
    f1.addsite(wpd1);
    f1.addsite(wpd2);
    f1.addsite(wpd3);
    f1.searchFor("a sentence test");
    Edited by: geedoubleu on Mar 16, 2008 9:03 AM

    The error message is "Semantic error: line 5. Message addsite( WebPageData ) not understood by class'Finder'"
    * Adds the argument of WebPageData instances to to a collection scannedSites.
    public void addSite(WebPageData theWebPage)
    this.scannedSites.add(theWebPage);
    }

  • How to pass variable to data tab which replace text in Word attachment

    Dear ABAP folks,
    I use METHOD cl_gui_frontend_services=>gui_upload to upload my word doc in BINARY and sucessful sent this word doc as attachment with Thomas Jung's FUNCTION 'Z_E_KEG_SEND_SIMPLE_EMAIL'.
    However, inside the word file, i need insert varible personnel number p0000-pernr.
    *How to pass the value p0000-pernr to data tab (lt_data) which replace symbol text &s_pernr& in doc before created as attachment ? *
    I try 'SCMS_BINARY_TO_TEXT'  and 'SCMS_BINARY_TO_STRING'    but fail.
    Need expert 's help.
    Thanks & Rgds,
    Felice
    Below are my code:
    ** Upload file to read data as binary
        CALL METHOD cl_gui_frontend_services=>gui_upload
    IF lt_data[] IS NOT INITIAL.
        CALL FUNCTION 'SO_SPLIT_FILE_AND_PATH'
         EXPORTING
            full_name     = lv_filename
          IMPORTING
            stripped_name = lv_str_filename
          EXCEPTIONS
            x_error       = 1
            OTHERS        = 2.
        SPLIT lv_str_filename AT '.' INTO lv_junk lv_filetype.
        ls_attach-type = lv_filetype.
        ls_attach-subject = lv_str_filename.
        ls_attach-CONTENT_HEX[] = lt_data[].
        APPEND ls_attach TO lt_attach.
        CLEAR ls_attach.
    ENDIF.
    CALL FUNCTION 'Z_E_KEG_SEND_SIMPLE_EMAIL'
    EXPORTING
    REQUESTED_STATUS = 'E'
    DOCUMENTS = lt_attach
    RECIPIENTS = lt_rec
    MESSAGE = t_objtxt
    SUBJECT = 'Confirmation Review'.
    COMMIT WORK.
    clear lt_rec.
    clear ls_rec-i_copy.

    Dear Luigi,
    Do you have sample code which replace the value in Word file ?
    I try sample code below, but the mergefield 'Title' in Word file not replace instead it override the whole file.
    Even i try with different download path, it also not update field 'Title'.
    The mergefield i insert by microsoft word > mailings > insert merge field >Title.
    report ztestmail_c.
    data: global_filename LIKE RLGRAP-FILENAME.
    data: begin of imerge occurs 0,
    Title(85) type c, field02(85) type c,
    field03(85) type c, field04(85) type c,
    end of imerge.
    data: begin of itabf occurs 31,
    ff(10),
    end of itabf.
    itabf-ff = 'Title'. "append itabf.
    imerge-Title = 'test0'.
    append imerge. clear imerge.
    global_filename = 'c:\temp\confirm-form0508.doc'.
    CALL FUNCTION 'WORD_OLE_FORMLETTER'
    EXPORTING
    WORD_DOCUMENT = global_filename
    *   hidden        =
    *   word_password =             "               Password for the mail merge file (.DOC)
    *   password_option = 1         " i             Controls password use
    *   file_name =  'confirm-form0508'               " rlgrap-filename  Name of download file (w/o ext.)
    *   new_document =              "               Create new Word document
    DOWNLOAD_PATH = 'C:\temp\confirm-form0615.doc'
    TABLES
    DATA_TAB = imerge
    FIELDNAMES = itabf
    EXCEPTIONS
    INVALID_FIELDNAMES = 1
    USER_CANCELLED = 2
    DOWNLOAD_PROBLEM = 3
    COMMUNICATION_ERROR = 4
    OTHERS = 5.

  • How to get variable from another class?

    I have 2 classes. In first I have int variable. In second class I need to get this variable value. How I can make it?
    import javax.microedition.lcdui.*;
    import java.io.*;
    import java.util.*;
    public class ChooseLessons extends Form implements CommandListener, ItemStateListener
         ChoiceGroup lessons;     // Choice Group of preferences
         Dictionary     dictionary;
         int volumeSize;
         ChooseLessons(Dictionary dictionary)
              int volumeSize = 15;
         public void commandAction(Command c, Displayable s)
              if (c == Dictionary.BEGIN_CMD) {
                   new TeachForm(dictionary, this);
    import javax.microedition.lcdui.*;
    import java.util.*;
    public class TeachForm extends Form implements CommandListener     
         Dictionary               dictionary;
         ChooseLessons          lessons;
         TeachForm(Dictionary dictionary, ChooseLessons lessons) {
              super(Locale.WORD);
              this.dictionary = dictionary;
              this.lessons = lessons;
              lessons.volumeSize(); // HERE I NEED VARIABLE VALUE FROM PREVIOUS CLASS
    }Edited by: Djanym on Mar 16, 2009 4:43 PM

    This is a classic problem that coders run into when trying to get their head around object-oriented programing. Since you have a class that should be modeled after a real world object, as far as that object is concerned, no one else needs to know the details of it - without asking nicely. This is where you should set up some getters and setters, which are methods that allow fields in a class to reveal themselves or allow their states to be changed in a orderly fashion.
    There are a number of fields that never need to be known outside of the class. Then there are some fields you would like to let people know about, but don't want them to have the ability to change them. In the example below, there are to getter methods allow return of the necessary fields. If you made these public, there is a possibility that someone utilizing this field may change it outside of its intended use, or access them without them being ready for public consumption.
    Class test {
    //These private variables are only visible from the class
    private int grade1 = 0;
    private int grade2 = 0;
    private int grade3 = 0;
    private float average = 0;
    private int gradeboost = 0;
    //This method sets the gradeboost field to one desired by the instructor
    void setboost(int boost) {
    gradeboost = boost;
    //These methods accept test scores and compute the average for three test
    //Notice that the calculated average may not be the true average of the three test scores
    //because of the possibility of gradeboost calculation being greater than 1
    void test1(int score) {
             grade1 = score;
             average = (grade1 + grade2 + grade3 + gradeboost)/3;
    void test2(int score) {
             grade2 = score;
             average = (grade1 + grade2 + grade3 + gradeboost)/3;
    void test3(int score) {
             grade3 = score;
             average = (grade1 + grade2 + grade3 + gradeboost)/3;
    //This is a getter method, which provides read access to the private variable average
    //If someone just had public access to the grades and wanted to take their own average
    //They would miss how the gradeboost field affects the final outcome.
    float getAverage() {
        return average;
    //Here is a getter method, which accepts an argument to determine which test score to return
    //Notice that this isn't the true testscore, but it has been modified by the gradeboost field.
    //If the user had public access to the true testscore, it wouldn't take into account the gradeboost calculation!!
    //This is how a getter can control exactly what a user has access to.
    float get testScore(int test) {
    float testresult = 0;
    if (test = 1) {
           testresult = (grade1+ gradeboost) / 3;
    if (test = 2) {
           testresult = (grade2+ gradeboost) / 3;
    if (test = 3) {
           testresult = (grade3+ gradeboost) / 3;
    return testresult;
    }

  • How call a method from another class

    i make three class.class A,class B and class C.
    class A have One button.
    Class B have a action listener of that button.
    class c have a metod like
    public void test(){     }
    how can i call a method in class b from class c;
    is it necessary to pass the class a or b through the constructor of class c or another way to call the method.

    public class Foo
        public static void main(String[] args)
            Bar.staticFn();
            Bar b = new Bar();
            b.memberFn();
    class Bar
        public void memberFn()
            System.out.println("memberFn");
        public static void staticFn()
            System.out.println("staticFn");
      }

  • Passing Params from Mutiple Class in a Single Script

    Hi Folks,
    there is a scenario where there are many parameters (optional and mandatory parameters) , which are to be used across different functions with in a child script called CHDS
    So I want to create a separate class ABC with in the same script and declare all those parameters in it and then pass the entire class as an argument to a function.
    Then I would declare an instance ABC and access those parameters required for that particular function.
    so The first class in the script is by defaut
    public class script extends IteratingVUserScript {
    public void functionA1(ABCparams) throws Exception
    ABCparams abc = new ABCparams();
    app.field1 = abc.parameter1;
    app.field2 = abc.parameter2;
    app.field6 = abc.parameter6;
    app.field7 = abc.parameter7;
    public void functionB2(ABCparams) throws Exception
    ABCparams pqr = new ABCparams();
    app.field3 = pqr.parameter3;
    app.field4 = pqr.parameter4;
    app.field8= pqr.parameter8;
    app.field9 = pqr.parameter9;
    Now the second class is
    public class ABCparams
    parameter1;
    parameter2;
    parameter3;
    parameter4;
    parameter5;
    parameter6;
    parameter7;
    parameter8;
    parameter9;
    parameter10;
    parameter11;
    parameter12;
    However the values for parameters declared in class ABCparams would be read from a databank of a parent script PRNS, i.e parent PRNS would invoke child script CHDS.
    Do you think that, this a feasible approach?

    Im not sure whether you can store the internal table into Java script array.
    Look at the below thread, it may help you
    pass an internal table to a javascript function
    By the way you want to store the itab into javascript?
    Raja T
    Message was edited by:
            Raja Thangamani

  • How to pass params to Action Event handler in treeNode?

    Trying to use Tree in portlet I found impossible to determine selected node. (bug # 6354989).
    But I can (despite what is written in manual) use Action Event Handler. It works now (at least, I hope so).
    But I generate tree dynamically and cannot write event handlers for all its nodes. May be there's a way to write one event handler but distinguish node that triggered it? May be by passing additional params to handler?

    The tree component does not work well in portlets. This is a known problem.
    It uses cookies to pass the value of the selected node, but cookies do not work inside of portlets. So, the methods that would normally tell you which node is selected, return nothing. There are also no javascript properties which would allow you to output javascript to store the value somewhere in the page.
    Unfortunately there is no workaround for the bug you mentioned so far so far.
    Rose

  • OSB-how to pass xml to another proxy Service

    Hi
    i am getting a xml as string after java call out and then i am using "fn-bea:inlinedXML($iso2xml_31)" for converting the string to XML,but when i am passing the inlinexml variable to another Proxy service by servicecallout i am not getting it.
    grateful if anyone can throw some light in this matter.
    thanks

    passing the inlinexml variable to another Proxy serviceMake sure the assign in the service callout is passing the right content to the other proxy service... Use OSB Test console to check the content of the variables...
    Cheers,
    Vlad

  • Please help!!! How to pass values to another form

    Hi. I have a form that has several database values and a checkbox item, is_selected, as a non-database item. I want to be able to save the values/records that are checked and be able to pass them to a new form. I know that I'll probably have more than 20 records that consists of many fields. Thanks in advance and I greatly appreciate any advice or suggestions.
    Thanks,
    Kristine

    Look into the Forms help, chapter "Creating and Passing Parameter Lists".
    You have to create a record group, fill the records with your data and pass the record group to the called form.
    Another method would be a database package containing a "global" pl/sql table.

  • How to pass Default value of a cell in to input control

    Hello Guys,
    We have a WEBI which has a floating cell and populated as Today's Date everyday when user runs it. Now user wants little modification and wants Input control for Date. He also wants to pass on the values selected in input control to that floating cell. How can I do that?
    Any suggestions?
    Regards
    Aj

    Hi nitya,
    I think u didnot get my requirement.
    my requirement is i have an complete editable ALV with all fields as input fields.
    now when i enter a value under material and press enter  i need to capyure the
    material value and based on the material value i need to get the details and populate all those values in the respective fields.
    All i need to do is get the material number that is entered.
    in the pdf of using ALV events it is such that editable cell editors trigger ON_DATA_CHANGED  event and non-editable cell editors trigger ON_CLICK event.
    But i couldnot find the ON_DATA_CHANGED event in the ALV events.
    Help me out in finding the event.
    Cheers,
    Madhu

Maybe you are looking for

  • Help! Trying to get a Video File off a DVD so I can use it in Final Cut Pro

    Okay. I'm trying to cut together a project and I need the video and audio off a short DVD. The DVD is under 5 minutes in length and is not copy right protected. For the life of me I cannot understand how to convert the files off the DVD to something

  • Error in the post installation steps of SLD .

    Hi We are working on EP7.0 2004s.We are using local sld.Right now I am doing the post installation steps for SLD.I added the J2EE and UME roles.In the next step I went into the administration tab of SLD for configuring.It is throwing this error. com.

  • Full resolution images possible?

    I am uploading some of my files from photoshop, and PNG files are rather crappy. Is there a way to pevent iWeb from converting them to PNG files and leave them as psd or jpg files? Also, I want to keep full resolution, I thought that was the point of

  • Viewing Photoshop Brushes .abr

    Hi. Is there a way to view brushes in Bridge. I have looked at Brush Pilot for Mac and ABRviewer and no success on my MacPro running 10.5.7 I am trying to create a catalogu of all my Photoshop brushes. Thanks Stephen

  • MRP VIEW For Plant Maintenance

    Hello friends, My Client require Minimum Stock of Spare Parts in Maintenance Store and when ever the minimum reserve quantity hit an automatic PR will generate and the purchase deptt. can Procure. so what will be the MRP View for Plant Maintenance in