How to run a listener which is in another class??

I want to call any listener from class a to b.
For example in ClassA there exsist a button a.
And in ClassB there exsist a button b.
When I use the button A, I want to change the Button B's name.
How can I do this?

Thanks for all! It is ok.
This is what I did in separate classes:
A.java
import javax.swing.JButton;
import javax.swing.JPanel;
public class A extends JPanel{
     public A(){
          a= new JButton("AAA");          
          add(a);          
     public JButton a;
B.java
import javax.swing.JButton;
import javax.swing.JPanel;
public class B extends JPanel{
     public B(){          
          b= new JButton("BBB");          
          add(b);          
     public JButton b;
C.java
import javax.swing.JButton;
import javax.swing.JPanel;
public class C extends JPanel{
     public C(){          
          c= new JButton("CCC");          
          add(c);          
     public JButton c;
JFrameABC.java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class JFrameABC extends JFrame implements Runnable{
     public void run(){
          final A a = new A();
        final B b = new B();
        final C c = new C();
        a.a.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent evt) {
                b.b.setText("newB");
        b.b.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent evt) {
                  c.c.setText("newC");
        c.c.addActionListener(new ActionListener(){
             public void actionPerformed(ActionEvent evt) {
                  a.a.setText("newA");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().add(a, BorderLayout.NORTH);
        getContentPane().add(b, BorderLayout.CENTER);
        getContentPane().add(c, BorderLayout.SOUTH);
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
RunJFrameABC.java
import java.awt.EventQueue;
public class RunJFrameABC {
    public static void main(String[] args) {
        EventQueue.invokeLater(new JFrameABC());
}---------------------------------------------------------

Similar Messages

  • How to run a project which gets parameters from a batch file

    Hello all,
    I use to run a program, which gets parameters only by interactive mode, using a batch file as you can see below:
    # myprogram < batchfile.txt
    Now, I'm updating its code by SunStudioExpress IDE and I'd like to run it from the batchfile. I have noticed that the project properties window has the option run -> arguments, however this program doesn't accept arguments this way and for changing it, I'd have a hard job.
    Does someone know how to run this project and to get its parameters from batchfile?
    Regards,
    Glauber

    Ah, it appears that when you run the project, "<" is passed as one of the arguments and is not treated as input redirection.
    Sorry, it looks like it is not possible to do the redirection; and it looks like a bug to me. Could you please file it through bugs.sun.com? It shouldn't take long as the problem is evident now.

  • How do i view an array which is in another class?

    I know how to view variables from another class but i dont know how to view arrays from another class. Im trying to get my class to view data from the other class's arrays. Can it be done in Java? If it can, then how?
    These are my arrays, i want these to be viewable by the other class:
        public int arraySmallWhiteStars[][] = new int [600][3];
        public int arrayLargeWhiteStars[][] = new int [3][3];
        public int arrayYellowStars[][] = new int [3][3];
        public int arrayMars[][] = new int [1][3];How can i do it?
    Ant...

    what, so i would do it like this:
    pnlDraw.drawShip(arrayOne[][]);i dont think that will work!
    are you sure?
    Ant...Are these instance variable or local variables? What I'm saying is. are these arrays declared in the drawShip method?
    and passing parameters to a method is NOT how you gets public variables from a class. Are you sure you know how to do that?
    If I have a class with a public instance variable called, say int[] myInt I can access values of that via.
    int fromOtherClass = myClassInstance.myInt[0];

  • How to Run a .sql file from simple java class

    How to execute a .sql file consisting of Complex Queries,procedures through simple java class.
    The queries may have different delimiters,queries independant of each other.
    I am able to do with Specific De-limiter.But I need in such a way that there should not be any
    Constraints. Since My .sql may Contain different De-limiters.
    If any one can Suggest Some Solution.
    It will be Great Help.
    regards
    Anil

    Check out ibatis script runner, it' a third party library but quite handy for running sql files...
    m

  • How to run jscript or vbscript inside a java class

    I would like to create a class that can excecute jscripts and/or Vbscripts. Does any one knows if there is a class or a way to host jscrips so the script can access only the methods I specify in my "hosting env"? This is similar as using MS scripting utility to run vbscripts inside a VBprogram.
    Thanks
    G/

    see the rhino project at
    http://www.mozilla.org/rhino/

  • How to display values in textfields obtained from another class

    Hi,
    Why, oh why, doesn't this work:
    When I select a row in my tableClass (consist of a JTable) I want to display these values (strings) in my TextFieldGUI class (consist of just JTextFields). My code looks like this:
    TableClass:
    public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {
        textFieldGUI = new TextFieldGUI() ;//reference to my textfield class
        gui = new mainGUI() ; //reference to my GUI class
        int tabbedIndex = gui.getSelectedIndex() ;
        int col = tableModel.getColumnCount() ;
        Vector string = new Vector() ;
        String empty = "" ;
        for(int index = 0; index < col ; index++){
            if(table.getValueAt(row, index) == null)
                string.addElement(empty) ;
            else
                string.addElement(table.getValueAt(row, index).toString()) ;
        if(tabbedIndex == 0){       
            System.out.println(string) ; //works fine
            textFieldGUI.setTextFieldValues(string) ;
    }TextField class:
    public void setTextFieldValues(Vector s){
        Vector string = new Vector() ;
        string = s ;
        System.out.println("TextFieldVector: " + string) ; //works fine as well
        String name = "" ;
        String dob = "" ;
        String web = "" ;
        name = string.elementAt(0).toString() ;       
        dob = string.elementAt(1).toString() ;       
        web = string.elementAt(2).toString() ;
        System.out.println("NAME: " + name +
                           ", BIRTH: " + dob +
                           ", WEB: " + web) ; //values are correctly printed
        txtName.setText(name) ; //writes nothing (empty)
        txtDob.setText(dob) ; //writes nothing (empty)
        txtWeb.setText(web) ; //writes nothing (empty)
    }Anyone got a hint on how I should svolve this one?
    thanks
    gmtongar

    Hi
    my problem is, for each job_id there is many users. Oh that's something completlty different...
    I Strongly Recommand to_
    1.*create 2 tables Jobs & users*
    2.*create a relation between them* 1 to many to get for each job more than a user that's the way that Must be -- execuse me the bad design of the db pulled u into this trap -
    3.then u can deal with it normally no need to a sample code but just a form with Jobs as  (Master) and Users as (detail) with a relation and with a simple query u can display each job_id is for many users.
    no null values no commas r needed.
    Hope this helps...
    Regards,
    Amatu Allah.

  • How to get change a GUI component from another class?

    Hi there,
    I'm currently trying to change a GUI component in my 'Application' class from my 'Dice' class.
    So the Application class sets up some GUI including a JLabel that initially displays "Change".
    The 'Dice' class contains the ActionPerformed() method for when the 'Change' button (made from Application class) is clicked.
    And it returns an 'int' between 1 and 6.
    Now I want to set this number back int he JLabel from the Application class.
    APPLICATION CLASS
    import javax.swing.*;
    import java.awt.*;
    import java.util.Random;
    import java.awt.event.*;
    public class Application extends JFrame implements ActionListener{
         public JPanel rollDicePanel = new JPanel();
         public JLabel dice = new JLabel("Loser");
         public Container contentPane = getContentPane();
         public JButton button = new JButton("Change");
         public Dice diceClass = new Dice();
         public Application() {}
         public static void main(String[] args)
              Application application = new Application();
              application.addGUIComponents();
         public void addGUIComponents()
              contentPane.setLayout(new BorderLayout());
              rollDicePanel.add(dice);
            button.addActionListener(diceClass);
            contentPane.add(rollDicePanel, BorderLayout.SOUTH);
            contentPane.add(button,BorderLayout.NORTH);
              this.setSize(460, 655);
              this.setVisible(true);
              this.setResizable(false);
         public void changeDice()
              dice.setText("Hello");
         public void actionPerformed(ActionEvent e) {}
    }DICE
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class Dice implements ActionListener
         public Dice() {}
         public void actionPerformed(ActionEvent e)
              //super.actionPerformed(e);
              String event = e.getActionCommand();
              if(event.equals("Change"))
                   System.out.println("Will be about to change the 'dice' label");
                   Application application = new Application();
                   application.dice.setText("Hello");
    }

    It's all about references, baby. The Dice object needs a way to communicate with the Application object, and so Dice needs a reference to Application. There are many ways to pass this. In my example I pass the application object directly to Dice, but a better way would use interfaces and some indirection. Look up the Observer pattern for a better way to do this that scales much better than my brute-force approach.
    import javax.swing.*;
    import java.awt.*;
    public class Application extends JFrame // *** implements ActionListener
        // *** make all of these fields private ***
        private JPanel rollDicePanel = new JPanel();
        private JLabel dice = new JLabel("Loser");
        private Container contentPane = getContentPane();
        private JButton button = new JButton("Change");
        // *** pass a reference to your application ("this")
        // *** to your Dice object:
        private Dice diceClass = new Dice(this);
        public Application()
        public static void main(String[] args)
            Application application = new Application();
            application.addGUIComponents();
        public void addGUIComponents()
            contentPane.setLayout(new BorderLayout());
            rollDicePanel.add(dice);
            button.addActionListener(diceClass);
            contentPane.add(rollDicePanel, BorderLayout.SOUTH);
            contentPane.add(button, BorderLayout.NORTH);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setPreferredSize(new Dimension(460, 655));
            pack();
            setLocationRelativeTo(null);
            setVisible(true);
            setResizable(false);
        // *** I'm not sure what this is supposed to be doing, so I commented it out.
        //public void changeDice()
            //dice.setText("Hello");
        // *** ditto.  I strongly dislike making a GUI class implement ActionListeenr
        //public void actionPerformed(ActionEvent e)
        // *** here's the public method that the Dice object calls
        public void setTextDiceLabel(String text)
            dice.setText(text);
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    public class Dice implements ActionListener
        // *** have a variable that holds a reference to your application object
        private Application application;
        private boolean hello = true;
        public Dice(Application application)
            // *** get that reference via a constructor parameter (one way to do this)
            this.application = application;
        public void actionPerformed(ActionEvent e)
            String event = e.getActionCommand();
            if (event.equals("Change"))
                System.out.println("Will be about to change the 'dice' label");
                if (hello)
                    // *** call the application's public method
                    application.setTextDiceLabel("Hello");
                else
                    application.setTextDiceLabel("Goodbye");
                hello = !hello;
                //Application application = new Application();
                //application.dice.setText("Hello");
    }

  • How to run a SQL manually with the same SQL_ID

    I want to know how to run a SQL which comes from application side manually so that same SQL_ID is generated. I am aware that even if there is a small change in the sql(even a space) the sql_id gets changed. CURSOR_SHARING_PARAMETER is similar in my DB.
    Thanks
    Rudresh

    I think you really want is the execution plan (plan_hash_value), what about outlines ?
    HTH
    Antonio NAVARRO

  • Running the program which saves file in sap directory in background

    Hi guys,
    how to Run the program which saves file in sap directory in background? Thanks!

    Hi Mark,
    AL11 is a transaction that shows your application server something like an windows browser.
    If you want to store file in your application server then you can write a code which uploads the data in to a file on application server.And you can run your code in background also.
    Use function module :SAP_DATA_CONVERT_WRITE_FILE to write file on the application server.
    If you want to upload file manually then use TCODE :CG3Z.
    Hope this will you out.

  • How to create a link which will redirect to a different iView?

    Hello,
    I have a certain iView, let's call it "myiView" which sits inside a certain Role, let's call it "myRole".
    At the Homepage of the users I have KM navigation iView which shows a certain folder. I would like to create inside this folder a link to "myiView", this way when users will click on this link at the Homepage they will be redirected automaticly to "myiView". I remember reading once something regarding internal links perhaps this is solution but I'm not sure. Can anyone please show me how to create such link which redirects to another iView at the portal.
    10X
    Roy

    Hey Prakash,
    I am creating a KM link to this target, where at this link I can write javascript? As far as I know it is only possible at the iView level no? And where do I take the PCD URL from?
    Hey Ashutosh,
    I think that your method will open a whole new browser since it is an external link, I woulk like to keep the current navgation at the same page, simply navigate the user to a different place at the portal...
    Roy

  • When I connect an external drive I'd like to run a program which is on it. How could I do that?

    When I connect an external drive I'd like to run a program which is on it. How could I do that?
    I tried automator, but without success.
    Thanks

    Interesting question.  Others have provided the direct answer (no, massive security hole), and a little time with a search engine finds various existing discussions of autorun-related topics (eg: here and here and here), and a link to the Do Something When tool, and there is the DeviceListener example in the Xcode kit and to adding a folder action where the volumes are mounted.  See the topics for details.   Haven't tried this stuff, though.

  • How to run video which needs adobe  flash player

    How to run video in iPad which required adobe flash player.

    Adobe has not made a version of Flash for the iPad.
    Kappy explains why. https://discussions.apple.com/message/19446567#19446567
    5 Flash Player Alternatives http://www.techshout.com/features/2011/01/flash-player-for-ipad-apps/
    Top 4 browsers supports flash player on iPad and iPhone
    http://mashtips.com/flash-player-ios/
     Cheers, Tom

  • I'm currently using a pc running windows xp which is no longer supported. how can I easily move my iTunes library to a PC running Windows 8.1

    I'm currently using a pc running windows xp which is no longer supported. how can I easily move my iTunes library to a PC running Windows 8.1

    Yes. For how:
    How to move your iTunes library to a new computer - Apple Support

  • How to know which leaf node i click and how to add a listener to each node?

    hi! hello to all members, i have a problem i know how to create a listener, but i dont know how to add a listener to each leaf node. here is the scenario i want to do, i have a JTree where theres a topic that you can select on each leaf node, so when the user click the specific topic it will open another JFrame,which i dont know how to do it also, that its! the next problem will be how do i know which leaf node i select, so that i can open a right topic before the JFrame will open?please, i am very need this to solve quickly as possible. thanks again to all members.

    What you have to do is to add a mouse listener on your JTree. Try something like this:
    tree.addMouseListener(new java.awt.event.MouseAdapter() {
             public void mouseReleased(MouseEvent e) {
                tree_mouseReleased(e);
    private void tree_mouseReleased(MouseEvent e) {
          TreePath selPath = tree.getSelectionPath();
          // Check If the click is the Right Click
          if (e.isPopupTrigger() == true) {
          // This is your right Click
           else {
                     // This is your Left Click
    }Your other problem: Set the userObject on nodes and on left click compare it with your object, if it matches, display the appropriate file. Alternatively, if your nodes are unique, you can match the names to open the file.
    Hope this Helps
    Regard
    Raheel

  • HT4972 My ipad 1 has never been updated and can't run many apps which makes it of not much use, how do I update it ? A simple step by step idiot proof guide would be best ! Can anyone help please ?

    My ipad 1 has never been updated and can't run many apps which makes it of not much use, how do I update it ? A simple step by step idiot proof guide would be best ! Can anyone help please ?

    You can only update the iPad to iOS 5.1.1and you cannot go any higher. If you never updated that high, you can do so by using iTunes on your computer. You will have to connect the iPad to your computer with the cable and launch iTunes
    You can read more here. Make sure that you read the section about using iTunes. The article starts off with using the Settings on the iPad for WiFi updates. That only works with the iPad 2 and higher that is already running iOS 5.
    Update your iPhone, iPad, or iPod touch - Support - Apple

Maybe you are looking for