Results 1 to 2 of 2
  1. #1
    MrNice is offline Member
    Join Date
    Jan 2014
    Posts
    16
    Rep Power
    0

    Default MultiFile Project Action listener, passing

    Hey All,
    I am trully new, but here my problem. I wanted to design a gameluncher and i manage to make some gui in widnow builder eclipse. Now the problem is funcionality.
    Start.java -main lunching class that start -luncher
    Luncher/luncher.java -just like above luncher
    Options/options.java Jdialog1 open by luncher
    Mods/Mods.java jdialog2 open by luncher

    now i wanted to add seperate action listener dispatcher's and acces/resend from other working classes:
    Options/OptionsListener.java
    Options/***.java other files or classes dispatch from listener
    Mods/Modslistener.java
    Mods/***.java other files or classes dispatch from listener

    1topic i reply
    2topic i reply

    This way only metod getaction works, but if i wanted to call getsource it wants object that is not decleared in actionlistener-'s(2). I wated to pass reference of all my buttons, text field and all- Is it possible??
    And will it /can be send either over other classes (dispatch)?
    And how to do it, and how to use after?
    How to change data contained in each component?

    I need to make 3 diffrent consoles (no editable txtarea)- that why i wanted to pass some.

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import java.util.EventObject;
    
    import javax.swing.JButton;
    import javax.swing.JDialog;
    import javax.swing.JFrame;
    
    public  class OptionsListener implements ActionListener {
    	JDialog parent;
    	private ArrayList<Object> Actions =new ArrayList<Object>();
    	
    	    public OptionsListener(JDialog parent,ArrayList<Object> actions) {
            this.parent = parent;
            this.Actions=actions;
            //write();
        }
    
    	@Override
    	public void actionPerformed(ActionEvent e) {
    		Object btnExit;
    		//Object btnExit;
    		//if( e.getActionCommand().equals("Exit"))
    		if(e.getSource() == Actions.contains(btnExit))
    				{
    					parent.txtConDl.append("lol\n");
    			//parent.dispose();
    				}
    				
    		
    	}
    	public void write(){
    		parent.txtConDl.append("lol\n");
    	}
    }
    Is this also correct??
    Java Code:
    public  class OptionsListener implements ActionListener {
    	JDialog parent;
    	private ArrayList<Object> Actions =new ArrayList<Object>();
    	
    	    public OptionsListener(JDialog parent,ArrayList<Object> actions) {
            this.parent = parent;
            this.Actions=actions;
    or i need to make a loop and assing in other way, or not just hash map??
    Plz Hlp. Thanks

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: MultiFile Project Action listener, passing

    The best advice I can give you is to ditch the GUI builder. If you really want to learn how to code Swing, you have to write the code yourself instead of relying on an IDE to do it for you.

    You either have to give the ActionListener access to the components to compare them what you get from getSource(), or you might consider using a different ActionListener on each component.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Need more action listener help
    By ndsmith20 in forum New To Java
    Replies: 9
    Last Post: 01-19-2013, 02:12 AM
  2. Need help with action listener please!!!
    By ndsmith20 in forum New To Java
    Replies: 3
    Last Post: 01-17-2013, 03:44 AM
  3. Can anyone help me with an action listener?
    By mdCollins1 in forum New To Java
    Replies: 5
    Last Post: 03-21-2012, 05:07 AM
  4. Replies: 2
    Last Post: 12-11-2011, 11:44 PM
  5. Action Listener? how to use this?
    By jeffrey in forum New To Java
    Replies: 2
    Last Post: 10-12-2009, 09:51 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •