@ -19,6 +19,8 @@ public class MainFrame extends JFrame {
private JSONArray currentGameDifficulty ;
private JSONArray currentGameDifficulty ;
private Model currentModel ;
private Model currentModel ;
private JLabel currentGameLabel ;
private int currentPosition ;
public void run ( ) {
public void run ( ) {
@ -79,10 +81,37 @@ public class MainFrame extends JFrame {
JButton back = new JButton ( ) ;
JButton back = new JButton ( ) ;
back . setVisible ( true ) ;
back . setVisible ( true ) ;
back . setBounds ( 5 , 5 , 100 , 25 ) ;
back . setBounds ( 120 , 52 5, 100 , 25 ) ;
rootPanel . add ( back ) ;
rootPanel . add ( back ) ;
back . setText ( "Back" ) ;
back . setText ( "Back" ) ;
currentGameLabel = new JLabel ( ) ;
currentGameLabel . setVisible ( true ) ;
currentGameLabel . setBounds ( 250 , 525 , 40 , 25 ) ;
currentGameLabel . setText ( "0/0" ) ;
rootPanel . add ( currentGameLabel ) ;
JButton next = new JButton ( ) ;
next . setVisible ( true ) ;
next . setBounds ( 280 , 525 , 100 , 25 ) ;
rootPanel . add ( next ) ;
next . setText ( "Next" ) ;
next . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
if ( currentPosition + 1 < currentGameDifficulty . size ( ) ) {
currentPosition + + ;
} else {
currentPosition = 0 ;
}
JSONObject jsonObject = ( JSONObject ) currentGameDifficulty . get ( currentPosition ) ;
loadDataToGameField ( jsonObject ) ;
currentGameLabel . setText ( ( currentPosition + 1 ) + "/" + currentGameDifficulty . size ( ) ) ;
}
} ) ;
JButton newButton = new JButton ( ) ;
JButton newButton = new JButton ( ) ;
newButton . setVisible ( true ) ;
newButton . setVisible ( true ) ;
newButton . setBounds ( 395 , 5 , 100 , 25 ) ;
newButton . setBounds ( 395 , 5 , 100 , 25 ) ;
@ -206,11 +235,46 @@ public class MainFrame extends JFrame {
}
}
currentGameDifficulty = ( JSONArray ) object . get ( "easyGame" ) ;
currentGameDifficulty = ( JSONArray ) object . get ( "easyGame" ) ;
loadDataToGameField ( ( JSONObject ) currentGameDifficulty . get ( 0 ) ) ;
loadDataToGameField ( ( JSONObject ) currentGameDifficulty . get ( 0 ) ) ;
currentPosition = 0 ;
currentGameLabel . setText ( ( currentPosition + 1 ) + "/" + currentGameDifficulty . size ( ) ) ;
}
}
} ) ;
} ) ;
JMenuItem menu_i5 = new JMenuItem ( "Mittel" ) ;
JMenuItem menu_i5 = new JMenuItem ( "Mittel" ) ;
menu_i5 . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
String data = Model . loadAllData ( ) ;
JSONObject object = null ;
try {
object = ( JSONObject ) new JSONParser ( ) . parse ( data ) ;
} catch ( ParseException ex ) {
throw new RuntimeException ( ex ) ;
}
currentGameDifficulty = ( JSONArray ) object . get ( "mediumGame" ) ;
loadDataToGameField ( ( JSONObject ) currentGameDifficulty . get ( 0 ) ) ;
currentPosition = 0 ;
currentGameLabel . setText ( ( currentPosition + 1 ) + "/" + currentGameDifficulty . size ( ) ) ;
}
} ) ;
JMenuItem menu_i6 = new JMenuItem ( "Schwer" ) ;
JMenuItem menu_i6 = new JMenuItem ( "Schwer" ) ;
menu_i6 . addActionListener ( new ActionListener ( ) {
@Override
public void actionPerformed ( ActionEvent e ) {
String data = Model . loadAllData ( ) ;
JSONObject object = null ;
try {
object = ( JSONObject ) new JSONParser ( ) . parse ( data ) ;
} catch ( ParseException ex ) {
throw new RuntimeException ( ex ) ;
}
currentGameDifficulty = ( JSONArray ) object . get ( "hardGame" ) ;
loadDataToGameField ( ( JSONObject ) currentGameDifficulty . get ( 0 ) ) ;
currentPosition = 0 ;
currentGameLabel . setText ( ( currentPosition + 1 ) + "/" + currentGameDifficulty . size ( ) ) ;
}
} ) ;
m_menu . add ( menu_i1 ) ;
m_menu . add ( menu_i1 ) ;
m_menu . add ( menu_i2 ) ;
m_menu . add ( menu_i2 ) ;