That's a lot closer. I used a D not a d in the name. What you have will work, but it doesn't follow the naming conventions.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
That's a lot closer. I used a D not a d in the name. What you have will work, but it doesn't follow the naming conventions.
If you don't understand my answer, don't ignore it, ask a question.
i updated the name.
Last edited by newtolearningjava; April 26th, 2014 at 05:48 PM.
Are you saying you do not know how to call a method?
You code must be full of calls to methods.
For example these statements are calls to methods:dispose(); setVisible(false); transferControlToClass2();
That's a call to a class's constructor. But there is no class named: callDispose. That is the name of a method.callDispose dispose = new callDispose ();
If you don't understand my answer, don't ignore it, ask a question.
Am i on the right track here?
Last edited by newtolearningjava; April 26th, 2014 at 05:49 PM.
What happened when you compiled and executed the code?Am i on the right track here?
If you don't understand my answer, don't ignore it, ask a question.
Can you make a small, complete program that compiles, executes and shows the problem?
Add a call to setVisible(false);
If you don't understand my answer, don't ignore it, ask a question.
The code creates two JFrames:and closes the game frame. The JFrame referred to by the frame variable is not closed.new game(); JFrame frame = new JFrame();
If you don't understand my answer, don't ignore it, ask a question.
in my original code i have so this why i have done it like this in the program. how do i fix it?
I was told i have to use EXTEND JFrame
public class game extends JFrame {
Last edited by newtolearningjava; April 26th, 2014 at 05:49 PM.
There should only be one JFrame created. Get rid of one of them.
If you don't understand my answer, don't ignore it, ask a question.
this is my original code when i get rid of frame nothing appears when it is complied
D OF ??
Last edited by newtolearningjava; April 26th, 2014 at 05:50 PM.
This one:WHICH DO I GET RID OF ??
JFrame frame = new JFrame();
and use the one that Game extends.
If you don't understand my answer, don't ignore it, ask a question.
BUT when i complie my code there is no gui it just says
BUILD SUCCESSFUL (total time: 6 seconds)
How many lines of code did you remove? You were only supposed to remove ONE line:
JFrame frame = new JFrame();
That required that all usages of the variable: frame be changed to use the JFrame provided by the Game class. Basically just remove "frame."
If you don't understand my answer, don't ignore it, ask a question.
so remove this line of code ????
JFrame frame = new JFrame();
if i do this there is error for cannot find symbol
symbol: method add(JPanel,String)
location: class Object
----
Last edited by newtolearningjava; April 19th, 2014 at 07:08 PM.
Post the new version of the code.
I made the changes I've described and it works for me.
If you don't understand my answer, don't ignore it, ask a question.
did u make changes in the code which is on post no37?[COLOR="Silver"]
--- Update ---
Last edited by newtolearningjava; April 26th, 2014 at 05:50 PM.
That code isn't any good for testing. It needs to be complete.
Did you miss post#40 about removing "frame."?
If you don't understand my answer, don't ignore it, ask a question.
here is the mini program you told me to make it works
IN MY ORIGINAL PROGRAM IT DOES NOT WORK WHICH IS WHAT IM TRYING TO GET WORKING
Last edited by newtolearningjava; April 26th, 2014 at 05:50 PM.
Good, now look at how the code in post#45 works and copy that technique to the other code.it works
If there error messages, copy the full text and paste it here.
If you don't understand my answer, don't ignore it, ask a question.
yes i have it working BUT when i click the button to open the new gui it opens more than 1 so how i get rid of that?
The simple answer is to change the code so that it only opens one.when i click the button to open the new gui it opens more than 1
How many are openned?
Are all the new GUIs the same or are they all different?
How many places does the code create a GUI? Why is more than one executed?
If you don't understand my answer, don't ignore it, ask a question.
it opens
Last edited by newtolearningjava; April 26th, 2014 at 05:51 PM.
Interesting? I've never seen that. Usually its 2 like the code posted earlier.it opens 4 for the new gui, they are the same
Where are the statements that create those 4 instances?
Is there a loop that creates the 4 new instances of the same class?
--- Update ---
How many times is the actionPerformed() method called? The code in it creates a new Game2 every time it is called.
Add a println() method to the actionPerformed() method to see how many times it is called.
If you don't understand my answer, don't ignore it, ask a question.