#How do I do this action listener?

1 messages · Page 1 of 1 (latest)

copper mantle
#

I'm trying to add an ActionListener that will listen to all of my buttons. The problem is, I have no idea how. Would appreciate some help please! Will post the code in the thread 🙂

shrewd turretBOT
#

This post has been reserved for your question.

Hey @copper mantle! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

copper mantle
#
     // Button 1
     button.setText("User " + name + "'s journal! 🌼");
     button.setFocusable(false);
     button.setForeground(new Color(0, 0, 0));
     button.setBackground(new Color(255, 252, 253));
     button.setHorizontalTextPosition(JButton.CENTER);
     button.setVerticalTextPosition(JButton.BOTTOM);
     button.setIconTextGap(-15);
     button.setBorder(BorderFactory.createEtchedBorder());
     button.setEnabled(true);
     button.setLayout(new BorderLayout(100,100));
     button.setPreferredSize(new Dimension(10,60)); //width, height
      public void actionPerformed(ActionEvent e) {
      if(e.getSource() == button);
   }
}
orchid sundial
#

Hi @copper mantle, I’m Alexander Lill (a real person), a researcher at the University of Zurich. I’m trying to help people receive answers faster on Discord. If you are not ok with me trying to help you, click the 🚪 symbol, and I will delete this message and apologize for the inconvenience.

#

Based on your question, I suggest the following links. Please click the number-emoji for each link that was helpful for you, and on the ❌ if none of the links was helpful for you.

1️⃣ Code - ChangeListener - ChangeListener - ChangeListener
<#help-americano message>

2️⃣ Help With Your Code!
<#help-marocchino message>

3️⃣ Actionlistener Implementation
<#help-espresso message>

Let me know if you have any questions! More info: #announcements message

pseudo dawn
#
public class MyListener implements ActionListener {
    ...
}
#

Then

JButton btn1 = ...
JButton btn2 = ...
MyListener x = new MyListener();
btn1.addActionListener(x);
btn2.addActionListener(x);
#

You can also do this in the same class as a lambda but we won't go there

copper mantle
shrewd turretBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

orchid sundial
#

Thank you for your feedback imp_o_rt, appreciate it 🙂

I’d like to invite you and @copper mantle to fill in a short follow-up survey on your experience with the suggested links and your feedback (max. 10 mins).

We would highly appreciate your feedback to help our research project. For your efforts, you can decide to be entered in a raffle for an Amazon gift card of USD 100 value (voluntary).

To participate in the survey, please answer the questions in the following link. Your responses will be treated confidentially.
https://uzhwwf.qualtrics.com/jfe/form/SV_1zWdrjjRfwFGXwa?ST=DI&CO=JC&CI=7399003

shrewd turretBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

orchid sundial
#

Dear @copper mantle, just in case you forgot and are interested, I would be thankful if you could fill out my survey. If not, I apologize for the @ mention. This will be my last message 🙂