Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute Main class into a JButton  RSS feed

 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i'm new using swing & i would like to know how can i execute the main class into a JButton.

Example: Main Class



this main class works fine & read a file from Argument, right click File, Properties, Run, Arguments(Neatbeans).


But into a JButton with action Performed.

Interface Class



it asks for an argument into the code..




I need to know how to set it up the private void CompareActionPerformed(java.awt.event.ActionEvent evt) as the ComparativeV3 main class, not giving it any argument, because the files are load from the arguments section & it reads diferent files with diferent arguments.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main method is for starting an app; you should not use it for anything else. Since the main method would trigger creating the GUI, it would not be appropriate to be called from a event handler (which is part of an already fully formed GUI, after all) anyway. You should break the main method into two pieces: 1) the parts that start the app, and b) the parts that initializes it in a way that you may want to repeat later on.
 
nu nin
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:The main method is for starting an app; you should not use it for anything else. Since the main method would trigger creating the GUI, it would not be appropriate to be called from a event handler (which is part of an already fully formed GUI, after all) anyway. You should break the main method into two pieces: 1) the parts that start the app, and b) the parts that initializes it in a way that you may want to repeat later on.


well i did it in other way but i didn't know which one was the correct.

Main Class.




And in the JFrame.



it works great but i can use only 1 file the same that it's in the args.



i don't know how to set it up without an args doing the same function like the fromer example without setting the path in code.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not clear to me what you're trying to achieve. If hardcoding the file name is a problem, then don't do it. If it needs changing at runtime, then there would need to be some way to specify a different file - maybe by using a JFileChooser.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!