|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Member
Join Date: Sep 2006
Posts: 1
|
swing component repaint issue
I've made a simple application that animates the Tower of Hanoi solution.
Everything works great except for one majoy flaw: When the solution is running and the animation is taking place the GUI will dissapear if minimized or get erased as a window passes over it. However. once the animation is over everything repaints as it should (except for my graphics). How can I prevent the screen from dissappearing? should I be overriding the paint() method? should I be looking into threads? Also, any process/action that happens as the animation is running will not execute until the animation is complete. (i.e. I disable the start button and the text fields before the solve/animate method is called but the effect is not seen until after the animation is complete). No matter the order of commands everything seems to wait until the animation is complete. Not sure what I've done wrong, or what the next step is...Any help would be greatly appreciated. wf there is quite a bit of code, but most of it is comments...here is the main class: Code:
public class HanoiFrame extends javax.swing.JFrame {
private static final int POLE_AREA_HEIGHT = 356;
private static final int POLE_AREA_WIDTH = 205;
private static final int DISK_ARC_HEIGHT = 15;
private static final int DISK_ARC_WIDTH = 15;
private static final int DISK_HEIGHT = 23;
private static final int MAX_DISKS = 10;
private static final int MAX_ANIMATION_DELAY = 30000;
private static final int MAX_PHYSICAL_DELAY = 100000;
private static final int MIN_DISKS = 1;
private static final int MIN_ANIMATION_DELAY = 1;
private static final int MIN_PHYSICAL_DELAY = 1;
private static final int EMPTY_CELL_VALUE = -1;
private static final int CELL_HEIGHT = 25;
private static final int COLUMNS = 3;
private static final int ROW = 11;
private static final int MILLISECONDS_PER_SECOND = 1000;
private final static String newline = "\n";
private Disk[] disks;
Disk newDisk;
private int[][] diskCells;
private int startX = 2;
private int startY = 340;
private int setDiskAmount = 0;
private int setAnimationDelay = 0;
private int setPhysicalDelay = 0;
private int moveNumber = 0;
private double movesLeft = 0;
private int intMovesLeft = 0;
private boolean buttonPressed = false;
/** Creates new form HanoiFrame */
public HanoiFrame() {
initComponents();
this.setVisible(true);
/* initialize the "poles" to hold a certain number of "cells */
this.diskCells = new int[ROW][COLUMNS];
for (int row = ROW - 1;row >= 0; row--) {
for (int col = 0;col < COLUMNS ; col++) {
diskCells[row][col] = EMPTY_CELL_VALUE;
}
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
inputPanel = new javax.swing.JPanel();
startButton = new javax.swing.JButton();
labelDiskAmount = new javax.swing.JLabel();
diskAmount = new javax.swing.JTextField();
labelAdelay = new javax.swing.JLabel();
animationDelay = new javax.swing.JTextField();
labelMSsuffix = new javax.swing.JLabel();
labelPdelay = new javax.swing.JLabel();
physicalDelay = new javax.swing.JTextField();
labelSecondSuffix = new javax.swing.JLabel();
resetButton = new javax.swing.JButton();
outputPanel = new javax.swing.JPanel();
outScrollPane = new javax.swing.JScrollPane();
outTextArea = new javax.swing.JTextArea();
hanoiPanel = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(0, 0, 0));
setResizable(false);
inputPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Parameters"));
startButton.setText("Start");
startButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent evt) {
startButtonMouseReleased(evt);
}
});
labelDiskAmount.setText("Number of Disks:");
labelAdelay.setText("Animation Delay ");
labelMSsuffix.setText("ms");
labelPdelay.setText("Physical Delay");
labelSecondSuffix.setText("s");
resetButton.setText("Reset");
resetButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resetButtonActionPerformed(evt);
}
});
resetButton.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseReleased(java.awt.event.MouseEvent evt) {
resetButtonMouseReleased(evt);
}
});
org.jdesktop.layout.GroupLayout inputPanelLayout = new org.jdesktop.layout.GroupLayout(inputPanel);
inputPanel.setLayout(inputPanelLayout);
inputPanelLayout.setHorizontalGroup(
inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(inputPanelLayout.createSequentialGroup()
.addContainerGap()
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(inputPanelLayout.createSequentialGroup()
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, inputPanelLayout.createSequentialGroup()
.add(labelDiskAmount)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(diskAmount))
.add(org.jdesktop.layout.GroupLayout.LEADING, inputPanelLayout.createSequentialGroup()
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(labelAdelay)
.add(labelPdelay))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(physicalDelay)
.add(animationDelay, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(inputPanelLayout.createSequentialGroup()
.add(labelSecondSuffix, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(9, 9, 9))
.add(labelMSsuffix)))
.add(org.jdesktop.layout.GroupLayout.TRAILING, resetButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(startButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
.addContainerGap())
);
inputPanelLayout.setVerticalGroup(
inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, inputPanelLayout.createSequentialGroup()
.addContainerGap()
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(labelDiskAmount)
.add(diskAmount, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(32, 32, 32)
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(labelAdelay)
.add(animationDelay, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(labelMSsuffix))
.add(35, 35, 35)
.add(inputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(labelPdelay)
.add(physicalDelay, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(labelSecondSuffix))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 106, Short.MAX_VALUE)
.add(startButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 49, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(resetButton)
.addContainerGap())
);
outputPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder("Message Center")));
outTextArea.setColumns(20);
outTextArea.setRows(5);
outScrollPane.setViewportView(outTextArea);
org.jdesktop.layout.GroupLayout outputPanelLayout = new org.jdesktop.layout.GroupLayout(outputPanel);
outputPanel.setLayout(outputPanelLayout);
outputPanelLayout.setHorizontalGroup(
outputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(outputPanelLayout.createSequentialGroup()
.addContainerGap()
.add(outScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 815, Short.MAX_VALUE)
.addContainerGap())
);
outputPanelLayout.setVerticalGroup(
outputPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(outputPanelLayout.createSequentialGroup()
.addContainerGap()
.add(outScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
.addContainerGap())
);
hanoiPanel.setBackground(new java.awt.Color(0, 0, 0));
org.jdesktop.layout.GroupLayout hanoiPanelLayout = new org.jdesktop.layout.GroupLayout(hanoiPanel);
hanoiPanel.setLayout(hanoiPanelLayout);
hanoiPanelLayout.setHorizontalGroup(
hanoiPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 615, Short.MAX_VALUE)
);
hanoiPanelLayout.setVerticalGroup(
hanoiPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 352, Short.MAX_VALUE)
);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, outputPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(hanoiPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(inputPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(inputPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(hanoiPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(outputPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void resetButtonActionPerformed(java.awt.event.ActionEvent evt) {
/* reset all the variable to original state */
setDiskAmount = 0;
setAnimationDelay = 0;
setPhysicalDelay = 0;
moveNumber = 0;
movesLeft = 0;
intMovesLeft = 0;
buttonPressed = false;
this.startButton.setEnabled(true);
this.diskAmount.setEditable(true);
this.animationDelay.setEditable(true);
this.physicalDelay.setEditable(true);
/* reset all the cell vales to empty (this could be its own function) */
for (int row = ROW - 1;row >= 0; row--) {
for (int col = 0;col < COLUMNS ; col++) {
diskCells[row][col] = EMPTY_CELL_VALUE;
}
}
/* reset the content of the TextFields and Area */
this.diskAmount.setText("");
this.animationDelay.setText("");
this.physicalDelay.setText("");
this.outTextArea.setText("");
/* repaint the display panel */
this.hanoiPanel.repaint();
}
/* i have no idea why this is here...It was generated by Netbeans when I
*made the reset button. As you can see it made 2. The one above it the same
*except it contains code. Since it was automatically generated
*I cannot delete it.
*/
private void resetButtonMouseReleased(java.awt.event.MouseEvent evt) {
}
/* is executed when the start button is pressed.
*also executes a field check and intializes key variables. Finally,
*it executes the solution and generates the solve time
*/
private void startButtonMouseReleased(java.awt.event.MouseEvent evt) {
/* check if the program has already been run (without being reset) */
if (!buttonPressed){
/* check the fields to ensure the input is correct and useable */
if (checkFields()){
/* give button a pressed status if all info valid */
buttonPressed = true;
/* disable the button */
this.startButton.setEnabled(false);
/* disable the fields */
this.diskAmount.setEditable(false);
this.animationDelay.setEditable(false);
this.physicalDelay.setEditable(false);
/* setup the disks on the starting pole */
setup();
/* initialize the number of moves required. 2 to the power of n minus 1 */
movesLeft = Math.pow(2, setDiskAmount) - 1;
/* convert the number to an integer */
intMovesLeft = (int)movesLeft;
/* set the physical delay */
setPhysicalDelay = Integer.parseInt(this.physicalDelay.getText());
/* start the engine/animation */
solutionEngine(setDiskAmount,0, 2, 1);
/* calculate the solve time and display */
totalTime();
}
}
}
/**
*Check all the fields at once to ensure that they are valid
*/
private boolean checkFields(){
String numberOfDisks = null;
String animationDelay = null;
String physicalDelay = null;
numberOfDisks = this.diskAmount.getText();
animationDelay = this.animationDelay.getText();
physicalDelay = this.physicalDelay.getText();
/* initiate my array of error messages */
ArrayList errMsg = new ArrayList(0);
/* check if the number of disks was left blank */
if (numberOfDisks.equals("")){
errMsg.add("Please enter the Number of Disks (MAX " + MAX_DISKS + ")");
}else{
/* check if the input given is valid */
try {
/* parse the disk amount entered into an integer */
setDiskAmount = Integer.parseInt(numberOfDisks);
/* check the # of disks entered is greater than 0 and less than 10 */
if (setDiskAmount < MIN_DISKS){
errMsg.add("Number of Disks must be greater than " + MIN_DISKS);
} else if (setDiskAmount > MAX_DISKS){
errMsg.add("Number of Disks must be less than" + MAX_DISKS);
}
} catch (NumberFormatException ex) {
errMsg.add("Number of Disks must be a Number");
}
}
/* check if animation delay was left blank */
if (animationDelay.equals("")){
errMsg.add("Please enter disk Animation Delay");
} else {
/* check if the input given is valid */
try {
/* parse the animation delay entered into an integer */
setAnimationDelay = Integer.parseInt(animationDelay);
/* check range of animation delay */
if (setAnimationDelay < MIN_ANIMATION_DELAY){
errMsg.add("Animation Delay must be greater than 0");
} else if (setAnimationDelay > MAX_ANIMATION_DELAY){
errMsg.add("Animation Delay must be less than " + MAX_ANIMATION_DELAY);
}
} catch (NumberFormatException ex) {
errMsg.add("Animation Delay must be a Number");
}
}
/* check if physical delay was left blank */
if (physicalDelay.equals("")){
errMsg.add("Please enter the Physical disk delay");
} else {
/* check if the input given is valid */
try {
/* parse the physical delay entered into an integer */
setPhysicalDelay = Integer.parseInt(physicalDelay);
/* check check the range of the physical delay */
if (setPhysicalDelay < MIN_PHYSICAL_DELAY){
errMsg.add("Physical Delay must be greater than 0");
} else if (setPhysicalDelay > MAX_PHYSICAL_DELAY){
errMsg.add("Physical Delay must be less than " + MAX_PHYSICAL_DELAY);
}
} catch (NumberFormatException ex) {
errMsg.add("Physical Delay must be a Number");
}
}
/* if there is any problem, add the message to the popup and display */
if (!errMsg.isEmpty()){
JOptionPane.showMessageDialog(this, errMsg.toArray());
return false;
}
return true;
}
/**
* @param args the command line arguments
*/
// public static void main(String args[]) {
// java.awt.EventQueue.invokeLater(new Runnable() {
// public void run() {
// new HanoiFrame().setVisible(true);
// }
// });
// }
public static void main(String[] args) {
new HanoiFrame();
}
/*
*set up the requested amount of disks on the first pole
*@param diskAmount the amount of disks entered by the user
*/
public void setup(){
int numberOfDisks = setDiskAmount;
this.disks = new Disk[numberOfDisks];
int diskNumber = 0;
int diskWidth = POLE_AREA_WIDTH - 4;
int arcH = DISK_ARC_HEIGHT;
int arcW = DISK_ARC_WIDTH;
int x = startX;
int y = startY;
int row = 0;
int col = 0;
/* get the usable area of poleA */
Container clientArea = this.hanoiPanel;
/* get the graphics to the display panel*/
Graphics gfx = clientArea.getGraphics();
/* set the color of the disks */
gfx.setColor(Color.MAGENTA);
/* draw the specified number of disks */
while (diskNumber < numberOfDisks){
/* reduce the y position */
y = startY - diskNumber * CELL_HEIGHT;
/* draw the disk */
gfx.fillRoundRect(x, y, diskWidth, DISK_HEIGHT, arcH, arcW);
/* create a new instance of disk */
newDisk = new Disk(x, y, diskWidth);
/* give the new disk an id */
this.disks[diskNumber] = newDisk;
/* add the id to the cell array of poleA */
this.diskCells[row][col] = diskNumber;
/* make the disk smaller and center */
x = x + 8;
diskWidth = diskWidth - 16;
/* increase disk number */
diskNumber++;
/* move to the next row */
row++;
}
}
/*
*move the disk from a source pole to the destination pole.
*this should take the source col and destination col to determine where to draw the
*disk. It will also need to know to draw the disk in the first available cell
*in a col
*@param source the starting pole of the next move
*@param destination the end pole of the next move
*/
public void moveDisk(int src, int dest){
/* the lines below would not be necessary if I were to pass the Graphics
*gfx object as a parameter. I may have to use this option in order
*to work around the current repainting issue */
/* get the graphics area */
Container clientArea = this.hanoiPanel;
/* get the graphics associated display panel*/
Graphics gfx = clientArea.getGraphics();
/* get the id of the disk to be moved */
int disk = getDiskId(src);
/* get the to and from rows */
int sourceRow = getRow(src);
int destinationRow = getRow(dest);
/* set the co ordintates of the destination */
int col = dest * POLE_AREA_WIDTH;
int x = disks[disk].getStartX() + col;
int y = startY - (destinationRow * CELL_HEIGHT);
int width = disks[disk].getDiskWidth();
/* draw over (delete) the source disk */
gfx.setColor(Color.BLACK);
gfx.fillRoundRect(disks[disk].getStartX() + (src * POLE_AREA_WIDTH), startY - ((sourceRow-1) * CELL_HEIGHT),
disks[disk].getDiskWidth(), DISK_HEIGHT, DISK_ARC_WIDTH, DISK_ARC_HEIGHT);
/* set the source row to empty */
this.diskCells[sourceRow - 1][src] = EMPTY_CELL_VALUE;
/* draw the new disk in the destination */
gfx.setColor(Color.MAGENTA);
gfx.fillRoundRect(x, y, width, DISK_HEIGHT, DISK_ARC_WIDTH, DISK_ARC_HEIGHT);
/* set the destination row to the disk id */
this.diskCells[destinationRow][dest] = disk;
}
/*
*returns the id of the disk
*@param col the the designated column
*@return the disk identification number
*/
public int getDiskId(int col){
int diskIdent = 0;
/* initialize the row number to max -1, because the array start at 0 */
int row = MAX_DISKS - 1;
/* do a cell check while row is greater than 0
*this is done so that is starts at the top row
*and moves down
*/
while (row > EMPTY_CELL_VALUE){
/* when the first cell that is not -1 is reached get the disk number
*that disk will be the smallest in the stack */
if(diskCells[row][col] != -1){
diskIdent = this.diskCells[row][col];
break;
}
row--;
}
return diskIdent;
}
/*
*returns the first available row
*@param col the designated col
*@return the first available row number
*/
public int getRow(int col){
int rowNumber = 0;
/* cycle through the cells until it finds an empty one */
while (diskCells[rowNumber][col] != -1){
rowNumber++;
}
return rowNumber;
}
/*
*the recursive solution to the Towers of Hanoi problem
*@param diskAmount the number of disks that need to be moved
*@param start the identity of the starting column
*@param end the identity of the ending column
*@param temp the identity of the temporary column
*/
public void solutionEngine(int diskAmount,int start, int end, int temp){
int disks = diskAmount;
int startPole = start;
int endPole = end;
int tempPole = temp;
try {
if ( disks == 1 ) {
moveNumber++;
updateMessageCenter("Move number: " + moveNumber + " of " + intMovesLeft);
updateMessageCenter("Moving disk from "+ startPole + " to "+ endPole);
/* move the disk */
moveDisk(startPole, endPole);
/* delay the movement of the next disk */
Thread.sleep(setAnimationDelay);
outTextArea.repaint();
} else {
solutionEngine( disks - 1, startPole, tempPole, endPole);
moveNumber++;
updateMessageCenter("Move number: " + moveNumber + " of " + intMovesLeft);
updateMessageCenter("Moving disk from "+ startPole + " to "+ endPole);
moveDisk(startPole, endPole);
Thread.sleep(setAnimationDelay);
solutionEngine( disks - 1, tempPole, endPole, startPole);
}
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
/*
*calculate the total time it takes for the tower of hanoi game to be
*solved, given the amount of disk and the amount of time it takes
*to physically move a disk from one pole to the other.
*/
public void totalTime(){
int timeInSeconds = setPhysicalDelay * intMovesLeft;
int i = 0;
int seconds = 0;
int minute = 0;
int hour = 0;
int day = 0;
int month = 0;
int year = 0;
while (i < timeInSeconds){
if(seconds > 60){
minute++;
seconds = 0;
}
if(minute > 60){
hour++;
minute = 0;
}
if(hour > 24){
day++;
hour = 0;
}
if(day > 30){
month++;
day = 0;
}
if(month > 12){
year++;
month = 0;
}
seconds++;
i++;
}
updateMessageCenter("It would take:" + year + " years " + month + " months " + day +
" days " + hour + " hours " + minute + " minutes and " + seconds + " seconds, to move " + setDiskAmount +
" disks at " + setPhysicalDelay + " seconds per move");
}
/*
*add the message to the diplay window
*currently this is not necessary, but may be required to
*dynamically display the contents of message into the text area
*@param message the message to be added/appended the the text area
*/
public void updateMessageCenter(String message){
this.outTextArea.append(message + newline);
}
// Variables declaration - do not modify
private javax.swing.JTextField animationDelay;
private javax.swing.JTextField diskAmount;
private javax.swing.JPanel hanoiPanel;
private javax.swing.JPanel inputPanel;
private javax.swing.JLabel labelAdelay;
private javax.swing.JLabel labelDiskAmount;
private javax.swing.JLabel labelMSsuffix;
private javax.swing.JLabel labelPdelay;
private javax.swing.JLabel labelSecondSuffix;
private javax.swing.JScrollPane outScrollPane;
private javax.swing.JTextArea outTextArea;
private javax.swing.JPanel outputPanel;
private javax.swing.JTextField physicalDelay;
private javax.swing.JButton resetButton;
private javax.swing.JButton startButton;
// End of variables declaration
}
|
|
|
|
|
|
#2 |
|
SitePoint Zealot
![]() ![]() Join Date: Jan 2001
Location: Up North
Posts: 132
|
try :
this.setVisible(true) ; at the end of your while block, where you paint. It might affect performance, but it`s worth a try. I allways use that function when something isn`t showing correctly in the GUI. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 22:24.








Linear Mode
