Jump to content




Recent Status Updates

  • Photo
      18 Aug
    KodeKool

    When faced with a wall of errors and no hope to fix them, remember the following "Programs always do what you tell them to, and seldom what you want them to, but eventually you'll run out of things that can go wrong and it'll just work. and that's the secret to good programming."

    Show comments (2)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

Isit possible for me to call the JFrame from another class ?

jframe

  • Please log in to reply
3 replies to this topic

#1 xxxxjayxxx

xxxxjayxxx

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 123 posts

Posted 13 May 2011 - 08:18 AM

public class Jay {

public void Jay_Program() {

        Image image = Toolkit.getDefaultToolkit().getImage("\\logo.png");
        frame = new JFrame(");
        frame.setIconImage(image);
        frame.setSize(698, 500);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

How can I call this from from another class ? :confused:
  • 0

#2 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3,031 posts
  • Programming Language:Java, C#, PHP, JavaScript, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Transact-SQL, Assembly, Scheme

Posted 13 May 2011 - 01:49 PM

In your main function, you can create an instance of that class...

Jay j = new Jay();
j.Jay_Program();

The only thing you are missing in your Jay class is:
JFrame frame;

public class Jay { private JFrame frame; public void Jay_Program() {          Image image = Toolkit.getDefaultToolkit().getImage("\\logo.png");         frame = new JFrame(");         frame.setIconImage(image);         frame.setSize(698, 500);         frame.setLocationRelativeTo(null);         frame.setVisible(true);         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }

  • 0

#3 xxxxjayxxx

xxxxjayxxx

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 123 posts

Posted 13 May 2011 - 08:30 PM

which mean that if I use
Jay j = new Jay();
j.Jay_Program();
I can edit the JFrame from the new class ?
  • 0

#4 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3,031 posts
  • Programming Language:Java, C#, PHP, JavaScript, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Transact-SQL, Assembly, Scheme

Posted 16 May 2011 - 03:37 AM

What do you mean by "edit the JFrame"?
  • 0