Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 22 of 22

Thread: When I press on "new" in the menu in my GUI the program doesn't initialize (reset)

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default [SOLVED] When I press on "new" in the menu in my GUI the program doesn't initialize

    Hi everyone this time it's not an exercise from the Java book I'm using to practicing but from my school project which I have to turn in soon. After many failure tries, I hope someone in here can help me fix what I'm doing wrong.

    I'm putting up a minimized code since the extras I've deleted aren't that important in this context and will only confuse more than help.

    The SimpleFrame class:
    import javax.swing.JFrame;
     
    public class SimpleFrame extends JFrame {
     
    	public SimpleFrame(){
     
    		//Set the size and the location of the frame:
     
    		setSize(750,500);
    		setLocation(200,100);
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setResizable(false);
     
    	}
     
    	public void showIt(){
    		this.setVisible(true);
    	}
     
    	public void showIt(String title){
    		this.setTitle(title);
    		this.setVisible(true);
    	}
     
    	public void showIt(String title, int x, int y){
    		this.setTitle(title);
    		this.setLocation(x, y);
    		this.setVisible(true);
     
    	}
     
     
    	public void hideIt(){
    		this.setVisible(false);
    	}
     
     
     
     
    }

    The ColorPanel class:
    import java.awt.*;
    import javax.swing.JPanel;
     
     
    public class ColorPanel extends JPanel{
    	//Generate a JPanel with background color col, width width and height height.
     
    	public ColorPanel(Color col){
    		setBackground(col);
    	}
     
    	public ColorPanel(Color col, int width){
    		this.setPreferredSize(new Dimension(width, this.getHeight()));
    		setBackground(col);
    	}
     
    	public ColorPanel(Color col, int width, int height){
    		this.setPreferredSize(new Dimension(width, height));
    		setBackground(col);
    	}
     
    }

    ...and lastly the MainGUI class which is the one where the problem occurs:
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JTextField;
    import javax.swing.filechooser.FileFilter;
     
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.util.Scanner;
     
    public class MainGUI extends SimpleFrame{	
    	private JTextField field1= new JTextField(20);
    	private JTextField field2= new JTextField(20);
     
    	private JLabel similarity1 = new JLabel("Similarity1");
     
    	private JLabel time1 = new JLabel("Time1");
     
    	public MainGUI(){
     
    		this.setLayout(new GridBagLayout());
    		GridBagConstraints c = new GridBagConstraints();
    		setBackground(Color.LIGHT_GRAY);
     
    		//Buttons, fields, labels START
    		c.anchor = GridBagConstraints.FIRST_LINE_START; //bottom of space
    		c.gridx = 0;        //Moves via x in colums
    		c.gridwidth = 0;   //2 columns wide
    		c.gridy = 0;        //moves via y in rows
     
    		JButton text1Button = new JButton("Text 1: ");
    		c.insets = new Insets(20,35,0,0); //moves the starting point from (top, left, bottom, right)  
    		this.add(text1Button, c);
     
    		JButton text2Button = new JButton("Text 2: ");
    		c.insets = new Insets(55, 35,0, 0);  
    		this.add(text2Button, c);
     
    		field1.setPreferredSize(new Dimension(200,25));
    		field1.setBackground(Color.LIGHT_GRAY);
    		c.insets = new Insets(20,120,0,0);  
    		this.add(field1, c);
     
    		field2.setPreferredSize(new Dimension(200,25));
    		field2.setBackground(Color.LIGHT_GRAY);
    		c.insets = new Insets(55,120,0,0); 
    		this.add(field2, c);
     
    		JLabel label1 = new JLabel(" Similarity ");
    		label1.setFont(new Font("Monospaced",Font.BOLD,25));
    		c.insets = new Insets(125, 200,0, 0);  
    		this.add(label1, c);
     
    		JLabel label2 = new JLabel(" Time ");
    		label2.setFont(new Font("Monospaced",Font.BOLD,25));
    		c.insets = new Insets(125, 400,0, 0);  
    		this.add(label2, c);
     
    		c.anchor = GridBagConstraints.LINE_START; 
     
    		JButton algo1Button = new JButton(" Algorithm1 ");
    		algo1Button.setPreferredSize(new Dimension(150,40));
    		c.insets = new Insets(25, -100,0, 0);  
    		this.add(algo1Button, c);
     
    		c.anchor = GridBagConstraints.FIRST_LINE_START; 
     
    		similarity1.setFont(new Font("Monospaced",Font.PLAIN,15));
    		c.insets = new Insets(180, 250,0, 0); 
    		this.add(similarity1, c);
     
    		time1.setFont(new Font("Monospaced",Font.PLAIN,15));
    		c.insets = new Insets(180, 425,0, 0);  
    		this.add(time1, c);
    		//Buttons, fields, labels END
     
    		//Menubar and menus START
    		JMenuBar menuBar = new JMenuBar();
    		this.setJMenuBar(menuBar);
     
    		JMenu fileMenu = new JMenu("   FILE   ");
    		menuBar.add(fileMenu);
     
    		JMenuItem newItem = new JMenuItem("New");
    		fileMenu.add(newItem);
     
    		fileMenu.addSeparator();
    		fileMenu.addSeparator();
     
    		JMenuItem closeItem = new JMenuItem("Close");
    		fileMenu.add(closeItem);
    		//Menubar and menus END
     
    		//Menulisteners
    		MenuListener MenuLi = new MenuListener(this);
     
    		newItem.addActionListener(MenuLi);
    		closeItem.addActionListener(MenuLi);
     
    		//ButtonListeners
    		ButtonListener ButLi = new ButtonListener(this);
     
    		text1Button.addActionListener(ButLi);
    		text2Button.addActionListener(ButLi);
    		algo1Button.addActionListener(ButLi);
    	}
     
    	public void initialize(){
    		field1.setText("");
    		field2.setText("");
    		similarity1.setText("0");
    		time1.setText("0");
    		butt.text1 = " ";
    		butt.text2 = " ";
     
    	}
     
    	//MenuListener internal class
    	class MenuListener implements ActionListener {
    		private JFrame frame;
     
    		MenuListener(JFrame fr) {
    			frame = fr;
    		}
     
    		public MenuListener(MainGUI Frame) {
    		}
     
    		public void actionPerformed(ActionEvent evt) {
     
    			if (evt.getSource() instanceof JMenuItem) {
    				String command = evt.getActionCommand();
     
    				if (command.equals("Close")) {
    					System.exit(0);
     
    				}else if (command.equals("New")) {
    					initialize();
     
    				} else{
    					System.out.println("ERROR: In the menudepartment!");
     
    				}
     
    			}
     
    		}
     
    	}
     
    	//ButtonListener internal class
    	class ButtonListener implements ActionListener {
    		private JFrame frame;
    		private LevensteinDistance levenshtein;
     
    		File selectedFile1 = null;
    		File selectedFile2 = null;
    		Scanner test1 = null;
    		Scanner test2 = null;
    		String text1 = "";
    		String text2 = "";
    		String tex1 = "";
    		String tex2 = "";
     
    		ButtonListener(JFrame fr) {
    			frame = fr;
    		}
     
    		public ButtonListener(MainGUI Frame) {
    		}
     
    		public void actionPerformed(ActionEvent arg0) {
     
    			if (arg0.getSource() instanceof JButton) {
    				String command = arg0.getActionCommand();
     
    				if (command.equals("Text 1: ")) {
    					//
    					String[] text = new String[] { "txt" };
    					//
    					JFileChooser FC = new JFileChooser();
    					//
    					FC.addChoosableFileFilter(new SimpleFileFilter(text,
    					"Only textfiles (*.txt)"));
    					//					
     
    					int returnVal = FC.showOpenDialog(frame);
    					if(returnVal == JFileChooser.APPROVE_OPTION){
    						selectedFile1 = FC.getSelectedFile();
    						field1.setText(selectedFile1.getName());
    					}
    					text1 = ""+"";
    					try{
    						test1 = new Scanner(selectedFile1);
    					} catch(FileNotFoundException e){
    						System.out.println("Text 1 is not found!");
    					}
     
    					while(test1.hasNextLine()){
    						text1 += test1.nextLine();
    						text1 = text1.toLowerCase();
     
    					}
     
    				}else if (command.equals("Text 2: ")) {
    					//
    					String[] text = new String[] { "txt" };
    					//
    					JFileChooser FC = new JFileChooser();
    					//
    					FC.addChoosableFileFilter(new SimpleFileFilter(text,
    					"Only textfiles (*.txt)"));
    					//
     
    					int returnVal = FC.showOpenDialog(frame);
    					if(returnVal == JFileChooser.APPROVE_OPTION){
    						selectedFile2 = FC.getSelectedFile();
    						field2.setText(selectedFile2.getName());
    					}
     
    					try{
    						test2 = new Scanner(selectedFile2);
    					} catch(FileNotFoundException e){
    						System.out.println("Text 2 is not found!");
    					}
     
    					text2 = ""+"";	
    					while(test2.hasNextLine()){					
    						text2 += test2.nextLine();
    						text2 = text2.toLowerCase();
     
    					}
     
    				} else if (command.equals(" Algorithm1 ")) {
    					text1 = text1.replaceAll("[.,!?#]", "");
    					text1 = text1.replaceAll("&","and");
    					text2 = text2.replaceAll("[.,!?#]", "");
    					text2 = text2.replaceAll("&","and");
    					tex1 = text1;
    					tex2 = text2;
    					double ratio = levenshtein.calculate(tex1, tex2);
    					similarity1.setText(Double.toString(ratio)+"%");
     
    				} else{
    					System.out.println("ERROR: In the button department!");	
    				}
     
    			}
     
    		}
     
    	}
     
    	public static void main(String[] args0) {
    		new MainGUI().showIt("SimilarityBtw2");
    	}
     
     
     
    }

    I know the problem occurs when I press "new" in the menu but as you can see it looks like this in the internal MenuListener class in the GUI:
    			}else if (command.equals("New")) {
    					initialize();
    which runs:
    public void initialize(){
    		field1.setText("");
    		field2.setText("");
    		similarity1.setText("0");
    		time1.setText("0");
    		butt.text1 = " ";
    		butt.text2 = " ";
     
    	}
    from the MainGUI class and the contructor is called too:
    private ButtonListener butt = new ButtonListener(null);

    The problem right now is that it still got the old txt files I uploaded saved. You can still run the algorithms on the old files even when pressing on "new" in the menu "File", which should reset so no algorithms should be able to run on the old stuff. It should flush out the data(files) and be ready to take in new text files to run the algorithm on.

    I hope there's someone out there who can fix this so I don't get this error and so the program resets as if I restarted the program. Yes, I'm getting desperate now since this is more important than the normal exercises which I can take a lot of time before asking for help if I'm not getting anywhere.
    Last edited by JavaN00b; May 29th, 2011 at 12:19 PM. Reason: Well it got solved...


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    The error message says there is a null variable at line 130 in MainGUI. Look at that line in your code and see what variable can be null. Use println to print out all the variable's values if needed.
    Then go back thru your code and see why that variable does NOT have a value.
    Last edited by Norm; May 28th, 2011 at 06:48 AM.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    The line at 130 is
    butt.text1 = " ";
    A string and set as " " which should be allowed since I do set it under the ButtonListener Class. That's why I don't understand why it won't accept it to set it as null. I wanted to reset the scanners first but since that seems to be a bigger job I figured that setting the text# string as " " would have the same effect.

    Oh I'm sure that it's in the initialize function where the problem is....I think

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    Where is the butt variable given a value?

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    ? o.O

    private ButtonListener butt;

    Why should butt be given a value when it's another class (the buttonListener) and how come it became a variable? O.o

    The ButtonListener is another class who uses the String text1 which I try to manipulate but fail heavily.

    The value to text1 is given under the ButtonListener class.

    Sorry, I'm not getting it.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    From your code, here is a sample of how you give a value to a variable:

    private JTextField field1= new JTextField(20);

    the variable: field1 gets set to a new textfield.

    The later in your code you call a method to set a value:
    field1.setText("");

    This is exactly what you should be doing with the butt variable. Assign it to a button object before calling a method with it.

  7. #7
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    So I assigned a value to the butt variable as told
    private ButtonListener butt = new ButtonListener(null);

    That took care of the nullpointerexception, YaY.

    The problem with resetting is still there though. I'm not getting any errors but the initialize() function still doesn't reset the values in the ButtonListener class. So I am still able to run the old uploaded data if I press on the algorithm button. Something that I don't want it to do. Since "new" should meanr reset to a new start.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    initialize() function still doesn't reset the values
    Try debugging the code by adding printlns to show how variables change and to show control flow. Add lots of them in all the places where the variables are set and where they are used.

  9. #9
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    I tried running it on text1 and made lots of println as you told me to.
    It seems that text1 only gets a value in the ButtonListener class and keeps its value only there while the text1 in the MainGUI which is butt.text1 is always empty aka "" and doesn't affect ButtonListener class or gets affected by ButtonListener class.

    I figured that out before too since nothing was happening when I pressed on "new" in my menu, then on the algorithm button and it acted like I hadn't reset. I guess the new information is that it's "" (empty) from the start before going into initialize().

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    command.equals("Text 1: ")
    This is a very WEAK point in your code. Obviously the String: "Text 1: " has been typed into the program at more than one place. If you change it in one place, and don't correctly change it in another, it won't work.
    A better way is to define a final String with the value and then use the reference to that in your code:
      final String TheLabel = "Text 1: ";  // Define the label to use
        ...
    		JButton text1Button = new JButton(TheLabel);
       ...
     
      command.equals(TheLabel)   // Test for that label

  11. #11
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    but that's the name of the JButton

    JButton text1Button = new JButton("Text 1: ");

    and not the String called text1. The String text1 will together with String text2 be used to find out how similar they are to each other via levensthein algorithm. The labels for the buttons shouldn't have anything to do with the text1 string since they are called "Text 1: " and "Text 2: ".

    The classes I uploaded can be put into the same project and run easily. That make it easier to help me. Well, I dunno really...

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    I was commenting on your coding style, not your current problem. The way you are doing it will cause you problems some time in the future.
    Typing the same String into several places in your program vs entering the String in one place and using that throughout your program.

  13. #13
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    I see, thank you for commenting on that. I shall take notion of that and fix it in my original code. I think the topic pops up in the Java book, I'm going through (still on chapter 6), in the later chapters under GUI chapter with buttons and so on.

    Though truth be told this is nowhere near my priority list. No offense but atm I just got only one thought in my head: Get this to work somehow so I can start testing and make my report since time is running out.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    So what is your problem now?

  15. #15
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    The same as before. Except the nullpointerexception.

    The function initialize() doesn't reset everything so I still have the old data saved.

    So when I upload something in "Text 1:" field and in "Text 2:" field, press on Algorithm1 button to run it. Then press on "new" under file to reset and on Algorithm1 button it gives the same result as before I pressed new instead of giving NaN or 0.

    That with the nullpointerexception has been my problem from the start. Finding out that butt.text1 doesn't affect text under the ButtonListener class and the other way around, well it's not saying anything to me. If I knew how to fix that I would have done it hours ago. ^^;;;

    Maybe I'm just too tired and should relax. I'll try to look at it again tomorrow since I can't see the solution at all.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    function initialize() doesn't reset everything
    Do you mean it resets some things and not others or it reset nothing?
    If only some, how do they differ from the ones it does reset?

  17. #17
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    I refer to the first post in this Thread for detailed code.

    field1.setText("");
    field2.setText("");
    similarity1.setText("0");
    time1.setText("0");

    Works fine.

    //butt.selectedFile1 = null;
    //butt.selectedFile2 = null;
    //butt.test1 = null;
    //butt.test2 = null;
    butt.text1 = " ";
    butt.text2 = " ";
    butt.tex1 = " ";
    butt.tex2 = " ";

    Doesn't work at all.

    They are all inside the same class.
    The ones that work MainGUI function inside the MainGUI class.
    The ones that don't work are inside an internal ButtonListener class inside the MainGUI class.

    So yes it resets some and not others.

    PS: I removed the error message from the first post.

  18. #18
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    butt.tex2 = " ";

    Doesn't work at all.
    How do you see that the value of the tex2 variable in the butt object is not set to a space?
    Where do you see that it has another value?

  19. #19
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    Well actually I don't think I need to reset tex1 and tex2 or for that matter any of these:

    //butt.selectedFile1 = null;
    //butt.selectedFile2 = null;
    //butt.test1 = null;
    //butt.test2 = null;
    butt.tex1 = " ";
    butt.tex2 = " ";

    The only ones I need to reset are these two:

    butt.text1 = " ";
    butt.text2 = " ";

    It gets a value when I press on the buttons to add txt files. After the file and scanner adds the data to the String text1 in the ButtonListener class under "(command.equals("Text 1: "))" and it keeps having that value.
    butt.text1 is set to space from the start in the MainGUI function. Before the initialize() function start and after the function end. Something you told me check out with the printlns yesterday.

    The problem is that I don't know how to made the value from text1 in the internal class ButtonListener to the MainGUI function and then back have the initialize to reset it to space. After that get the ButtonListener to use that text1 since it was reset in initialize() function.

  20. #20
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    I don't know how to made the value from text1 in the internal class ButtonListener to the MainGUI function and then back have the initialize to reset it to space. After that get the ButtonListener to use that text1 since it was reset in initialize() function.
    To get a value from a class(ButtonListener), add a get method that can be called by another class(MainGUI).

    When does text1 get a value? What does a user have to do to make that happen?
    Last edited by Norm; May 29th, 2011 at 09:56 AM.

  21. #21
    Junior Member
    Join Date
    May 2011
    Posts
    21
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    Nevermind, I showed the code to a friend who told me where I went wrong in 3 mins by saying:

    Your String text1 and text2 should be moved out of the internal class and put at the top of the MainGUI class since you are modifying them in the whole program in different places. The scope for those Strings is the whole MainGUI class with it's internal classes. That way they will start with "" and you can add data to them. Then when your function initialize() is called the function can easily access text1 and text2 and modify them to "" again. Thus you will get it reset as you wanted when the user press on "new" in the menu.

    This means that there's no need for adding ButtonListener butt = new ButtonListener(null) anymore. Since that isn't here there won't be any nullpointer exceptions either. No need for get methods either.

    It seems to work fine so I guess that's that.
    I was so close to just delete the "new" from menu instead since it was too much a hassle and I already don't got time for that. D:

    I'll come back again when I'm done with this project and back to the java book where I should soon start on arrays I think.^^

    Anyway thanks for trying to help me.

  22. #22
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: When I press on "new" in the menu in my GUI the program doesn't initialize (reset

    If you created two instanced of ButtonListener, then if you changed the values in one, the values in the other would NOT change.
    Your posted full code only shows ONE instance being created. You make some comments about creating a ButtonListener but never showed the full code where there were two instances created.

    We should have guessed what was happening. A classic case of two instances existing. Change values in one instance does NOT change values in the other. Except for static.

Similar Threads

  1. Creating a java program to "Beat" Snake web app?
    By AkOndray in forum AWT / Java Swing
    Replies: 2
    Last Post: December 5th, 2010, 12:36 AM
  2. Replies: 6
    Last Post: November 12th, 2010, 04:40 AM
  3. Replies: 2
    Last Post: October 29th, 2010, 03:14 AM
  4. Java says:"Hello World". I say:"It works!"
    By Davidovic in forum Member Introductions
    Replies: 4
    Last Post: June 29th, 2010, 07:13 AM
  5. "java.lang.NoSuchMethodError: main" and "fatal exception occured."
    By joachim89 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 10th, 2010, 08:35 AM