logo
Tags down

shadow

How to call a method from my panel class through the button-actionPerformed in the dialog-class, that get´s it´s instanc


By : Vince
Date : October 16 2020, 06:10 AM
I hope this helps . Since your actionPerformed method is in the dialog class, I'm assuming that you are using the dialog class as your listener.
If you make a controller class OR set the panel class to be your listener, you can place the ActionPerformed event in the controller/panel class, which will then have access to the methods/fields that it needs to be able to reach
code :


Share : facebook icon twitter icon

Can I call ActionPerformed method from an Event Handler class for JButton?


By : Черненко Евгений
Date : March 29 2020, 07:55 AM
To fix the issue you can do The easiest and cleanest way is to add a dedicated, specific action listener to each button. That way, when the actionPerformed() method is called, you're sure that the associated button has been clicked, and don't need to test which button has been clicked:
code :
selectButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        // handle click on select button
    }
});

scrollButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        // handle click on scroll button
    }
});
    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == selectButton) {
            // handle click on select button
        }
        else if (e.getSource() == scrollButton) {
            // handle click on scroll button
        }
    }

Asp.Net MVC how to call a method from a instanc of a class by buttonClick event


By : DD7687
Date : March 29 2020, 07:55 AM
should help you out Let's call your model Server, and from the looks of it the view has an array of Server (or a List, IEnumerable etc...). The code below will add an anchor, which will make a GET to a route and pass the Id of the Server, assuming that you got an Id. If not, you can pass something else that is unique for the specific Server. This is very handy because you don't need to send the entire model, you simply pass the Id and let the Controller handle that part instead. The Controller can fetch the correct Server instance based on the Id, and then wake it up.
View:
code :
@model Server[]

<! -- Other stuff -->
<table>
@for (int i = 0; i < Model.Length; i++)
{
    <tr>
        <td>@Model[i].DnsName</td>
        <td>@Model[i].IpAddress</td>
        <td>@Model[i].MacAddress</td>
        <td>
            @Html.ActionLink(string.Format("Wake up {0}", Model[i].DnsName), "WakeUp", "Home", new {id = @Model[i].Id})
        </td>
    </tr>
}
</table>
public class HomeController : Controller
{
    [HttpGet]
    public ActionResult WakeUp(int id)
    {
        // id will be the id of the server.
        // Do your logic here.

       return View(); // Or whatever you want to return.
    }
}
public class HomeController : Controller
{    
    [HttpGet]
    public ActionResult WakeUp(int id)
    {
       // Possibly some validation here?

       // Send the id to the manager.
       var manager = new WakeUpManager();
       manager.WakeUp(id);

       return View(); // Or whatever you want to return.
    }
}

public class WakeUpManager
{
    public void WakeUp(int serverId)
    {
        // Wake the server up... or snooze... or whatever. :)
    }
}

How do I call actionPerformed method from another class in java


By : user6221244
Date : March 29 2020, 07:55 AM
Does that help After reading Your other question it is more clear what you want to do.
Servlet and your main program live in different JVM and can not talk directly.

Can I add an ActionListener to a button in a jFrame and have the actionPerformed method in a different Class?


By : user2285194
Date : March 29 2020, 07:55 AM
Hope that helps I have a jFrame where a user enters their data and a controller class where I would like to enter that data into a new object. At the moment I have added a listener to the button in the jFrame but cannot get it to recognise the actionPerformed method in the controller class. , You could do:
code :
public class CreateAccountGUI extends javax.swing.JFrame {

    public CreateAccountGUI() {
        /**/
        JButton btnCreateAccount = new JButton("Create");
        AccountStrategyController controller = new AccountStrategyController();
        controller.setView(this);
        btnCreateAccount.addActionListener(controller);
    }
}

class AccountStrategyController implements ActionListener{

    private CreateAccountGUI view = null;

    public void setView(CreateAccountGUI view){
        this.view = view;
        view.setVisible(true);//Show the account creation form
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        //respond to button click 
    }
}
public class CreateAccountGUI extends javax.swing.JFrame {

    public CreateAccountGUI() {
        /**/
        JButton btnCreateAccount = new JButton("Create");
        AccountStrategyController controller = new AccountStrategyController();
        controller.setView(this);
        btnCreateAccount.addActionListener(controller.createAccountListener());
    }
}

