4

I have the classes Embed.java and watermarkdemo.java

There are some lines of code in the main method of Embed.java. I want to call the main method of Embed.java in the actionPerformed () method when the user clicks on the insert button. Please can someone give me the outline of how this can be done?

I hope I am clear in my problem and it is easy to understand what I am actually saying. Thankyou

Sumedha Vangury
  • 643
  • 2
  • 17
  • 43

3 Answers3

5
public void actionPerformed(ActionEvent e) {
    ...
    Embed.main(null);  // or a String[] containing args you want to pass
    ...
}

Simple as pie.

arshajii
  • 127,459
  • 24
  • 238
  • 287
0

This is called "calling static methods"

onemethod() {
  AnotherClass.anotherMethod();
Val
  • 1
  • 8
  • 40
  • 64
0
Embed.main();

If you make your main method implement varargs then you would need to pass anything in. If it implements a during array you'll have to pass in an empty array.

Personally though I would think about refactoring the code you need into a separate method. In main you're likely to have all your setup which you may not want to run again

RNJ
  • 15,272
  • 18
  • 86
  • 131