1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| //*******************************************
//Fichier GUIState.java
//*******************************************
package mybudgetingtool;
public class GUIState {
//******************************************************
// Déclarations des variables pour la sauvegarde des TextsFields :
String oldtext1, oldtext2, oldtext3;
String oldtext4, oldtext5, oldtext6;
String oldtext7, oldtext8, oldtext9;
//******************************************************
// Déclarations des variables pour la sauvegarde des ComboBox :
int oldBox1, oldBox2, oldBox3, oldBox4, oldBox5, oldBox6;
//********
// Constructeur :
public GUIState(budgetingtool g)
{
oldtext1 = g.jTextField1.getText();
oldtext2 = g.jTextField2.getText();
oldtext3 = g.jTextField3.getText();
oldtext4 = g.jTextField4.getText();
oldtext5 = g.jTextField5.getText();
oldtext6 = g.jTextField6.getText();
oldtext7 = g.jTextField7.getText();
oldtext8 = g.jTextField8.getText();
oldtext9 = g.jTextField9.getText();
oldBox1 = g.jComboBox1.getSelectedIndex();
oldBox2 = g.jComboBox2.getSelectedIndex();
oldBox3 = g.jComboBox3.getSelectedIndex();
oldBox4 = g.jComboBox4.getSelectedIndex();
oldBox5 = g.jComboBox5.getSelectedIndex();
oldBox6 = g.jComboBox6.getSelectedIndex();
}
//Méthode :
public void setGUI(budgetingtool g) {
g.jTextField1.setText(oldtext1);
g.jTextField2.setText(oldtext2);
g.jTextField3.setText (oldtext3);
g.jTextField4.setText(oldtext4);
g.jTextField5.setText(oldtext5);
g.jTextField6.setText(oldtext6);
g.jTextField7.setText(oldtext7);
g.jTextField8.setText( oldtext8);
g.jTextField9.setText(oldtext9);
g.jComboBox1.setSelectedIndex(oldBox1);
g.jComboBox2.setSelectedIndex(oldBox2);
g.jComboBox3.setSelectedIndex(oldBox3);
g.jComboBox4.setSelectedIndex(oldBox4);
g.jComboBox5.setSelectedIndex(oldBox5);
g.jComboBox6.setSelectedIndex(oldBox6);
}
public void setinitializeGUI(budgetingtool g)
{
g.jTextField1.setText("0.00");
g.jTextField2.setText("0.00");
g.jTextField3.setText("0.00");
g.jTextField4.setText("0.00");
g.jTextField5.setText("0.00");
g.jTextField6.setText("0.00");
g.jTextField7.setText("0.00");
g.jTextField8.setText("0.00");
g.jTextField9.setText("0.00");
g.jComboBox1.setSelectedIndex(0);
g.jComboBox2.setSelectedIndex(0);
g.jComboBox3.setSelectedIndex(0);
g.jComboBox4.setSelectedIndex(0);
g.jComboBox5.setSelectedIndex(0);
g.jComboBox6.setSelectedIndex(0);
}
}
//*******************************************
// Fichier budgetingtool.java
//*******************************************
//utilisation d'un TextField
private void jTextField1FocusLost(java.awt.event.FocusEvent evt) {
Calculate();
if(jTextField1.getText().equals(undoStack.lastElement().oldtext1))
{
JOptionPane.showMessageDialog(this," pas d'élément à ajouter pour textField1");
}
else
{
addElementStack();
JOptionPane.showMessageDialog(this,undoStack.lastElement().oldtext1 +" élément 1 ajouté");
}
}
//********************************************************
Stack<GUIState> undoStack=new Stack<GUIState>();
Stack<GUIState> redoStack=new Stack<GUIState>();
undoStack.push(new GUIState(this));
redoStack.push(new GUIState(this));
private void addElementStack()
{
//Get GUI State :
oldState = new GUIState(this);
//put on undoStack
undoStack.push(oldState);
}
private void restoreundoState()
{
undoStack.pop();
oldState=undoStack.peek();
oldState.setGUI(this);
oldState=new GUIState(this);
redoStack.push(oldState);
}
private void restoreredoState()
{
redoStack.pop();
oldState=redoStack.peek();
oldState.setGUI(this);
addElementStack();
} |
Partager