Updating a textfield

Hi!
I have a problem with uptating a textfield.
In my program there are one public class where i create the textfield.
I have also a thread that recieves som data from RS-232 and calculate some variables.
So here is my question!!
How can i update the textfield from the thread?
Thanks for helping:)
Best regards
Stian

Call its setText() method.

Similar Messages

  • Problem updating textField via menuItem

    I am new to java and I am having a problem getting a menuItem to update a text field in my swing app. The following code is a striped down version but contains the necessary code to repeat my problem.
    I'm sure it is something fairly simple, but have had no luck finding a solution. All I want is for a menuItem to update the textfield once selected.
    How can I fix this?
    Please help.
    /*  this class test an implementation of JmenuItem and textfield
    where the menuItem is suppose to update the text in the textField*/
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MenuItemTest
        private GridBagLayout layout;
        private GridBagConstraints constraints;
        private JTextField termField;
        private JLabel headerLabel;
        private JLabel termLabel;
        private JMenuBar menuBar;
        private JMenu menu;
        private JMenuItem menuItem;
        public MenuItemTest()
            // create GUI components
            headerLabel = new JLabel("ItemMenu TextField Test");
            termLabel = new JLabel("Field:");
            termField = new JTextField("choose MenuItem");
        public Container createContentPane()
            //Create the content-pane-to-be.
            JPanel contentPane = new JPanel(new BorderLayout());
            contentPane.setOpaque(true);
            layout = new GridBagLayout();// new gridbaglayout
            JPanel p = new JPanel(layout); // set frame layout
            constraints = new GridBagConstraints(); // instantiate constraints
            // add components to JPane     
            setConstraints( 1,0,6,1,1,10);
            p.add(headerLabel,constraints);
            setConstraints( 2,1,1,1,1,2);
            p.add(termLabel,constraints);
            setConstraints(2,2,2,1,1,2);
            p.add(termField,constraints);
            contentPane.add(p, BorderLayout.CENTER);
            return contentPane;
        }// end createContentPane()
        // method for simplifying grabBagConstraints
        private void setConstraints(int row, int column, int width, int height,
                                    int fill, int ipady)
             constraints.gridx = column; // set gridx
             constraints.gridy = row; // set gridy
             constraints.gridwidth = width; // set gridwidth
             constraints.gridheight = height; // set gridheight
            constraints.insets = new Insets(1,1,0,0);//set uniform vertical gap
            constraints.fill = fill;
            constraints.ipady = ipady;
        }// end method addComponent
        //class for build menu bar
         public class MCalMenu
            public JMenuBar createMenuBar()
                //implements menu handler
                MenuHandler handler = new MenuHandler();
                //Create the menu bar.
                menuBar = new JMenuBar();
                menu = new JMenu("Menu");
                menuBar.add(menu);
                //a group of JMenuItems
                menuItem  = new JMenuItem("Preset Field 1");
                menuItem.addActionListener(handler);
                menu.add(menuItem);
                menuItem = new JMenuItem("Preset Field 2");
                menuItem.addActionListener(handler);
                menu.add(menuItem);
                menuItem = new JMenuItem("Preset Field 3");
                menuItem.addActionListener(handler);
                menu.add(menuItem);
                return menuBar;
            }// end createMenuBar method
        }//end class MCalMenu
        // class for menu events
        public class MenuHandler extends JDialog implements ActionListener
            public void actionPerformed(ActionEvent e)
                if ( e.getActionCommand() == "Preset Field 1")
                    termField.setText("1");
                }//end if
                else if (e.getActionCommand() == "Preset Field 2")
                    termField.setText("2");
                }//end else if
                else if (e.getActionCommand() == "Preset Field 3")
                   termField.setText("3");
                }//end else if   
            }// end actionPerformed method
        }// end MenuHandler class
        public void createAndShowGUI()
            JFrame frame = new JFrame("MenuItem TextField Update Fail");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            MenuItemTest myMenuItemTest = new MenuItemTest();
            MCalMenu myMCalMenu = new MCalMenu();
            frame.setJMenuBar(myMCalMenu.createMenuBar());
            frame.setContentPane(myMenuItemTest.createContentPane());
            frame.setSize(200, 200);
            frame.setVisible(true);
        public static void main(  String args [] )
            MenuItemTest myMenuItemTest = new MenuItemTest();
         myMenuItemTest.createAndShowGUI();
    }

    I think that your problem is that your createAndShowGUI method is creating two separate and distinct objects when you run this program: a MenuItemTest object and a MCalMenu object. As distinct objects, they don't share instance variables which means that this program has two termField JTextFields, one which is visible and the other which is not visible and which you are trying to change. This won't work.
    The other problem is here:
    if ( e.getActionCommand() == "Preset Field 1")don't compare strings with ==. Better to use the String method equals(...)

  • Updating text for non flash users

    Hi there,
    I´ve got a client that wants a basic flash site built
    and they have no Flash or Dreamweaver experience. The main problem
    for me is that they want to be able to update some textfields
    themselves. Their vision is to have like a basic text document that
    they simply upload and bobs your uncle, it´s finished.
    I´m kind of a rookie on flash and site design and know the
    basics, but this is sort of out of my area of knowledge. Greatefull
    for any tips that might solve this problem.
    Regards
    Johan

    you are welc
    me
    If you look at mytext.txt in the text file, I believe you can
    understand it is not suitable to hold data like long text,
    paragraphs, or a lot of data. xml would be easier to manage, if you
    have more data & need to have formatting when display it.
    look at this site
    http://www.kianclassic.com.my/
    - at ContactUs page, the address, tel, fax, all loaded from a
    single XML file, and formatted in that way.
    - at PhotoGallery page, filename & description of each
    photo also loaded from xml.
    By using this way, client can update their contacts info, add
    new photo, by themselve, without need flash software or skill of
    using it.

  • TextField related problem

    Hello friends
    I am using this code and i am changing textField value .
    But it do'nt change .
    It shows only last value .
    But I want to chage in every time in loop .
    please give suggestion.
    Thanks
                import java.awt.BorderLayout;
                import javax.swing.JFrame;
                import javax.swing.JLabel;
                import javax.swing.JPanel;
                import javax.swing.JTabbedPane;
                import javax.swing.JTextField;
                import javax.swing.event.ChangeEvent;
                import javax.swing.event.ChangeListener;
                import javax.swing.*;
                public class Try extends JFrame{
                public JTextField street;
                public Try(String a) {
                super("TabPaneExercise");
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                street  =new JTextField(a);
                street.requestFocusInWindow();
                this.add(street);
                JButton j =new JButton("Hello");
                this.add(j);
                j.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                      search(evt);
                this.getContentPane().add(street, BorderLayout.CENTER);
                 this.getContentPane().add(j, BorderLayout.SOUTH);
                this.setLocation(100, 100);
                this.pack();
                 private void search(java.awt.event.ActionEvent evt)
                    for(int i=0;i<5;i++)
                        synchronized(this)
                            try{
                                    this.wait(1000);
                                    System.out.println("Hay"+i);
                                    this.street.setText("Hay"+i);                 
                                }catch(Exception e){}                 
                public static void main(String[] args)
                     (new Try("hello")).setVisible(true);
    }

    use a timer or put your loop in a separate thread, and update the textfield via
    SwingUtilities.invokeLater(...)

  • How to create an interactive pdf, hyperlinking text to a video on a usb drive?

    Creating an interactive pdf in InDesign CS6, hyperlinking text to a video.  Both pdf and video placed on a usb thumbdrive.  When clicking link on Mac a warning box came up, but after clicking Allow the video played fine.  On PC the warning box also came up but clicking Allow did nothing

    You'll need to use startDrag and stopDrag  in order to be able to move an object (the slider handle).  You will need to specify a rectangle that has 0 height for the drag limits.  The width of that rectangle will define the maximum value of the scroll (which will be the maximum value of your scale.
    Assuming you will have a linear scale for values along the drag line, the math is fairly easy to manage.  The x property of the handle at the minimum slider position should be 0.  You use the ratio of the current x position of the slider handle to the full width to determine what value to assign ( ex: ratio = handle.x / rectangleWidth).  So if the minimum value is 1K and the maximum value in 10K, you essentially have 9K represented by the length of the line, so the value provided by the slider position at any point along that line would be 1K + (ratio * 9K)
    You can use a MOUSE_MOVE event listener that you assign when the slider's MOUSE_DOWN event occurs to update the textfield as the slider is moved.  You can remove the MOUSE_MOVE listener when the slider's MOUSE_UP event occurs.
    So, in summary, you need to look into the startDrag and stopDrag methods, which will be inititiated using MOUSE_DOWN and MOUSE_UP events, respectively.  The MOUSE_DOWN event will create a MOUSE_MOVE listener that you will use to have a function continually update the textfield value displayed, while the MOUSE_UP event will have that MOUSE_MOVE listener removed.  The ratio of the x property of the slider to the total slideable distance will be used to determine the current value that the MOUSE_MOVE event handler assigns to the textfield display.

  • Simple JFrame Doubt

    Why is the jextfield on the jframe so small.
    Also How do I update the textField of MyButton JFrame from JButtonActionListener?
    import java.awt.FlowLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class MYButton extends JFrame {
         JButton jbnButton1;
         JTextField jtfClick;
         MYButton() {
              jbnButton1 = new JButton("Click Me");
              jbnButton1.addActionListener(new JButtonActionListener(MYButton.this));
              jtfClick = new JTextField();
              setLayout(new FlowLayout());
              getContentPane().add(jbnButton1);
              getContentPane().add(jtfClick);
              setSize(400, 400);
              pack();
              setTitle("Example JFrame");
              setVisible(true);
         public static void main(String args[]) {
              new MYButton();
         public JTextField getJtfClick() {
              return jtfClick;
         public void setJtfClick(JTextField jtfClick) {
              this.jtfClick = jtfClick;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    public class JButtonActionListener implements ActionListener {
         JFrame parent;
         public JButtonActionListener(JFrame p) {
              parent = p;
         public void actionPerformed(ActionEvent e) {
    //How do I update the textField of MyButton JFrame from here
    }

    hemanthjava wrote:
    Why is the jextfield on the jframe so small. Because it hasn't been given a preferred size and FlowLayout isn't going to assign it one. Why not initialize it like:
            jtfClick = new JTextField(12);
    Also How do I update the textField of MyButton JFrame from JButtonActionListener?You could pass a reference to the JFrame to the action listener by way of the listener's constructor.

  • How do you animate basic text in FlashDevelop?

    I need a text to be sliding on the Y axis but i cannot seem to figure out the code for it?
    Any ideas?

    start a loop (like enterframe) and repeatedly update the textfields position:
    var tf:TextField=new TextField();
    addChild(tf);
    tf.text="whatever";
    someobjectwithanenterframeevent.addEventListener(Event.ENTER_FRAME,enterframeF);
    function enterFrameF(e:Event):void{
    tf.y+=3;
    if(tf.y>whatever){
    tf.y=0;  // or terminate the loop

  • Jdic browser help

    Hello,
    I used jdic to embed internet explorer in a java application.
    I have a textfield and when the user inputs the website he wishes to visit, the jdic does the work and displays the site.
    My problem is that I dont know how to update the textfield when the user navigates inside the jdic webrowser component.
    Has anyone done something similar ? Could you provide me with an example please.
    Thanks

    I had a look at the JDIC home page and it has both a mailing list and a discussion forum. Wouldn't you get better answers there?

  • Please somebody help me with this

    1.1 modify the application so that:
    i) Information about any foreign key constraints for the selected table is displayed eg as
    additional labels in the table editor window, or in a separate dialog window.
    You can choose how you wish to display this information.
    ii) An Update button is added for each text field in the display, which will attempt to update the corresponding field in the database table, from the current data in the textfield. The following code will retrieve the current value from a JTextField object:
    String newValue = textfieldName.getText();
    The following code will convert the string to a number:
    int newNumber = Integer.parseInt(newValue);
    Remember, an attempt to update a row in a table may fail if eg it tries to alter a
    foreign key to a value not currently recorded for any corresponding primary key
    that the foreign key refers to.
    An attempt to set a foreign key field to 'null' should always be successful.
    If the update attempt fails, the value in the displayed text field should revert to its
    original state, to maintain consistency with the database.
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import oracle.jdbc.driver.*;
    * class JdbcCW
    * demonstration of Java client connecting to an Oracle DBMS
    * @author put your name here
    * @date December 2002
    public class JdbcCW extends JFrame{
    static String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    static String initialquery = "select table_name from user_tables";
    static String nullstring = "null";
    private String user;
    private String pass;
    private Connection conn;
    private Statement stmt;
    private ResultSet results;
    private JComboBox tableChooser;
    private JButton editButton;
    private JButton exitButton;
    private JButton detailsButton;
    private JPanel panel1;
    private JPanel panel2;
    private String selectedTable;
    private Container cp;
    public static void main(String[] args) throws SQLException {
    JdbcCW demo = new JdbcCW();
    demo.show();
    * JdbcCW constructor method
    public JdbcCW() throws SQLException {
    super("Java/Oracle coursework");
    addWindowListener (new WindowAdapter() {
    public void windowClosing (WindowEvent evt) {
    System.exit(0);
    try {
    user =
    JOptionPane.showInputDialog("enter oracle username eg ops$c9999999");
    pass = JOptionPane.showInputDialog("enter oracle password eg 29feb80");
    if ( user.length() == 0 || pass.length() == 0)
    throw new Exception("no user name and/or password");
    DriverManager.registerDriver (new OracleDriver());
    conn = DriverManager.getConnection(url, user, pass);
    if (conn != null)
    System.out.println("Connected");
    catch (Exception e ) {
    e.printStackTrace();
    System.exit(0); // problems - abandon ship
    // now we can access tables in the database
    stmt = conn.createStatement();
    results = stmt.executeQuery(initialquery);
    boolean anyRecords = results.next();
    if ( ! anyRecords ) {
    JOptionPane.showMessageDialog (this, "No Tables in the database");
    System.exit(0);
    tableChooser = new JComboBox();
    do
    tableChooser.addItem(results.getString(1));
    while (results.next() ) ;
    selectedTable = (String) tableChooser.getSelectedItem();
    tableChooser.addActionListener (new ActionListener () {
    public void actionPerformed (ActionEvent evt) {
         changeTable();
    editButton = new JButton("Edit");
    editButton.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent evt) {
         runEdit();
    exitButton = new JButton("Exit");
    exitButton.addActionListener(new ActionListener () {
    public void actionPerformed(ActionEvent evt) {
    System.exit(0);
    panel1 = new JPanel(); // panels have flow layout
    JLabel label1 = new JLabel("Choose Table");
    panel1.add(label1);
    panel1.add(tableChooser);
    panel2 = new JPanel();
    panel2.add(editButton);
    panel2.add(exitButton);
    cp = getContentPane();
    cp.add(panel1,BorderLayout.NORTH);
    cp.add(panel2,BorderLayout.SOUTH);
    setSize(300,200);
    setLocation(100,100);
    private void changeTable() {
    selectedTable = (String) tableChooser.getSelectedItem();
    * method runEdit runs a query to determine the structure of the
    * selected table in order to customise the table editor window
    private void runEdit() {
    System.out.println("Selected Table " + selectedTable);
    String query = "select column_name,data_type from user_tab_columns " +
         "where table_name = '" + selectedTable + "'";
    try {
         results = stmt.executeQuery(query);
    } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query " + query);
         return;
    JdbcEdit tableEditor = new JdbcEdit(this,selectedTable,results);
    tableEditor.show();
    public ResultSet makeQuery(String query) {
         ResultSet results;
         try {
         results = stmt.executeQuery(query);
         } catch (SQLException e) {
         System.out.println("Query Failed " + query);
         return null;
         return results;
    } // end class JdbcGen
    * class JdbcEdit
    * oracle table editing dialog window
    * @author put your name here as well
    * @date December 2002
    class JdbcEdit extends JDialog {
    private JdbcCW parent;
    private Container cp;
    private Vector columnNames;
    private Vector dataTypes;
    private Vector editFields;
    private Vector rows;
    private int noOfColumns;
    private int currentRow = 0;
    * JdbcEdit constructor method
    * the parameter true makes the dialog window modal -
    * the parent frame is inactive as long as this window is displayed
    public JdbcEdit (JdbcCW parent, String tableName, ResultSet results) {
         super(parent,"table editor " + tableName, true);
         this.parent = parent;
    columnNames = new Vector();
    dataTypes = new Vector();
         editFields = new Vector();
         JPanel mainPanel = new JPanel();
         mainPanel.setLayout(new BoxLayout(mainPanel,BoxLayout.Y_AXIS));
    // boxLayout - components are added to mainPanel in a vertical stack
         try {
         boolean anyRecords = results.next();
         if ( ! anyRecords ) {
              JOptionPane.showMessageDialog (this, "No Detail for " +
                             tableName+ " in the database");
              return;
         do {
              String columnName = results.getString(1);
              String dataType = results.getString(2);
              System.out.println("Row " + columnName + " Type " + dataType);
              JPanel editPanel = new JPanel();
              JLabel colNameLabel = new JLabel(columnName);
              JTextField dataField = new JTextField(20);
              editPanel.add(colNameLabel);
              editPanel.add(dataField);
    // this would be a good place to add an Update button
              mainPanel.add(editPanel);
    // now store the columnName, dataType and data text field
    // in vectors so other methods can access them
    // at this point in time the text field is empty
              columnNames.add(columnName);
              dataTypes.add(dataType);
         editFields.add(dataField);
         }while (results.next() ) ;
         } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query ");
         return;
    // get the data from the Oracle table and put the first
    // row of data in the text fields in the dialog window
         populateData(tableName);
    // find out which column(s) are part of the primary key and make these
    // textfields non-editable so the values can't be changed
    findPKConstraints(tableName);
    // this would be a good place to discover any foreign key constraints
         JPanel buttonsPanel = new JPanel();
         JButton exitButton = new JButton("Exit");
         exitButton.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent evt) {
              closeWindow();
         JButton nextButton = new JButton("Next");
         nextButton.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent evt) {
              showRow(true);
         JButton prevButton = new JButton("Prev");
         prevButton.addActionListener(new ActionListener () {
         public void actionPerformed(ActionEvent evt) {
              showRow(false);
         buttonsPanel.add(exitButton);
         buttonsPanel.add(nextButton);
         buttonsPanel.add(prevButton);
    cp = getContentPane();
         cp.add(mainPanel,BorderLayout.CENTER);
         cp.add(buttonsPanel,BorderLayout.SOUTH);
         pack();
    private void closeWindow() {
         dispose();
    private void populateData(String tableName) {
    int noOfColumns;
    // have to access the Statement object in the parent frame
         ResultSet tableData = parent.makeQuery("select * from " + tableName);
         try {
         boolean anyRecords = tableData.next();
         if ( ! anyRecords ) {
              JOptionPane.showMessageDialog (this, "No data in " +
                             tableName);
              return;
         rows = new Vector();
    noOfColumns = columnNames.size();
         do {
              String [] row = new String[noOfColumns];
              for (int i = 0; i < noOfColumns; i++) {        
              row[i] = tableData.getString(i+1);
              rows.add(row);
         } while (tableData.next() ) ;
         } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query ");
         return;
    // Put the first row of data from the table into the test fields;
         String [] rowData = (String[]) rows.get(0);
         for (int i = 0; i < noOfColumns; i++) {
    // get the reference to a text field in the dialog window
    JTextField textField = (JTextField) editFields.get(i);
    // vector editFields holds a reference to each JTextField
    // in the visible dialog window
    // hence the next line of code puts the data retrieved from
    // the table into the relevant text field in the GUI interface
         textField.setText(rowData);
    // method showRow updates the textfields in the GUI interface
    // with the next row of data from the table ( if next is true)
    // or with the previous row of data from the table ( if next is false)
    private void showRow(boolean next) {
    if ( rows == null ) {
    System.out.println("table is empty");
         getToolkit().beep();
         return;
         if (next && currentRow < rows.size() - 1) {
         currentRow++;
         } else if (!next && currentRow > 0) {
         currentRow--;
         } else {
         System.out.println("No Next/Prev row " + currentRow);
         getToolkit().beep();
         return;
         String [] rowData = (String[]) rows.get(currentRow);
    int noOfAttributes = dataTypes.size();
         for (int i = 0; i < noOfAttributes; i++) {
         JTextField textField = (JTextField) editFields.get(i);
         textField.setText(rowData[i]);
    private void findPKConstraints(String tableName){
         String PK_ConstraintName = "none";
         String pkquery =
    "select owner,constraint_name from user_constraints " +
         "where table_name = '" + tableName + "' and constraint_type = 'P'";
    // have to access the Statement object in the parent frame
         ResultSet results = parent.makeQuery(pkquery);
         try {
         boolean anyRecords = results.next();
         if ( ! anyRecords ) {
              // if none just return - but print a debug message
              System.out.println("No primary key constraint found");
              return;
         } else {
              // There should only be one
              System.out.println("Owner = " + results.getString(1) +
                        " name = " + results.getString(2));
              PK_ConstraintName = results.getString(2);
              // Now find out which columns
              pkquery =
    "select Column_name, position from user_cons_columns"
              + " where constraint_name = '" + PK_ConstraintName
              + "'";
    // have to access the Statement object in the parent frame
              results = parent.makeQuery(pkquery);
              anyRecords = results.next();
              if ( ! anyRecords ) {
              // if none just return - but there must be at least one
              System.out.println("no columns found");
              return;
              } else {
              do {
                   System.out.println
    ("Name " + results.getString(1) +
                   " position " + results.getString(2))
                   int position = Integer.parseInt(results.getString(2));
                   JTextField primarykey =
    (JTextField)editFields.get(position - 1);
                   primarykey.setEditable(false);
              } while (results.next());
         } catch (java.sql.SQLException e) {
         System.out.println("SQL Exception on query " + pkquery);
         return;

    You're pretty optimistic if you think anyone is going to answer that. There are three very good reasons not to (each is good enough by themselves!).
    1. IT'S YOUR HOMEWORK, IT DOESN'T EVEN LOOK AS THOUGH YOU'VE TRIED. WE HELP WITH PROBLEMS, NOT PROVIDE SOLUTIONS, ESPECIALLY FOR HOMEWORK.
    2. Format your code. Use [ code] and [ /code] (without the spaces). And if you've used 'i' as an index variable, [ i] will result in switching to italics mode. Use 'j' as your index variable.
    3. Don't post your whole program, only the parts you're having trouble with (mostly not relevant for this question, as you don't seem to have trouble with any particular area)

  • Button Action Procedure

    I'm missing something basic.
    I have a button. It's action event handler (button_action() ) sets a SessionBean1.property to a value. But it seems that the handler is called each time I update a textfield on the page. I thought the event handler is only called when the button is pressed....
    URL of appropriate tutorial, please........
    thank you
    (last stupid question I will post today... promise)
    harold

    you are a busy one today :)
    wow that sounds quite bizarre - did you put a log method call at the top of the button click and you see it getting called w/o pressing the button??
    do you have validators or converters on your textfields?
    what's in your constructor?
    v

  • JFrame calling another JFrame

    Hello,
    I have a simple question:
    2 java files with 2 JFrames in them
    JFrame1(Cars.java) calls JFrame2(AddCar.java) from actionlistener.
    What I think is wrong is JFrame1 actionListener:
    if(ae.getSource() == CarEdit_btn){
    AddCar objEditAddCar = new AddCar();
    objEditAddCar.EditCar();
    And JFrame2's EditCar() method:
    public void EditCar(){
    AddCar windowAddCar1 = new AddCar();
    windowAddCar1.setTitle("Add Car");
    windowAddCar1.pack();
    windowAddCar1.show();
    AddCarMilage_txt.setText("544");
    The problem is that AddCarMilage_txt.setText("544"); doesnt update the value of the JTextField of JFrame2.
    Any ideas? Thanks
    Or another way to go around for me is, how do I use args[] from main inside the constructor?

    read this:
    http://forum.java.sun.com/thread.jspa?threadID=5199666&messageID=9792440#9792440
    it has also 2 classes and updates the textfield of the other class just copy and paste the code.

  • Inheriting from MovieClip

    Hi all,
    I'm new to Flash and I'm new to OOP, and so I'm having a bit
    of trouble writing ActionScript programs to do exactly what I want.
    I am trying to create a simple application, in which a
    MovieClip is dragged around the screen and a textbox gets updated
    with the MovieClip's coordinates somewhere else on the screen. I
    wanted to do this using custom classes, so I created a class called
    MovieClipCoordinates that would contain a MovieClip and a
    TextField. I am initializing the MovieClip as the output of a
    this.createEmptyMovieClip() of the main movie, and the TextField
    similarly.
    My intention is to have the TextField updated whenever the
    MovieClip is dragged. So, in the onRelease function of the
    MovieClip, I need to update the TextField of the
    MovieClipCoordinates object that the MovieClip is a property of.
    The problem is, I have no idea how to find out the
    MovieClipCoordinates that the MovieClip belongs to. I thought I
    would create a method in the MovieClipCoordinates class that would
    set the TextField, which would be called from the
    MovieClip.onRelease. So I figured I would not have a MovieClip
    inside the MovieClipCoordinates class, but instead another class
    inherited from MovieClip which also contains a reference to the
    MovieClipCoordinates class that it is a member of. However, the
    problem now is that I can no longer create this subclass through a
    call to createEmptyMovieClip. So how do I create it?
    I'm getting a bit confused at this point of time. Could
    someone please give me some idea of how to do this?
    Thanks.
    Ajit

    LuigiL,
    Thank you very much for your assistance. I truly appreciate
    it.
    Though the code works perfectly, I wonder if I may trouble
    you to clarify a couple of questions that I have with your code.
    Looking particularly at this section of the code:
    private function setHandlers(target_mc:MovieClip):Void{
    //use a reference to the current object
    var thisObj:MovieClipCoordinates=this;
    target_mc.onPress=function():Void{
    this.startDrag();
    target_mc.onRelease=function():Void{
    this.stopDrag();
    //get the new coordinates
    var thisX=thisObj.box_mc._x;
    var thisY=thisObj.box_mc._y;
    //and refresh the text
    thisObj.printCoordinates(thisX,thisY);
    How is it legal to use thisObj inside the onRelease function?
    I was under the impression that the onRelease function is a
    separate function altogether, that is called in the context of the
    MovieClip that it is associated with. How does it have knowledge of
    thisObj, which was defined in scope above it?
    Would it be even possible to define the onPress and onRelease
    functions above as two separate functions (CoordinatesPress and
    CoordinatesRelease, for example) and rewrite the above code as
    follows?:
    private function setHandlers(target_mc:MovieClip):Void{
    //use a reference to the current object
    var thisObj:MovieClipCoordinates=this;
    target_mc.onPress=CoordinatesPress;
    target_mc.onRelease=CoordinatesRelease;
    defining the handler functions separately. If I chose to do
    this, how would I possibly pass the thisObj to the handlers?
    I seem to be missing something fundamental in ActionScript
    functions, or perhaps just in the event-handlers. I would
    appreciate it if you could help me clear this up.
    Thanks again,
    Ajit

  • How to pass values from one function to another

    Hi,
    I am a middle school teacher and a newbie in Flash Actionscript. I am trying to create a countdown timer for use in my class during tests. The start and pause functions work as required, but not the pause button. When I click on the pause button, the timer is reset to 0:00:00. Please help. Here is the code I had written so far:
    var Subject1timeLeftHr;
    var Subject1timeLeftMin;
    var Subject1timeLeftSec;
    Subject1start_btn._visible = true;
    Subject1pause_btn._visible = false;
    Subject1rotor_mc.gotoAndStop(1);
    Subject1rotor_mc._visible = false;
    Subject1durationHr_txt.text = "0";
    Subject1durationMin_txt.text = "00";
    Subject1durationSec_txt.text = "00";
    Selection.setFocus(Subject1durationHr_txt);
    function SubjectdurationHr(SubjectxdurationHr_txt, SubjectxdurationMin_txt)
    if (SubjectxdurationHr_txt.length == 1)
    Selection.setFocus(SubjectxdurationMin_txt);
    function SubjectdurationMin(SubjectxdurationMin_txt, SubjectxdurationSec_txt)
    if (SubjectxdurationMin_txt.length == 2)
    Selection.setFocus(SubjectxdurationSec_txt);
    function SubjectdurationSec(SubjectxdurationSec_txt, SubjectxdurationHr_txt)
    if (SubjectxdurationSec_txt.length == 2)
    Selection.setFocus(SubjectxdurationHr_txt);
    Subject1durationHr_txt.onChanged = function()
    SubjectdurationHr(Subject1durationHr_txt,Subject1durationMin_txt);
    Subject1durationMin_txt.onChanged = function()
    SubjectdurationMin(Subject1durationMin_txt,Subject1durationSec_txt);
    Subject1durationSec_txt.onChanged = function()
    SubjectdurationSec(Subject1durationSec_txt,Subject1durationHr_txt);
    function startcountdown(SubjectxdurationLeft, SubjectxdurationHr, SubjectxdurationHr_txt, SubjectxdurationMin, SubjectxdurationMin_txt, SubjectxdurationSec, SubjectxdurationSec_txt, Subjectxduration, SubjectxstartTime, SubjectxendTime, Subjectxtimer_mc, Subjectxpause_btn, Subjectxstart_btn, Subjectxrotor_mc, SubjectxtimeLeft, SubjectxtimeLeftHr, SubjectxtimeLeftMin, SubjectxtimeLeftSec, SubjectxtimeLeftHr_txt, SubjectxtimeLeftMin_txt, SubjectxtimeLeftSec_txt)
    delete SubjectxdurationLeft;
    delete SubjectxdurationHr;
    delete SubjectxdurationMin;
    delete SubjectxdurationSec;
    delete Subjectxduration;
    delete SubjectxdurationHr_txt.text;
    delete SubjectxdurationMin_txt.text;
    delete SubjectxdurationSec_txt.text;
    SubjectxstartTime = getTimer();
    Subjectxtimer_mc.onEnterFrame = function()
    if (SubjectxdurationHr_txt.text == Nan || SubjectxdurationMin_txt.text == Nan || SubjectxdurationSec_txt.text == Nan)
    else
    SubjectxdurationHr = 60 * 60 * 1000 * Number(SubjectxdurationHr_txt.text);
    SubjectxdurationMin = 60 * 1000 * Number(SubjectxdurationMin_txt.text);
    SubjectxdurationSec = 1000 * Number(SubjectxdurationSec_txt.text);
    Subjectxduration = SubjectxdurationHr + SubjectxdurationMin + SubjectxdurationSec;
    SubjectxendTime = SubjectxstartTime + Subjectxduration;
    SubjectxdurationLeft = SubjectxendTime - getTimer();
    if (SubjectxdurationLeft > 0)
    SubjectxdurationHr_txt._visible = false;
    SubjectxdurationMin_txt._visible = false;
    SubjectxdurationSec_txt._visible = false;
    Subjectxpause_btn._visible = true;
    Subjectxstart_btn._visible = false;
    Subjectxrotor_mc._visible = true;
    Subjectxrotor_mc.play();
    SubjectxtimeLeft = SubjectxdurationLeft / (1000 * 60 * 60);
    SubjectxtimeLeftHr = Math.floor(SubjectxtimeLeft);
    SubjectxtimeLeftMin = Math.floor((SubjectxtimeLeft - SubjectxtimeLeftHr) * 60);
    SubjectxtimeLeftSec = Math.floor(((SubjectxtimeLeft - SubjectxtimeLeftHr) * 60 - SubjectxtimeLeftMin) * 60);
    SubjectxtimeLeftHr_txt.text = String(SubjectxtimeLeftHr);
    if (SubjectxtimeLeftHr_txt.length < 1)
    SubjectxtimeLeftHr_txt.text = "0" + SubjectxtimeLeftHr_txt.text;
    SubjectxtimeLeftMin_txt.text = String(SubjectxtimeLeftMin);
    if (SubjectxtimeLeftMin_txt.length < 2)
    SubjectxtimeLeftMin_txt.text = "0" + SubjectxtimeLeftMin_txt.text;
    SubjectxtimeLeftSec_txt.text = String(SubjectxtimeLeftSec);
    if (SubjectxtimeLeftSec_txt.length < 2)
    SubjectxtimeLeftSec_txt.text = "0" + SubjectxtimeLeftSec_txt.text;
    else
    delete Subjectxtimer_mc.onEnterFrame;
    SubjectxtimeLeftHr_txt.text = "";
    SubjectxtimeLeftMin_txt.text = "";
    SubjectxtimeLeftSec_txt.text = "";
    SubjectxdurationHr_txt._visible = true;
    SubjectxdurationMin_txt._visible = true;
    SubjectxdurationSec_txt._visible = true;
    Subjectxrotor_mc.gotoAndStop(1);
    Subjectxrotor_mc._visible = false;
    SubjectxdurationHr_txt.text = "0";
    SubjectxdurationMin_txt.text = "00";
    SubjectxdurationSec_txt.text = "00";
    Subjectxpause_btn._visible = false;
    Subjectxstart_btn._visible = true;
    Selection.setFocus(SubjectxdurationHr_txt);
    function pausecountdown(SubjectxdurationHr_txt, SubjectxtimeLeftHr, SubjectxdurationMin_txt, SubjectxtimeLeftMin, SubjectxdurationSec_txt, SubjectxtimeLeftSec, Subjectxstart_btn, Subjectxpause_btn, Subjectxrotor_mc)
    delete Subjectxtimer_mc.onEnterFrame;
    SubjectxdurationHr_txt.text = String(SubjectxtimeLeftHr);
    SubjectxdurationMin_txt.text = String(SubjectxtimeLeftMin);
    SubjectxdurationSec_txt.text = String(SubjectxtimeLeftSec);
    Subjectxstart_btn._visible = true;
    Subjectxpause_btn._visible = false;
    Subjectxrotor_mc.stop();
    Subject1pause_btn.onRelease = function()
    pausecountdown(Subject1durationHr_txt,Subject1timeLeftHr,Subject1durationMin_txt,Subject1t imeLeftMin,Subject1durationSec_txt,Subject1timeLeftSec,Subject1start_btn,Subject1pause_btn ,Subject1rotor_mc);
    Subject1start_btn.onRelease = function()
    startcountdown(Subject1durationLeft,Subject1durationHr,Subject1durationHr_txt,Subject1dura tionMin,Subject1durationMin_txt,Subject1durationSec,Subject1durationSec_txt,Subject1durati on,Subject1startTime,Subject1endTime,Subject1timer_mc,Subject1pause_btn,Subject1start_btn, Subject1rotor_mc,Subject1timeLeft,Subject1timeLeftHr,Subject1timeLeftMin,Subject1timeLeftS ec,Subject1timeLeftHr_txt,Subject1timeLeftMin_txt,Subject1timeLeftSec_txt);
    Subject1cancel_btn.onRelease = function()
    Subject1timeLeftHr_txt.text = "";
    Subject1timeLeftMin_txt.text = "";
    Subject1timeLeftSec_txt.text = "";
    Subject1durationHr_txt._visible = true;
    Subject1durationMin_txt._visible = true;
    Subject1durationSec_txt._visible = true;
    Subject1durationHr_txt.text = "0";
    Subject1durationMin_txt.text = "00";
    Subject1durationSec_txt.text = "00";
    Subject1timeLeftHr_txt._visible = true;
    Subject1timeLeftMin_txt._visible = true;
    Subject1timeLeftSec_txt._visible = true;
    Subject1pause_btn._visible = false;
    Subject1start_btn._visible = true;
    Subject1rotor_mc._visible = false;
    Subject1rotor_mc.gotoAndStop(1);
    delete Subject1timer_mc.onEnterFrame;
    delete Subject1durationLeft;
    delete Subject1duration;
    delete Subject1durationHr_txt.text;
    delete Subject1durationMin_txt.text;
    delete Subject1durationSec_txt.text;

    I think you need to spend some time reducing your code to practical levels.  You seem to be passing everything in the book to every function and I would guess that probably none of it is necessary.  If you declared those variables at the beginning, then you don't need to pass them into any function because they are gobally available to any of the code/functions that follows them.  Similarly, if you have textfields on the stage, you do not need to pass those into any functions for the same reason.
    I see you making overuse of "delete" (and possibly errant use as well).  Probably the only thing you might want/need to use is...
    delete Subjectxtimer_mc.onEnterFrame;
    Which stops the enterframe activity from firing off, which I will guess is being used to update the textfields that indicate the time.
    And that conditional that uses == Nan isn't likely to do anything except wonder what an Nan is.  Textfields hold strings, which are quoted.  SO unless you have a variable named Nan somewhere that has a String value assigned to it, that conditional won't be doing anything for you.  You probably won't need it at all if you get this working properly.

  • Load and Send XML values

    I am new to ActionScript 3 and have a project I would like to get some help on. I have an XML file on a server that has two types of parent nodes... an example is below:
    <bodytypesuggestions>
    <ID1>36</ID1>
    <ID2>34</ID2>
    <ID3>37</ID3>
    </bodytype>
    <bodytypes>
    <ID1>34</ID1>
    <ID2>32</ID2>
    <ID3>35</ID3>
    </bodytype>
    The AS code below connects my flash to the URL:
    import flash.net.*;
    import flash.events.*;
    var myXML:XMLList;
    var url:URLRequest = new URLRequest("MYSERVER.COM");
    var XMLLoader:URLLoader = new URLLoader(url);
    XMLLoader.addEventListener(Event.COMPLETE, GetRecommendations);
    XMLLoader.addEventListener(Event.CHANGE, updateAndGetRecommendations);
    function GetSuggestions(event:Event):void {
    if (XMLLoader.data) {
    myXML = XMLList(XMLLoader.data);
    var myDev:XMLList = new XMLList(XMLLoader.data)
    var bodytypelist:XMLList = myDev..bodytypes
    var bydytypesugglist:XMLList = myDev..bodytypesuggestions
    trace(bodytypelist);
    this["ID1"].text = bodytypelist.ID1;
    this["ID1"].restrict = "0-9.";
    this["ID1"].maxChars = 5;
    this["ID2"].text = bodytypelist.ID2;
    this["ID2"].restrict = "0-9.";
    this["ID2"].maxChars = 5;
    this["ID3"].text = bodytypelist.ID3;
    this["ID3"].restrict = "0-9.";
    this["ID3"].maxChars = 5;
    Now in my flash file, I have 3 textInput fields that are populated with the above XML values from the bodytype child values.
    My question is - how can I write a function that when a user changes a value in any one of the text fields, the data returned is from the bodytypesuggestions node value instantly, i.e. once a field value is changed, the other two will change accordingly. The actual XML on the server already handles those calculations. I hope this makes sense, I really need some help on this one.

    I am not 100% certain what you're asking for here...
    I would tend to send XML rather than an XMLList string. I can't get the e4x filtering to work for an XMLList like that, which means (I assume) that you would need to iterate the list and using filtering on each XML object in the list. Perhaps I've missed something as you don't seem to be expressing a problem with loading the xml data and getting it into the textfields initially. I've not tried using the filtering on an XMLList directly before but could not get it working the way you have it. So in the following simulation I have wrapped the list in a top level tag to get it working the way I wanted.
    Here is a non-loading simulation of what you seem to want. The difference here is that the GetSuggestions 'listener' is called manually with the data string rather than by the URLLoader's listener with the data attached to the URLLoader's dispatched event.
    Hope that helps some.
    var xStr:String="<bodytypesuggestions><ID1>36</ID1><ID2>34</ID2><ID3>37</ID3></bodytypesuggestions><bodytypes><ID1>34</ID1><ID2>32</ID2><ID3>35</ID3></bodytypes>";
    var myXML:XML;
    var suggestions:XMLList;
    //requires 3 input textfields on the stage named ID1, ID2, ID3
    function GetSuggestions(data:String):void {
    if (data) {
    var myXML:XML = XML("<wrapper>"+XMLList(data).toXMLString()+"</wrapper>");
    var bodytypelist:XMLList = myXML..bodytypes;
    suggestions = myXML..bodytypesuggestions;
    ID1.text = bodytypelist.ID1;
    ID1.restrict = "0-9.";
    ID1.maxChars = 5;
    ID2.text = bodytypelist.ID2;
    ID2.restrict = "0-9.";
    ID2.maxChars = 5;
    ID3.text = bodytypelist.ID3;
    ID3.restrict = "0-9.";
    ID3.maxChars = 5;
    GetSuggestions(xStr)
    ID1.addEventListener(Event.CHANGE,myTextListener)
    ID2.addEventListener(Event.CHANGE,myTextListener)
    ID3.addEventListener(Event.CHANGE,myTextListener)
    function myTextListener(e:Event):void{
         var updates:Array = ['ID1','ID2','ID3'];
         //check to see if current value is recognized
         if (TextField(e.currentTarget).text == suggestions.elements(TextField(e.currentTarget).name).text()){
              trace('found match')
              for each(var fieldName:String in updates){
                   if (TextField(e.currentTarget).name==fieldName) continue;
                   TextField(this[fieldName]).text = suggestions.elements(fieldName).text();
                   trace(' set '+fieldName + ' to '+TextField(this[fieldName]).text)

  • Popup problem needs guidance

    I have a jsp which create a pop up if user clicks on a link. The pop then displays some checkbox where user can check on 1 or more. Once done, user clicks on finish button which supposely close the popup window, pass the value of the checkboxes back to text fields in the parent windows. How would I go about doing this? Please help. Code sample will help a lot. Javascript is preferable. Thanks.

    One way might be to pass all of your param values to
    your pop up when you call it. Since you are not
    displaying all of your params, store them as "hidden"
    input fields in your pop up page. Display and provide
    as form inputs for the check boxes you mentioned.
    When you submit this page, call the original page in
    your window opener, which would take these values you
    are passing back and redisplay to the user.
    hope this was helpful
    MKRThis is a great idea, but if they're just putting the values into textfields, isn't it a bit of overkill? If they had to change the actual text on the page, then that would an awesome way to do it, but since you can update the textfield values easily with a little JavaScript, it wouldn't really be necessary to put another call into the server. The JavaScript can do all the work client-side, and not have to hit the server again.
    (I'm sorry if that sounds kind of anal, but I'm not only a developer, I'm also the server admin. So, I try to keep requests to a minimum. Just a thought though, both are valid ideas. I wasn't flaming MKR, I really liked that idea actually, but maybe not for this application - unless of course they were only using textfield b/c they're easy to update.)

Maybe you are looking for

  • Problem with application.cfm

    I'm just getting back into coldfusion after a few years...and i'm already running into a problem with the application.cfm What could cause this simple error when I try to go to a coldfusion page (the cfm page would load prior to adding the applicatio

  • IPhoto Images Showing Up in iLife Media Browser, Desktop/ScreenSaver, Etc.

    Like others, I'm having the problem where my iPhoto library/images are not showing up in the iLife Media Browser in other iLife and iWork applications. They are also not showing up in the Desktop & Screen Saver system preferences. I've read a lot of

  • 3.3.3 hangs all the time and crashes browser, 4.0 beta crashed Vista

    see subject == User Agent == Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729)

  • High Quality Wide Screen for YouTube - PLEASE HELP!

    I am using a Panasonic PV-GS400 camera in wide-screen mode (this is another topic, but the camera still outputs 720 x 480 video, my understanding is that it is called "anamorphic wide screen"). I had figured out some settings to get my videos to appe

  • Setup sol-8 reboots (dump device not found)

    i have a pIII intel system and im trying to setup sol 8 on it. it detects the hardware but when it gets to the interactive and jumpstart and i select either of the two, the system gives a brief message, no dump device found, rebooting and reboots. it