Link to home
Start Free TrialLog in
Avatar of sgenoves116
sgenoves116

asked on

New Java code isn't seen at run time. Still see "old code"

I built a small swing program that displays a button and using an ActionEvent changes the button text from "click me" to "I've been clicked".   I then decided to delete *all* button code and associated ActionEvent and add a JTextField instead.  It complies fine, but when I run it, I still get the button and the ActionEvent behaviour.  I made sure I saved my edits and am at a loss why I still get the old code behaviour.
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Probably 'cos you're running the old code ;-)
When i've had this before, i've put this as the first line of main:

System.out.println("This is the NEW code");
Avatar of sgenoves116
sgenoves116

ASKER

Here's the code.  I added the println and do see "This is the NEW code" in the command window, but still get the button instead of my textfield.  I'm using javac/java on the command line, no IDEs.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class OpenGui4 {

  public static void main (String[] args) {
 
     SimpleGui1 gui = new SimpleGui1();
     System.out.println("This is the NEW code");
     gui.go();
}

     public void go() {
     //create a frame
     JFrame frame = new JFrame();
     
     JTextField Tfield = new JTextField(20);
    //  Tfield.addActionListener(this);
     
   
     
     // when the window is closed, exit the program
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
     
     frame.getContentPane().add(BorderLayout.EAST, Tfield);
     
     //set the size, in pixels of the frame
     frame.setSize(500,500);
     
     // make frame visible
     frame.setVisible(true);
     
     Tfield.requestFocus();
    }  // end of go method
 

} //end of class
     
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)