Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT how to open one Jframe from main method call

Have Programming Question? Ask it here!
 
 
 


Ankush Pruthi
how to open one Jframe from main method call
0 Answer(s)      10 months ago
Posted in : Swing AWT


I have downloaded a snake game project in java. Initially the project contains three java files i.e "

Engine.java

Snake.java

GameBoard.java

And Engine.java have the main() method, when i run this Engine.java class game starts running.

And to improve the user iteractivity i have created two JFrames :"PlayGame.java", Rules.java

Now this project having five java classes in this project-

Engine.java(containing main() method) Snake.java GameBoard.java PlayGame.java(is a JFrame) Rules.java(is a JFrame)

PlayGame.java have three buttons

Play - i want when play button getclicked snake game start/run.
Rules - when clicked Rules.java Jframe should be opened
Exit - exits the application

Now what i want is at first "PlayGame.java" JFrame should appear and throw this game should start i.e when i click play button game should start But problem i am facing is "playGame.java" JFrame and "game screen" appearing at the same time .thats what i don't want in my project

Here is the code that i have included in main method

    public static void main(String[] args) {
    new PlayGame().setVisible(true);

    JFrame frame = new JFrame("SnakeGame");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setResizable(false);

    Canvas canvas = new Canvas();
    canvas.setBackground(Color.black);
    canvas.setPreferredSize(new Dimension(GameBoard.MAP_SIZE *GameBoard.TILE_SIZE,GameBoard.MAP_SIZE * GameBoard.TILE_SIZE));

    frame.add(canvas);
    frame.pack();![alt text][1]
    frame.setLocationRelativeTo(null);
    frame.setVisible(true); 

    new Engine(canvas).startGame();

         }

Advertisement
View Answers

