Results 1 to 5 of 5
  1. #1
    jumpman8947 is offline Member
    Join Date
    Feb 2013
    Posts
    38
    Rep Power
    0

    Default Calling Java Classes

    I'm currently working on a program where i need to call another java class from a button listener in another class. For example i have a button in example1 and when i press that button i want to execute the whole example2 class(which is a slideshow application). Here is some of my code That has the button

    Java Code:
    JButton button2 = new JButton("button2");
    button2.addActionListener(new button2Listener());
    
    ....
    
    private class button2Listener implements ActionListener
    	{
    		public void actionPerformed(ActionEvent e)
    		{
    			// I'm confused on what to put here
    			
    
    
    		}
              }
    And here is some code from the other java class that i need to execute the whole file
    Java Code:
    public class Internal extends JFrame
    {
    
    	public Internal()
    	{
    
    		//Code for the slideshow goes here
    	}
    }
    	public static void main(String[] args)
    	{
    		Internal in = new Internal();
    		in.show();
    	}
    
    }
    Thanks.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Calling Java Classes

    Last edited by Norm; 12-29-2013 at 12:06 AM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: Calling Java Classes

    You don't whole execute classes. You create instances of them and execute their methods.

    You shouldn't create Swing components in the main thread. And show() has been deprecated since Java 1.5.

    Seems like you are in way over your head. IMO, you need to back up and make sure you understand what classes and methods are. Then read this: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
    Get in the habit of using standard Java naming conventions!

  4. #4
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: Calling Java Classes

    Simply creating the instance
    Java Code:
    Internal in = new Internal();
    will execute the constructor in the Internal class.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,025
    Rep Power
    6

    Default Re: Calling Java Classes

    Best not to extend JFrame. Better to extend JPanel and add it to a JFrame instance. Then do all your "work" in the JPanel. And don't use "show()." It's deprecated. Use "setVisible(boolean)."

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Need help with calling classes!
    By lifedistroy in forum New To Java
    Replies: 1
    Last Post: 03-20-2012, 11:36 AM
  2. Calling classes from another class
    By jay_mascis in forum New To Java
    Replies: 1
    Last Post: 04-20-2011, 12:41 AM
  3. using and calling class within classes..
    By Bgreen7887 in forum New To Java
    Replies: 5
    Last Post: 10-27-2010, 04:49 PM
  4. Calling Methods between classes?
    By questionanswer in forum New To Java
    Replies: 2
    Last Post: 03-22-2010, 02:22 AM
  5. Calling jar classes from java executable
    By SteM in forum Advanced Java
    Replies: 1
    Last Post: 11-27-2007, 09:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •