Getting values from a JTextField on a JPanel in another class

I have created a class which extends a JPanel and added a JTextField to it, which has an addActionListener for getting the values typed in the JTextField. I want to use the class created in another class and retrieve the values typed in the JTextField, so how do i go about that? I have the class created below so the problem is how to retrieve content of val[val] in another class?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TextFieldChooser extends JPanel{
  int val;
  public TextFieldChooser(String str){
    val = 0;     
    setLayout(new FlowLayout());
    add(new JLabel(str));
    JTextField txtf = new JTextField(5);
    txtf.addActionListener(new TextFieldListener());
    add(txtf);
  }//end constructor     
  private class TextFieldListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
       val = Integer.parseInt(e.getActionCommand());
  }//end text field listener
  public int getValue(){
    return val;     
}//class

The problem is which listener can be programmed to handle the event performed on the class TextFieldChooser in the other class?
I have created a class which extends a JPanel and
added a JTextField to it, which has an
addActionListener for getting the values typed in the
JTextField. I want to use the class created in
another class and retrieve the values typed in the
JTextField, so how do i go about that? I have the
class created below so the problem is how to retrieve
content of val[val] in another class?
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TextFieldChooser extends JPanel{
int val;
public TextFieldChooser(String str){
val = 0;
setLayout(new FlowLayout());
add(new JLabel(str));
JTextField txtf = new JTextField(5);
txtf.addActionListener(new TextFieldListener());
add(txtf);
}//end constructor
private class TextFieldListener implements
s ActionListener{
public void actionPerformed(ActionEvent e) {
val = Integer.parseInt(e.getActionCommand());
}//end text field listener
public int getValue(){
return val;
}//class

Similar Messages

  • Can´t get a value from a JTextField

    I don´t succeed in getting the text from a texfield from an actionListener.
    I have a class which is a JPanel containing a textfield.
    class MyPanel extends JPanel {
        private JTextField textfield = new JTextField();
        public String getInutValue() { return textfield.getText(); }
    }From another class that is a JFrame I have a button with an actionListener:
    class MainFrame extends JFrame {
        public void actionPerformed(ActionEvent e) {
             MyPanel panel = new MyPanel ();
             System.out.println(panel.getInutValue());  // Prints an emptry string ( "" )
    }Why can´t I get the value from the textfield on the JPanel from my other class?

    Roxxor wrote:
    I don´t succeed in getting the text from a texfield from an actionListener.
    I have a class which is a JPanel containing a textfield.
    class MyPanel extends JPanel {
    private JTextField textfield = new JTextField();
    public String getInutValue() { return textfield.getText(); }
    }From another class that is a JFrame I have a button with an actionListener:
    class MainFrame extends JFrame {
    public void actionPerformed(ActionEvent e) {
    MyPanel panel = new MyPanel ();
    System.out.println(panel.getInutValue());  // Prints an emptry string ( "" )
    }Why can´t I get the value from the textfield on the JPanel from my other class?You are creating a new instance of MyPanel in the actionPerformed method.

  • From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    From two given tables, how do you fetch the values from two columns using values from one column(get values from col.A if col.A is not null and get values from col.B if col.A is null)?

    Hi,
    Use NVL or COALESCE:
    NVL (col_a, col_b)
    Returns col_a if col_a is not NULL; otherwise, it returns col_b.
    Col_a and col_b must have similar (if not identical) datatypes; for example, if col_a is a DATE, then col_b can be another DATE or it can be a TIMESTAMP, but it can't be a VARCHAR2.
    For more about NVL and COALESCE, see the SQL Language manual: http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions119.htm#sthref1310
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Getting values from a datagrid to an ArrayCollection

    Hi, I have a drag and dropable datagrid. I fill it with rows of data from another datagrid. Finally, my application demands savings the data from the datagrid into an array collection along with the index of each row. How do i get values from a datagrid into an arrayCollection variable? Please help me..!

    Whatever is dropped into the DataGrid automatically goes into its dataProvider property, typically an ArrayCollection. Just access the data grid's dataProvider property to see the values.

  • How to get values from a stored package variable of type record ?

    Sir,
    In my JClient form, I need to get values from a database stored package variable of type record. And the values are retained in the JClient form for the whole session. The values are copied only once when the form is started.
    What is the best way to do that ?
    Thanks
    Stephen

    Stephen,
    not sure what your model is, but if it is Business Components, I think I would expose the properties as a client method on the application module. This way all JClient panels and frames will have access to it. You could use a HashMap to store the data in teh app module.
    If JDBC supports the record type, then you should be able to call it via a prepared SQL statement. If not, you may consider writing a PLSQL accessor to your stored procedure that returns something that can be handled.
    Steve Muench provides the following examples on his blog page
    http://otn.oracle.com/products/jdev/tips/muench/stprocnondbblock/PassUserEnteredValuesToStoredProc.zip
    http://otn.oracle.com/products/jdev/tips/muench/multilevelstproc/MultilevelStoredProcExample.zip
    Frank

  • How can I get values from listbox?

    Hi all,
    I need to get price values from Price List (Inventory -> Item Master Data screen). It's important to get values from field 'Price' BEFORE item will be added/updated.
    How can I get values from Pricelist listbox?
    Thanks for any suggestions or short sample code.
    Best regards,
    Andy

    Hi Andy
    Here is som sample code that will get the description of the price list and also the price that is displaying at the time. The item master must be open for this snippet of code
      Public Sub GetItemPriceFromOpenWindow()
            'this is assuming item master is open
            Dim oEdit As SAPbouiCOM.EditText
            oEdit = SBO_Application.Forms.GetForm("150", 1).Items.Item("34").Specific
            SBO_Application.MessageBox(oEdit.Value)
            Dim oCmb As SAPbouiCOM.ComboBox
            oCmb = SBO_Application.Forms.GetForm("150", 1).Items.Item("24").Specific
            SBO_Application.MessageBox(oCmb.Selected.Description)
        End Sub
    Hope it helps

  • POPUP FM to get values from a table control?

    I know about the FM POPUP_GET_VALUES to get one or more values from a popup dialog box.  I would like to find a similar FM that allows getting values from a table control or something that allows entry of multiple lines of values.  Is there such a thing, or do I need to write my own?

    it depends on what values you want to enter, better write your own to have a control on the function.

  • How to get values from a table(in jsp) for validation using javascript.

    hi,
    this is praveen,pls tell me the procedure to get values from a table(in jsp) for validation using javascript.
    thank you in advance.

    Yes i did try the same ..
    BEGIN
    select PROD_tYPE into :P185_OFF_CITY from
    magcrm_setup where atype = 'CITY' ;
    :p185_OFF_CITY := 'XXX';
    insert into mtest values ('inside foolter');
    END;
    When i checked the mtest table it shos me the row inserted...
    inside foolter .. Now this means everything did get execute properly
    But still the vallue of off_city is null or emtpy...
    i check the filed and still its empty..
    while mtest had those records..seems like some process is cleaining the values...but cant see such process...
    a bit confused..here..I tried on Load after footer...
    tried chaning the squence number of process ..but still it doesnt help
    some how the session variables gets changed...and it is changed to empty
    Edited by: pauljohny on Jan 3, 2012 2:01 AM
    Edited by: pauljohny on Jan 3, 2012 2:03 AM

  • Help: cant get values from a resultset

    i have a class that contains all my MySQL statement and i am trying to use the results found from one of my select statements to pass on into another class which displays the results in a gui form. Here is my query:
    public void profile(String user)
            try
                 Class.forName(driver);
                 Connection con = DriverManager.getConnection( url,db_user, db_pass);
                 String username, name, email, dob, bio, gender, homepage, number;
                 //find username and select all details
                 String find = "SELECT Username, Full_name, Email, dob, Biography, Gender, Homepage, Contact_number FROM users WHERE Username = ? ";
                 PreparedStatement ps1 = con.prepareStatement(find);
                 ps1.setString(1, user);
                ResultSet rs = ps1.executeQuery();
                while(rs.next())
                    //retreive information from the server
                    username = rs.getString(1);
                    name  = rs.getString(2);
                    email  = rs.getString(3);
                    dob = rs.getString(4);
                    bio = rs.getString(5);
                    gender = rs.getString(6);
                    homepage = rs.getString(7);
                    number = rs.getString(8);
                    User_Profile profile = new User_Profile(username, name, email, dob, bio, gender, homepage, number);
                    JOptionPane.showMessageDialog(null, username + bio + email, null, JOptionPane.ERROR_MESSAGE);
                  con.close();
            catch( Exception e )
                     e.printStackTrace();
                     JOptionPane.showMessageDialog(null, "error," + e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
        }As you can see, i am trying to pass on the variables username, name, etc to a new instance of my user_profile class but it doesnt for some reason. i dont get any comple errors so thats ok. i created messege dialog box from within the while statement above to see if a value is stored, and yes their is a value stored in my variables
    below is the user profile class which shows my constructor that suppose to get the values from the query class in this code entered above       User_Profile profile = new User_Profile(username, name, email, dob, bio, gender, homepage, number);
        protected String username;
        protected String FullName;
        protected String Email;
        protected String DOB;
        protected String Biography;
        protected String Gender;
        protected String Homepage;
        protected String Con_Number;
        protected String crnt_user;
    public User_Profile(String user, String name, String email, String dob,
                                String bio, String gender, String homepage, String number)
            initComponents();
            addWindowListener( this );
            //get values from sql query and store them here.
            this.username = user;
            this.FullName = name;
            this.Email = email;
            this.DOB = dob;
            this.Biography = bio;
            this.Gender = gender;
            this.Homepage = homepage;
            this.Con_Number = number;
         }the code below is used to display one of the values received from the query class, in this case returns null..
    txt_name.setText(username)

    Does the user String match the database String
    exactly?
    Some databases are case sensative.Sorry posted before done.
    Also, ensure you do not have trailing spaces in one or both. I remember Oracle had this problem a few years ago using the Type 4 driver but not through ODBC.

  • Getting values from a running window

    has anyone ever used a program that could retrieve values from an opened window? I have this poker calculator program that can get values from an open poker window. It has a list of about 50 different types of windows (exes, iexplorer, different sites etc.).
    Is there any simple way in java of doing something like this?

    its not done by a screenshot, because you just give
    it the window's title. It works even if its
    minimized.At least in Windows, if you have the window's title then you can get a link to the application and you can find out all sorts of information about it. So your conclusion that screenshots aren't involved isn't correct. They may or may not be involved. But this access is done by a native Windows API and Java doesn't support that.

  • Getting values from a Map

    Hi,
    I would like to get values from a Map. This is my Map
    courrierId659 = [Ljava.lang.String;@7e6f03,
    nomModele = [Ljava.lang.String;@aa594b,
    navigation = [Ljava.lang.String;@1cc67fd,
    dateImpression = [Ljava.lang.String;@bf2fa9,
    nomGestionnaire = [Ljava.lang.String;@1d2279c,
    courrierId650 = [Ljava.lang.String;@64635b,
    selection = [Ljava.lang.String;@1a93ff1
    I want to get all the values whose keys start with courrierId, is possible to get these values in a effective way? or I have to iterate through the Map?
    Thank you in advance

    elsymenab wrote:
    I want to get all the values whose keys start with courrierId, is possible to get these values in a effective way?Yes. Loop through the keys, and where the key meets your criteria, get the value.
    or I have to iterate through the Map?That sounds pretty effective to me.
    ~

  • Getting value from portal or bsp application to selection screen parameter

    Daer SDNer's.
                           Is there any possibility of getting value from bsp application and that value to be passed to selection paramater of bw query varaiable.
    concept as follows.
                                    report is based on vendor related information. particular vendor having user id in bsp or portal for accessing reports. if he selects bw query in portal or bsp dash board. that same vendor name or id shoukd be pass to default vendor selection entry in bi... so only that particular vendor details should display.....
    Harikrishna

    Dear Arun,
                      thanks for the reply. can i dynamically get the values to selection parmaters from bsp or else i need to mantain those user ids(vendor name) in bw. could you explain on it. if possible provide some sample code on it.
    Thanks
    Harikrishna N

  • Get value from  APEX_ITEM.SELECT_LIST_FROM_QUERY - column on a report.

    Hello.
    Help. Help. Help.
    I have to get value from APEX_ITEM.SELECT_LIST_FROM_QUERY - column on a report.
    SELECT DISTINCT ROLE AS GET_ROLE,
    JOB AS GET_JOB,
    APEX_ITEM.SELECT_LIST_FROM_QUERY
    ( 1, '%', 'SELECT DISTINCT CODE c,
    MODE m
    FROM T2
    WHERE ROLE = ' || ROLE ) AS GET_CODE
    FROM T1
    WHERE AGE >30 AND
    SEX = 'M' ;
    I was trying to use javascript :
    for (var i = 0; i < selectlist_name.options.length; i++)
    if (selectlist_name.options[ i ].selected)
    result=selectlist_name.options;
    But I don't know is that correct:
    "selectlist_name" - APEX_ITEM.F01
    (of my APEX_ITEM.SELECT_LIST_FROM_QUERY)?

    Just as a note, but you want to make sure your APEX_ITEM call is closed. The code snippet you posted isn't complete.
    APEX_ITEM.SELECT_LIST_FROM_QUERY(6,c020, 'select DISTRIBUTION_NAME, DISTRIBUTION_NAME from DISTRIBUTIONS','style="", SEQ_ID   <-- No closing )In the documentation - http://www.utoug.org/i/doc/api099.htm - (though it isn't necessarily the easiest to read) it gives this explanation of the syntax:
    APEX_ITEM.SELECT_LIST_FROM_QUERY(
    p_idx IN NUMBER,
    p_value IN VARCHAR2 DEFAULT,
    p_query IN VARCHAR2,
    p_attributes IN VARCHAR2 DEFAULT,
    p_show_null IN VARCHAR2 DEFAULT,
    p_null_value IN VARCHAR2 DEFAULT,
    p_null_text IN VARCHAR2 DEFAULT,
    p_item_id IN VARCHAR2 DEFAULT,
    p_item_label IN VARCHAR2 DEFAULT,
    p_show_extra IN VARCHAR2 DEFAULT)
    RETURN VARCHAR2;
    What you want to look at is p_value to set an initial value. It should come from your data, but you could consider doing an NVL or DECODE to substitute your default.
    In this case it would modify your query to be:
    SELECT distinct apex_item.hidden(1, seq_id), c003,c004,c005, c006,
          APEX_ITEM.SELECT_LIST_FROM_QUERY(6,c020, 'select DISTRIBUTION_NAME, DISTRIBUTION_NAME from DISTRIBUTIONS','style=""),
          SEQ_ID
      FROM APEX_collections
    WHERE collection_name = 'ARGYLL_INVOICES'
    order by seq_id If the value is always NULL, you can use the p_show_null, p_null_value, and p_null_text to put in a "default"
    SELECT distinct apex_item.hidden(1, seq_id), c003,c004,c005, c006,
          APEX_ITEM.SELECT_LIST_FROM_QUERY(6,NVL(c020,0), 'select DISTRIBUTION_NAME, DISTRIBUTION_NAME from DISTRIBUTIONS','style="",YES, 100, 'Default'),
          SEQ_ID
      FROM APEX_collections
    WHERE collection_name = 'ARGYLL_INVOICES'
    order by seq_id

  • How to Get Value from a Variable to restrict a Key Figure ?

    I am trying to make a query in Query designer, we are running BI7.
    I have a user entry veriable on the Fiscal year period, the user will need to enter a period they want the report for, i.e. 07.2008 for July 2008 report and 04.2008 for April 2008 report.
    Based on what the user entered as the starting period (in the variable entry), I have to then use that initial value and show the Year to date value (of sales etc) in the next column.
    To Clarify, if user entered 07.2008 then all the data from 01.2008 to 07.2008 needs to be in the next column.   if user entered 04.2008 then all the data from 01.2008 to 04.2008 should be in the next column.
    So to summarise according to my understanding, I want to get the value from a variable and pass it onto another variable to restrict a key firgure (sales amount)...
    Can someone please clarify what i need to do here?  
    Many thanks in advance, points will be awarded accordingly.

    hi,
    please follow the below steps:
    1. Create a new varialbe , this variable should be processed by customer exit.
    2.  In the column section, create a new column and drag the sales key figure, also drag fiscal year period and restrict with the new variable.
    3. In the cmod tcode write a customer exit code to extract the value of the user entry and assign it your variable, you can refer to the below code.
      WHEN '< New VAR name>'.
        IF I_STEP = '2'.                                 "AFTER THE POPUP
          LOOP AT I_T_VAR_RANGE INTO LOC_VAR_RANGE
            WHERE VNAM = '<Fiscal Year Period VAR Name>'.
            CLEAR L_S_RANGE.
            L_S_RANGE-LOW      = LOC_VAR_RANGE-LOW(4).
            L_S_RANGE-LOW+4(3) = '001'.
            L_S_RANGE-HIGH     = LOC_VAR_RANGE-LOW.       "LOW E.G. 2001006
            L_S_RANGE-SIGN = 'I'.
            L_S_RANGE-OPT = 'BT'.
            APPEND L_S_RANGE TO E_T_RANGE.
            EXIT.
          ENDLOOP.
        ENDIF.
    For ex- if the user enters 008/2008, this code will create as range assign 001/2008 - 008/2008 value to the variable.
    hope it helps,
    rgs,
    Parth.

  • Variable used in FOx formula should get value from user

    Hi Gurus,
    In my fox formula I want to multiply a keyfigure (say quantity) with a factor. For example if the factor is 10 then all records should get multiplied by 10.
    But the requirement is user shpuld be able to give the factor that should be multiplied. That is the l_factor used in the fox function should be a variable which gets value from user. I know we can give variables in filter and planning functions in IP. But can we give values in Fox formula.
    I would really appreciate the time and effort.
    Thanking you,
    Jerry Jerome

    Hello,
    May be you can try this solution.
    I think you have create a dummy character info-object(Z_Number) of same data type interget number.Create variable for Z_Number and restrict in filter(ZV_NUM).
    DATA Z_MAT TYPE 0Material.
    DATA Z_NUM TYPE Z_NUMBER.
    DATA Z_NUM_READ TYPE I.(Declate same as data type for Z_Number)
    Z_NUM = VARV(ZV_NUM).
    FORACH Z_MAT.
    Z_NUM_READ = Z_NUM.
    {Z_KF1,Z_MAT} = Z_NUM_READ * {Z_KF1,Z_MAT}.
    ENDFOR.

Maybe you are looking for