Related Tutorials/Questions & Answers:
how to open one Jframe from main method call
how to open one Jframe from main method call  I have downloaded... the main() method, when i run this Engine.java class game starts running...(containing main() method) Snake.java GameBoard.java PlayGame.java
How I call the function union from the main - Java Interview Questions
How I call the function union from the main  Please, from public static void main(String[] args) I would like to call the function union and I...}, }; //calling the function union : paramtere to pass is mat //how i call
Advertisements
How to call the run method from another class?
How to call the run method from another class?  Sorry, if this is a stupid question. I would like to find out how to call the run method... want to call this from AdaugaComanda.java, so that changes can be seen
how to call static method
how to call static method  class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends class A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
how to call static method
how to call static method  class A { //some code } class B extends A { static method() } class C { } //how to access static method() from B to C
How to open textfields in the the same panel of the jframe by selcting from dropdown menu option ...
How to open textfields in the the same panel of the jframe by selcting from... of option from the dropdown menu .acc. to my requirement i have to show the textfields and submit button in the same panel of the jframe window . Below is my
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data from a Jtextfield in the first Jframe to another JLabel in the other JFrame.Can you please help me,how
navigating the value of JTextField from one JFrame to another - Swing AWT
navigating the value of JTextField from one JFrame to another  hello I m doing one project where I m retriving the data from databse in JTextField... JFrame .... Can anyone plz tell me how we can do this...can anybody give me
how to call jsp from flex
how to call jsp from flex  hi, i want to know that how can i call a FLEX from JSP. . A good Example will be appreciated
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
navigating the value of JTextField from one JFrame to another - Swing AWT
navigating the value of JTextField from one JFrame to another  Hello... is working also.. but only first record is comming... how can I fetch all the records from database using up and down keys of keyboard? And also I wanted
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my... an object for it.my java code is public class submit { JFrame frame; JTextArea text1; void form() { frame=new JFrame("details you have entered are"); JPanel
how to call jsp from flex
how to call jsp from flex  Plz help me out to get JSP from FLEX.... I need your help.... Thanks for future
how to handle action events in case of more than one JFrame
how to handle action events in case of more than one JFrame   I have downloaded a snake game project from the internet, initially this project... is set in the actionPerformed() method of individual buttons. Now problem i am
main method
main method  Why is the java main method static
main method
main method  What is the argument type of a program's main() method
main method
in paranthesis denote?   Hi Friend, public-It indicates that the main() method can be called by any object. static-It indicates that the main() method is a class method. void- It indicates that the main() method has no return value
main method
can not make multiple main with in the same class program fails to compile. Compiler gives error that the main method is already defined in the class...main method  hello, Can I make multiple main methods in the same
main() method
main() method  Can we define two main() methods having same parameter but with different return type in a program
how to call javascript function from flex
how to call javascript function from flex  how to call javascript function from flex
how to call from pc to telephone in java - MobileApplications
how to call from pc to telephone in java  Hi, presently I am working on "make a call from pc to telephone" in java. I am unable to procceed how to start. I am new this technoloy.Please give me some valuable suggestions how
How to make phone call from web application
How to make phone call from web application  I'm creating an XHTML... to make call to a specific number when user clicks a particular button. Please suggest on how to do this. I'm new to this. Thanks in advance
how can i define only one method from the interface. - Java Beginners
how can i define only one method from the interface.  If i am having an interface with 3 methods(declaration) . If i want to use only one method for defining without defining the other two methods. if it is possible then tell me
error got minus one from read call - JSP-Servlet
minus one from a read call oracle.jdbc.dbaccess.DBError.throwSqlException...error got minus one from read call  hiiii while connecting my servlet...) the code is as follows: // *DataBase Connectivity from the Servlet. import
Main method overloading
Main method overloading  Can we overload main()method
What is the arguement of main method?
What is the arguement of main method?  hi, What is the arguement of main method? thanks,   Hi, For main() method accepts only an array of String object as arguement. For moe details on http://www.roseindia.net/java
Can a main method be overloaded?
Can a main method be overloaded?   Hi, Can a main method... number of main() methods with different Signature and implementation in the class...-Questions/11577-Main-method-overloading.html
how to reset JFrame
how to reset JFrame  how to reset JFrame
How to call jasper from jsp or servlet - JSP-Servlet
How to call jasper from jsp or servlet  Hi Expert , I created jasper report using ireport.how to call that jasper with jsp file or servlet file ? Thanks in advance Eswaramoorthy.s
how to call the array variable in scriptlet from javascript function
how to call the array variable in scriptlet from javascript function  This is the scriptlet code:- <% String[] abc={"saab","volvo","bmw","Benz","Porsche","Jaguar"}; %> Actually i want the array variable one by one
how to call an exe file from java - Java Beginners
how to call an exe file from java  hi, how to call exe file with some parameters from java and save the output of the exe file in a specified path. Please let me know immediately..its urgent!!! Thanks in advance
Why is the main method declared static?
Why is the main method declared static?  Hi, Why is the main method declared static? thanks   Hi, When we declare main() method in any Java class always has the same signature, and we declare public static void main
how to move label in jframe in java?
how to move label in jframe in java?  please any one can give me code for moving a java label in Jframe
What is the return type of the main method?
to have a method named main in at least one class. The following is what must...What is the return type of the main method?  hi, What is the return type of the main method? thanks   Hi, In the java programming
how to call servlet from html page at anchor tag ?
how to call servlet from html page at anchor tag ?  I have a very different problem as i am using netbeans ide 6.9 ml to make a website in java and my website is running on it but after uploading it on server
JFrame
in main JFrames many windows gets open. But i want all JFrames to open within Main Jframe. How can i do it. Please help me to do it. Or what else can i have
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning. I am trying to develop a coding pass a string from one class and declare... to move it to the main method. i am trying to find a solution for this. Thank's
How to invoke method of a library from command line
How to invoke method of a library from command line  Suppose there are two methods in a libray and you have to invoke one of the method from that library directly from the command prompt. How will you do
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
When is java main method called?
When is java main method called?  When is java main method called? Please explain the main method in Java with the help of code.   In a java class, main(..) method is the first method called by java environment when
How to fetch entries/values from database to a jsp page one by one?
How to fetch entries/values from database to a jsp page one by one?  I have a table in Microsoft SQL server Management Studio with two columns title and data and each column has 10 enteries. I have a jsp page on which i want
What if the main() method is declared as private?
What if the main() method is declared as private?  Hi, What if the main() method is declared as private? Thanks   Hi, I have found some reference site for java programming coding for Main() method is declared
 

 

 

DMCA.com