These two lines (might) count as the "application code:"
String name = inText.getText(); outText.setText( name );
(Although it could be argued that there is no application code because all the code deals with the GUI.)
In a typical application with a graphical interface, about 40% of the code manages the user interface. The rest of the code is for the application--the reason the program was written. Usually the application code is kept separate from the code that manages the interface. In a big application it would be confusing to mix the two together. Here is our tiny application with a separate method for the application code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Repeater extends JFrame implements ActionListener { JLabel inLabel = new JLabel( "Enter Your Name: " ) ; TextField inText = new TextField( 15 ); JLabel outLabel = new JLabel( "Here is Your Name :" ) ; TextField outText = new TextField( 15 ); public Repeater() // constructor { getContentPane().setLayout( new FlowLayout() ); getContentPane().add( inLabel ) ; getContentPane().add( inText ) ; getContentPane().add( outLabel ) ; getContentPane().add( outText ) ; inText.addActionListener( this ); setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE ); } // The application code. void copyText() { String name = inText.getText(); outText.setText( name ); } public void actionPerformed( ActionEvent evt) { copyText(); repaint(); } public static void main ( String[] args ) { Repeater echo = new Repeater() ; echo.setSize( 300, 100 ); echo.setVisible( true ); } }
In large applications the application code and the GUI code are kept in many separate files.
When you enter text into the top TextField and hit enter, the text is copied to the lower TextField. What happends if you enter text into the lower TextField and hit enter?