Results 1 to 2 of 2
Thread: Call a class from another class
- 05-23-2012, 02:45 PM #1
Member
- Join Date
- May 2012
- Posts
- 15
- Rep Power
- 0
Call a class from another class
Hi guys!
So, I've this code in one file called one.java
And what I need is to call this program from a button created in a second file called two.java how can I call it ?Java Code:import javax.swing.JOptionPane; public class one { public static void main(String[]args) { int Valor,i; String Salida=""; for(i=1;i<=20;i++) { Valor= 1 + (int) (Math.random() * 6); Salida+= Valor + " "; if(i%5==0) { Salida+="\n"; } } JOptionPane.showMessageDialog(null,Salida,"20 Nos. Aleatorios del 1 al 6",JOptionPane.INFORMATION_MESSAGE); System.exit(0); } }
Thanks in advance !!! :)Java Code:public void actionPerformed(ActionEvent e) { if (e.getSource ()==boton1) { // I need to create a code here to call the code in one.java } }
- 05-23-2012, 03:26 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: Call a class from another class
The way you have arranged your code, the only thing to call is the main( ... ) method; you can do this:
But I think you need to give it a second thought ...Java Code:public void actionPerformed(ActionEvent e) { if (e.getSource () == boton1) one.main(null); }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Eclipse Compile Error: Call validateValue(Class<T>, String, Object, Class<?>...)
By Tomshi in forum EclipseReplies: 0Last Post: 03-27-2011, 05:49 AM -
how do i call a class from main class
By revanger in forum New To JavaReplies: 7Last Post: 07-20-2010, 05:32 PM -
how call from inner class(anonymous or not), a method of parent class?
By lse123 in forum AWT / SwingReplies: 2Last Post: 05-01-2010, 08:59 AM -
How can I call abstract class methods from another class
By srinivas2828 in forum New To JavaReplies: 13Last Post: 03-12-2010, 02:33 PM -
How can I call method from class in other class??
By Hisham in forum New To JavaReplies: 6Last Post: 02-14-2010, 03:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks