Jump to content

How to restart a card (card layout)

- - - - -

  • Please log in to reply
14 replies to this topic

#1
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
Hello everyone :)
I have a problem to restarting a game. I would like to reset/restart the game/card.
I know the way to restart the entire mainframe:


	mainframe.this.dispose(); 

		new mainframe().setVisible(true); 


But now I would like to restart only one card of the mainframe.
The only way that I know is to reseting all the variables etc.
I hope there is a faster and better way.

Screenshot of the app that I'm working on:

Attached File  Screen Shot 2012-01-26 at 4.36.57 PM.png.jpg   82.67K   23 downloads

#2
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
Can you post a small, simple program that compiles and executes (a SSCCE) and shows the problem?

#3
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
Yes of course I'll post a SSCCE approximately tomorrow np.
Thx for now hf.

#4
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
Ok so this is a simple example of my problem.

[ATTACH]4526[/ATTACH]

When you click a button "prva" a new card in showed and if you click the button "Button" something on this card change.
I would like to: if someone click the button "Refresh" that this card restart itself..like no one never clicked the button "Button".

In this case the solution will be to set the text of the button and label to what it was before the change.
But in my case I have a lot of variables in labels and so one. So I'm searching for something like:

//Pseudocode
If button refresh was clicked {
Restard the entire card;
}

Attached Files

  • Attached File  src.zip   6.52K   4 downloads


#5
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
The code has undefined classes:
package org.jdesktop.layout does not exist
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);

And its not really a small program with almost 300 lines.

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
See if
removeAll();
initComponents();
does what you want (in the actionperformed of the refresh button)

#7
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
WindDC for the example that I did this solution works great:

removeAll();

initComponents();


But for my true problem where I have threads for example it doesn't work properly. If you have any other idea in this way in would be great :)

Norm the code is more than 300 lines because it's done in Netbeans and Netbeans generate a lot of (not significant to understand the problem) code .
To understand the problem what I'm trying to do is my example good enough.

For the missing package you have to put in Eclipse in build path/external archives this two files:

[ATTACH]4527[/ATTACH]

[ATTACH]4528[/ATTACH]

Attached Files



#8
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts

Quote

not significant to understand the problem)
Can you make a SMALL simple program (SSCCE) that compiles and executes and shows your problem. Without the IDE's classes.

#9
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
Norm I think that you just don't get what's the problem. So thank you anyway.

#10
Norm

Norm

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 327 posts
Without a SSCCE, its hard to see the problem. I'd rather not waste a lot of time working through all the code you posted to make an SSCCE. If you're not interested enough in solving your problem to take the time to make a SSCCE, that's up to you.

#11
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

Serialcek said:

WindDC for the example that I did this solution works great:
removeAll();
initComponents();

But for my true problem where I have threads for example it doesn't work properly. If you have any other idea in this way in would be great :)

Norm the code is more than 300 lines because it's done in Netbeans and Netbeans generate a lot of (not significant to understand the problem) code .
To understand the problem what I'm trying to do is my example good enough.

For the missing package you have to put in Eclipse in build path/external archives this two files:

[ATTACH]4527[/ATTACH]

[ATTACH]4528[/ATTACH]

Make sure that the removeAll and initcomponents is called on the right class.
If, for example, the card was in "Druga_stran" and not in "Prva_Stran" (where the refresh button is). Then I would need to do the removeall and initcomponents on the Prva_Stran instance.

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        druga_stran.removeAll();
        druga_stran.initComponents();
    }
You need a druga_stran instance for that:

public class Prva_Stran extends javax.swing.JPanel {
    private Druga_stran druga_stran;


    /** Creates new form Prva_Stran */
    public Prva_Stran(Druga_stran druga_stran) {
        this.druga_stran = druga_stran;
        initComponents();
    }

MainFrame's initcomponents:
 druga_stran1 = new layers.Druga_stran();
 prva_Stran1 = new layers.Prva_Stran(druga_stran1);

Druga_stran initcomponents must be public then:
public void initComponents() {

These are the required changes if the card is in fact not in the same class as the refresh button.

#12
Serialcek

Serialcek

    Learning Programmer

  • Members
  • PipPipPip
  • 72 posts
In my case I have on the card a jPanel and in this jPanel I have some kind of an animation (balloons are moving). (LOOK FOR THE SCREEN SHOOT IN MY FIRST POST)

When I click restart button which contains:

removeAll();

initComponents();


It actually reset everything in the card including what's in the jPanel (jPanel is for one second empty) but the next second the animation (balloons in the jPanel) continue to run from where they ends/stopped.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users