Jump to content

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

- - - - -

  • Please log in to reply
3 replies to this topic

#1
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
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:

#2
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme
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); } }


#3
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
which mean that if I use
Jay j = new Jay();

j.Jay_Program();
I can edit the JFrame from the new class ?

#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
  • Programming Language:Java, C#, PHP
  • Learning:C, C++, C#, PHP, Transact-SQL, Assembly, Scheme
What do you mean by "edit the JFrame"?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users