Here you have my switch from my Class Essaie with the Main() :
switch(c)
{
case 0 :
zero();
break;
case 1 :
un();
break;
case 2 :
deux();
break;
case 3 :
trois();
break;
case 4 :
quatre();
break;
case 5 :
cinq();
break;
case 6 :
six();
break;
case 7 :
sept();
break;
case 8 :
huit();
break;
case 9 :
neuf();
break;
case 10 :
dix();
break;
case 11 :
onze();
break;
case 12 :
douze();
break;
case 13 :
exit = true;
break;
case 14 :
quatorze(); //HELP
default:
System.out.println("\nEntrez un numero compris entre 1 et 13 (14 pour help)");
break;
I would like to replace that with a simple frame that would call the same function using button to call them.
I’ve tried to create a class Windows and instantiate it in my main but i dont manage to link the action listener of the button of my Windows to the function in my class Essaie.
I’m sure that would be a lot easier to create the windows directly in the main and not use a class but i can’t get the trick, can anyone help me overcome this, or give me a sample of code to create button with action listener that would call those function?
To create a button that calls zero() you can:
And you can add the button b0 to your JFrame. When the user clicks the button, the actionPerformed method is invoked and that will call your zero() method.