class AccountStrategyController{

    private CreateAccountGUI view = null;

    public void setView(CreateAccountGUI view){
        this.view = view;
        view.setVisible(true);//Show the account creation form
    }

    public  ActionListener createAccountListener(){     
        return new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //respond to button click 
            }
        };
    }   
}
public  ActionListener createAccountListener(){     
    return e -> {
        //respond to button click 
    };
}   

Call actionPerformed Method using normal method of class


By : Rhett
Date : March 29 2020, 07:55 AM
will help you If you want, some actionPerformed() method of a JButton to be executed on pressing ENTER inside a JTextField, then I guess you can use the doClick(), method from AbstractButton class to achieve this. Though this approach, might can override the original behaviour of the JTextField on press of the ENTER key :(
Please have a look at this code pasted below, to see if this is what, stands fit for your needs :-) !!!
Related Posts Related Posts :
  • How to flip two words in a sentence in java
  • Maven - How to remove module-info.class warning for shaded .jar?
  • Project Reactor, using a Flux sink outside of the creation lambda
  • Count the number of Arrays & access a specific array in the JSON Response using REST ASSURED with JAVA & Seleniu
  • Rotating zombies to face player
  • How to distribute the same apk for regular and instant app
  • How do I find one String inside of another
  • How to instantiate interface in Kotlin?
  • Java Intern pool implementation creates too many temporary objects
  • I need some advide about user type with hashmap
  • Is there a way to split for loop in java to do different things for values?
  • Thread safety on block of code which has external reference
  • I am unable to install java8 on my ubuntu gcp machine
  • Function returning blank string
  • Class Random Java: The method "roll()" is undefined for type Random. Why?
  • How to return value from the function without exiting from the function?
  • Getting wrong hours when Convert date without time to Milliseconds using SimpleDateFormat
  • Why we need Action Interface when all actions can be done with ActionsClass
  • How can I make this program run when it says could not find or load main class?
  • How to avoid duplicate node?
  • Everytime i run this recrusion algorithm, my variable is set to 0 how to solve it
  • Determine Whether JLabel Text is Being Cut Off?
  • Why is TomEE not able to create JMS connection factory resource?
  • Unable to sendKeys in an EditText field
  • Merge sort implementation in java is copying a value into another index instead of swapping
  • Should method parameters be made as final in Java8
  • AEM OSGI 3rd party dependency, bundle not Active
  • Using mybatis to map multiple tables to a single collection
  • Is it possible to pass text from edittext to webview?
  • Problems with repeat use of while loop
  • Change border color on click Java
  • Cannot find any information on property [bankOffer] in a bean of type [game.Game]
  • How to check if a button is clicked in another Jframe
  • IDEA Gives warning 'some variable always false'?
  • Using methods of classes that its didn't extends the same parent class
  • How do I set up a build-script with Maven?
  • How do I add arrays to an Arraylist of Arrays (Arraylist<Integer[]>)
  • Trying to remove a tuple using a prepared statement
  • Best/recommended way to convert Java 8 OffsetDateTime to localized string on android
  • Print a String n times using recursion
  • I have a Jtable with a button in one of the columns and I want to access the value in the 1st column when I press the bu
  • Generating source code with a gradle task based on existing classes with annotations on them
  • a subclass for specifying a generic shows bound mismatch
  • Static Variable with null reference
  • painting string in the middle of a given size cell java
  • Displaying column in tableView
  • What does <+ mean in Java?
  • What cplex function I have to use to write this variable?
  • Java ConcurrentHashSet - iterating over it in a multi-threaded environment
  • Can't seem to get my Java to work in VS Code
  • I don't understand the function of "count++"
  • What are the possibilities to design an API that needs overloads depending on a generic type?
  • Can't connect to Apache Ignite Cluster on AWS EC2 - Ignite server rejects clients
  • Trying to understand garbage collection in java
  • Is there a way to associate an ArrayList with another ArrayList with a one to many relationship?
  • Generate List with Combination of Subset of List, Java
  • Getting Illegal State Exception in Regex
  • Shuffling an Array (Java)
  • Tomcat v 9.0 - Public Key Retrieval is not allowed
  • Clarification on why this code is resulting in false and not true
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk