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



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ankush Pruthi
how to open one Jframe from main method call
0 Answer(s)      a year and a month 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 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 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 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
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
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
how to reset JFrame
how to reset JFrame  how to reset JFrame
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
 

 

 

DMCA.com