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

Posted on 2005-04-22
Last Modified: 2010-03-31
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.
Question by:sgenoves116
    LVL 86

    Expert Comment

    Probably 'cos you're running the old code ;-)
    LVL 86

    Expert Comment

    When i've had this before, i've put this as the first line of main:

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

    Author Comment

    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");

         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.getContentPane().add(BorderLayout.EAST, Tfield);
         //set the size, in pixels of the frame
         // make frame visible
        }  // end of go method

    } //end of class
    LVL 86

    Accepted Solution

    You're not running the go() of OpenGui4

    >>SimpleGui1 gui = new SimpleGui1();

    should be

    OpenGui4  gui = new  OpenGui4();
    LVL 86

    Expert Comment


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now