CCB Premier Import
This commit is contained in:
6
EX-01/.classpath
Normal file
6
EX-01/.classpath
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
EX-01/.project
Normal file
17
EX-01/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EX-01</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
11
EX-01/.settings/org.eclipse.jdt.core.prefs
Normal file
11
EX-01/.settings/org.eclipse.jdt.core.prefs
Normal file
@@ -0,0 +1,11 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
BIN
EX-01/bin/AfficherSaisir.class
Normal file
BIN
EX-01/bin/AfficherSaisir.class
Normal file
Binary file not shown.
BIN
EX-01/bin/ApplicationGridLayout.class
Normal file
BIN
EX-01/bin/ApplicationGridLayout.class
Normal file
Binary file not shown.
BIN
EX-01/bin/ApplicationLayoutCombinaison.class
Normal file
BIN
EX-01/bin/ApplicationLayoutCombinaison.class
Normal file
Binary file not shown.
BIN
EX-01/bin/CalcButton.class
Normal file
BIN
EX-01/bin/CalcButton.class
Normal file
Binary file not shown.
BIN
EX-01/bin/Calculatrice.class
Normal file
BIN
EX-01/bin/Calculatrice.class
Normal file
Binary file not shown.
BIN
EX-01/bin/Calculette.class
Normal file
BIN
EX-01/bin/Calculette.class
Normal file
Binary file not shown.
BIN
EX-01/bin/Stock.class
Normal file
BIN
EX-01/bin/Stock.class
Normal file
Binary file not shown.
23
EX-01/src/AfficherSaisir.java
Normal file
23
EX-01/src/AfficherSaisir.java
Normal file
@@ -0,0 +1,23 @@
|
||||
import java.lang.Math;
|
||||
import java.util.Scanner;
|
||||
import java.text.*;
|
||||
public class AfficherSaisir {
|
||||
|
||||
public static void main(String[] args){
|
||||
System.out.println("Bonjour") ;
|
||||
|
||||
//Afficher ensuite le nombre pi (Math.PI) de mani<6E>re format<61>e avec 3 chiffres apr<70>s la virgule.
|
||||
DecimalFormat df = new DecimalFormat ( ) ;
|
||||
df.setMaximumFractionDigits ( 3 ) ; //arrondi <20> 3 chiffres apres la virgules
|
||||
System.out.println(df.format(Math.PI));
|
||||
|
||||
//Saisir un nombre n ; afficher un nombre al<61>atoire entre 0 et n
|
||||
@SuppressWarnings("resource")
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("Veuillez saisir un chiffre :");
|
||||
String str = sc.nextLine();
|
||||
System.out.println("Vous avez saisi : " + str);
|
||||
|
||||
System.out.println (Math.random());
|
||||
}
|
||||
}
|
||||
11
EX-01/src/ApplicationGridLayout.java
Normal file
11
EX-01/src/ApplicationGridLayout.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import java.awt.GridLayout;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
|
||||
public class ApplicationGridLayout {
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
56
EX-01/src/ApplicationLayoutCombinaison.java
Normal file
56
EX-01/src/ApplicationLayoutCombinaison.java
Normal file
@@ -0,0 +1,56 @@
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class ApplicationLayoutCombinaison {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Cr<43>er la fenetre de l'application
|
||||
JFrame mainFrame = new JFrame("Combinaison de plusieurs layout");
|
||||
|
||||
// Cr<43>er un panel global
|
||||
JPanel panelGlobal = new JPanel();
|
||||
|
||||
// Changer le layout du panel global
|
||||
panelGlobal.setLayout(new BorderLayout());
|
||||
|
||||
// Ajouter des boutons
|
||||
panelGlobal.add(new JButton("East"), BorderLayout.NORTH);
|
||||
panelGlobal.add(new JButton("West"), BorderLayout.SOUTH);
|
||||
|
||||
// Cr<43>er le panel du milieu
|
||||
JLabel panelLabel = new JLabel();
|
||||
panelLabel.add(new JLabel("Bouton 1"));
|
||||
panelGlobal.add(panelLabel, BorderLayout.NORTH);
|
||||
|
||||
JPanel panelBoutons = new JPanel();
|
||||
panelBoutons.setLayout(new GridLayout(2, 2));
|
||||
panelBoutons.add(new JButton("Bouton 1"));
|
||||
panelBoutons.add(new JButton("Bouton 2"));
|
||||
panelBoutons.add(new JButton("Bouton 3"));
|
||||
panelBoutons.add(new JButton("Bouton 4"));
|
||||
panelBoutons.add(new JButton("Bouton 1"));
|
||||
panelBoutons.add(new JButton("Bouton 2"));
|
||||
panelBoutons.add(new JButton("Bouton 3"));
|
||||
panelBoutons.add(new JButton("Bouton 4"));
|
||||
panelBoutons.add(new JButton("Bouton 1"));
|
||||
panelBoutons.add(new JButton("Bouton 2"));
|
||||
panelBoutons.add(new JButton("Bouton 3"));
|
||||
panelBoutons.add(new JButton("Bouton 4"));
|
||||
panelGlobal.add(panelBoutons, BorderLayout.SOUTH);
|
||||
|
||||
|
||||
//Ajout du panel a la fenetre
|
||||
mainFrame.add(panelGlobal);
|
||||
|
||||
//'Compactage' de la fenetre
|
||||
mainFrame.pack();
|
||||
|
||||
//On quitte l'application quand la fenetre est fermee
|
||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
//Affichage de la fen?tre
|
||||
mainFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
332
EX-01/src/Calculatrice.java
Normal file
332
EX-01/src/Calculatrice.java
Normal file
@@ -0,0 +1,332 @@
|
||||
import java.awt.*;
|
||||
import java.applet.Applet;
|
||||
import java.lang.Integer;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
|
||||
public class Calculatrice extends Applet
|
||||
{
|
||||
//d<>claration des variables pour les boutons
|
||||
|
||||
TextField txtDisp;
|
||||
public final int NONE = 0;
|
||||
public final int ADD = 1;
|
||||
public final int SUB = 2;
|
||||
public final int MUL = 3;
|
||||
public final int DIV = 4;
|
||||
public final int NEG = 5;
|
||||
public final int SQRT = 6;
|
||||
public final int EQ = 7;
|
||||
public final int C = 8;
|
||||
public final int AC = 9;
|
||||
public final int DECSEP = -1;
|
||||
|
||||
String msDecimal;
|
||||
int mnOp = NONE;
|
||||
boolean mbNewNumber = true;
|
||||
boolean mbDecimal = false;
|
||||
double mdReg = 0.0;
|
||||
|
||||
|
||||
/*
|
||||
Initialisation de l'applet
|
||||
Mise en page des boutons : couleur, et police de caract<63>re
|
||||
*/
|
||||
|
||||
public void init()
|
||||
{
|
||||
CalcButton btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9;
|
||||
CalcButton btnDecSep, btnNeg, btnSqrt, btnPlus, btnMinus;
|
||||
CalcButton btnTimes, btnDiv, btnEqual, btnClear, btnAllClear;
|
||||
|
||||
setLayout(null);
|
||||
setFont(new Font("Helvetica", Font.PLAIN, 14));
|
||||
//setBackground(new Color(0xCC, 0xCC, 0xCC));
|
||||
|
||||
btn0 = new CalcButton("0",NONE, 0);
|
||||
add(btn0);
|
||||
btn0.reshape(64, 164, 40, 24);
|
||||
btn0.setForeground(Color.blue);
|
||||
|
||||
btn1 = new CalcButton("1",NONE, 1);
|
||||
add(btn1);
|
||||
btn1.reshape(64, 132, 40, 24);
|
||||
btn1.setForeground(Color.blue);
|
||||
|
||||
btn2 = new CalcButton("2",NONE, 2);
|
||||
add(btn2);
|
||||
btn2.reshape(120, 132, 40, 24);
|
||||
btn2.setForeground(Color.blue);
|
||||
|
||||
btn3 = new CalcButton("3",NONE, 3);
|
||||
add(btn3);
|
||||
btn3.reshape(176, 132, 40, 24);
|
||||
btn3.setForeground(Color.blue);
|
||||
|
||||
btn4 = new CalcButton("4",NONE , 4);
|
||||
add(btn4);
|
||||
btn4.reshape(64, 100, 40, 24);
|
||||
btn4.setForeground(Color.blue);
|
||||
|
||||
btn5 = new CalcButton("5",NONE , 5);
|
||||
add(btn5);
|
||||
btn5.reshape(120, 100, 40, 24);
|
||||
btn5.setForeground(Color.blue);
|
||||
|
||||
btn6 = new CalcButton("6",NONE, 6);
|
||||
add(btn6);
|
||||
btn6.reshape(176, 100, 40, 24);
|
||||
btn6.setForeground(Color.blue);
|
||||
|
||||
btn7 = new CalcButton("7",NONE, 7);
|
||||
add(btn7);
|
||||
btn7.reshape(64, 68, 40, 24);
|
||||
btn7.setForeground(Color.blue);
|
||||
|
||||
btn8 = new CalcButton("8",NONE, 8);
|
||||
add(btn8);
|
||||
btn8.reshape(120, 68, 40, 24);
|
||||
btn8.setForeground(Color.blue);
|
||||
|
||||
btn9 = new CalcButton("9",NONE, 9);
|
||||
add(btn9);
|
||||
btn9.reshape(176, 68, 40, 24);
|
||||
btn9.setForeground(Color.blue);
|
||||
|
||||
btnDecSep = new CalcButton("<EFBFBD>",NONE, DECSEP);
|
||||
add(btnDecSep);
|
||||
btnDecSep.reshape(176, 164, 40, 24);
|
||||
btnDecSep.setForeground(Color.blue);
|
||||
|
||||
|
||||
btnNeg = new CalcButton("+/-", NEG, 0);
|
||||
add(btnNeg);
|
||||
btnNeg.reshape(120, 164, 40, 24);
|
||||
btnNeg.setForeground(Color.blue);
|
||||
|
||||
|
||||
btnSqrt = new CalcButton("Sqrt", SQRT, 0);
|
||||
add(btnSqrt);
|
||||
btnSqrt.reshape(8, 80, 40, 24);
|
||||
btnSqrt.setForeground(Color.red);
|
||||
|
||||
|
||||
btnPlus = new CalcButton("+", ADD, 0);
|
||||
add(btnPlus);
|
||||
btnPlus.reshape(232, 112, 40, 56);
|
||||
btnPlus.setForeground(Color.red);
|
||||
|
||||
|
||||
btnMinus = new CalcButton("-", SUB, 0);
|
||||
add(btnMinus);
|
||||
btnMinus.reshape(288, 112, 40, 24);
|
||||
btnMinus.setForeground(Color.red);
|
||||
|
||||
|
||||
btnTimes = new CalcButton("<EFBFBD>", MUL, 0);
|
||||
add(btnTimes);
|
||||
btnTimes.reshape(232, 80, 40, 24);
|
||||
btnTimes.setForeground(Color.red);
|
||||
|
||||
|
||||
btnDiv = new CalcButton("<EFBFBD>", DIV, 0);
|
||||
add(btnDiv);
|
||||
btnDiv.reshape(288, 80, 40, 24);
|
||||
btnDiv.setForeground(Color.red);
|
||||
|
||||
|
||||
btnEqual = new CalcButton("=", EQ, 0);
|
||||
add(btnEqual);
|
||||
btnEqual.reshape(288, 144, 40, 24);
|
||||
btnEqual.setForeground(Color.red);
|
||||
|
||||
|
||||
btnClear = new CalcButton("C", C, 0);
|
||||
add(btnClear);
|
||||
btnClear.reshape(8, 112, 40, 24);
|
||||
btnClear.setForeground(Color.red);
|
||||
|
||||
|
||||
btnAllClear = new CalcButton("AC", AC, 0);
|
||||
add(btnAllClear);
|
||||
btnAllClear.reshape(8, 144, 40, 24);
|
||||
btnAllClear.setForeground(Color.red);
|
||||
|
||||
|
||||
txtDisp = new TextField("0", 80);
|
||||
txtDisp.setEditable(false);
|
||||
add(txtDisp);
|
||||
txtDisp.reshape(64, 8, 268, 27);
|
||||
String sOneTenth = (new Double(0.1)).toString();
|
||||
msDecimal = sOneTenth.substring(sOneTenth.length()-2).substring(0, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
Cr<EFBFBD>ation de la frame
|
||||
*/
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
Frame frm = new Frame("Ma premiere calculatrice en java");
|
||||
Calculatrice ex1 = new Calculatrice();
|
||||
ex1.init();
|
||||
frm.add("Center", ex1);
|
||||
frm.pack();
|
||||
frm.resize(350, 350);
|
||||
frm.show();
|
||||
}
|
||||
|
||||
/*
|
||||
Fonction pour les nombres d<>cimaux
|
||||
*/
|
||||
|
||||
public void append(int nValue)
|
||||
{
|
||||
String sDigit;
|
||||
|
||||
if(nValue == DECSEP)
|
||||
if(!mbDecimal)
|
||||
{
|
||||
if(mbNewNumber)
|
||||
{
|
||||
txtDisp.setText("0");
|
||||
mbNewNumber = false;
|
||||
}
|
||||
mbDecimal = true;
|
||||
sDigit = msDecimal;
|
||||
}
|
||||
else
|
||||
return;
|
||||
else
|
||||
sDigit = (new Integer(nValue)).toString();
|
||||
if(mbNewNumber)
|
||||
{
|
||||
txtDisp.setText(sDigit);
|
||||
mbNewNumber = false;
|
||||
}
|
||||
else
|
||||
txtDisp.setText(txtDisp.getText() + sDigit);
|
||||
repaint();
|
||||
}
|
||||
|
||||
/*
|
||||
Initialisation des op<6F>rations
|
||||
*/
|
||||
public void doOp(int nNewOp)
|
||||
{
|
||||
double dDisp;
|
||||
dDisp = (new Double(txtDisp.getText())).doubleValue();
|
||||
switch(nNewOp)
|
||||
{
|
||||
case NEG:
|
||||
case SQRT:
|
||||
case C:
|
||||
case AC:
|
||||
|
||||
switch(nNewOp)
|
||||
{
|
||||
case NEG:
|
||||
txtDisp.setText((new Double(-dDisp)).toString());
|
||||
break;
|
||||
|
||||
case SQRT:
|
||||
txtDisp.setText((new Double(Math.sqrt(dDisp))).toString());
|
||||
mbNewNumber = true;
|
||||
mbDecimal = false;
|
||||
break;
|
||||
case C:
|
||||
mbNewNumber = true;
|
||||
mbDecimal = false;
|
||||
txtDisp.setText("0");
|
||||
break;
|
||||
case AC:
|
||||
mnOp = NONE;
|
||||
mbNewNumber = true;
|
||||
mbDecimal = false;
|
||||
mdReg = 0.0;
|
||||
txtDisp.setText("0");
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ADD:
|
||||
case SUB:
|
||||
case MUL:
|
||||
case DIV:
|
||||
case EQ:
|
||||
|
||||
switch(mnOp)
|
||||
{
|
||||
case ADD:
|
||||
mdReg = mdReg + dDisp;
|
||||
break;
|
||||
|
||||
case SUB:
|
||||
mdReg = mdReg - dDisp;
|
||||
break;
|
||||
case MUL:
|
||||
mdReg = mdReg * dDisp;
|
||||
break;
|
||||
case DIV:
|
||||
mdReg = mdReg / dDisp;
|
||||
break;
|
||||
case EQ:
|
||||
case NONE:
|
||||
mdReg = dDisp;
|
||||
break;
|
||||
}
|
||||
mnOp = nNewOp;
|
||||
mbNewNumber = true;
|
||||
mbDecimal = false;
|
||||
txtDisp.setText((new Double(mdReg)).toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*
|
||||
Initialisation de la calculatrice
|
||||
*/
|
||||
|
||||
public Calculatrice() {
|
||||
try {
|
||||
jbInit();
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void jbInit() throws Exception {
|
||||
this.setBackground(SystemColor.text);
|
||||
this.setSize(new Dimension(300, 316));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Initialisation des boutons
|
||||
*/
|
||||
|
||||
class CalcButton extends Button
|
||||
{
|
||||
int mnOp;
|
||||
int mnValue;
|
||||
|
||||
CalcButton(String sText, int nOp, int nValue)
|
||||
{
|
||||
super(sText);
|
||||
mnOp = nOp;
|
||||
mnValue = nValue;
|
||||
}
|
||||
|
||||
public boolean action(Event evt, Object arg)
|
||||
{
|
||||
Calculatrice par = (Calculatrice)getParent();
|
||||
|
||||
if(mnOp == par.NONE)
|
||||
par.append(mnValue);
|
||||
else
|
||||
{
|
||||
par.doOp(mnOp);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
31
EX-01/src/Calculette.java
Normal file
31
EX-01/src/Calculette.java
Normal file
@@ -0,0 +1,31 @@
|
||||
import javax.swing.*;
|
||||
public class Calculette {
|
||||
public static void main(String[] args) {
|
||||
//Cr<43>ation de la fen<65>tre de l'application
|
||||
JFrame mainFrame = new JFrame("Exemple de FlowLayout");
|
||||
|
||||
//Cr<43>ation d'un panel
|
||||
JPanel panelBoutons = new JPanel();
|
||||
|
||||
//Changement du layout du panel
|
||||
|
||||
|
||||
|
||||
//Ajout des boutons
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Ajout du panel <20> la fen<65>tre
|
||||
mainFrame.add(panelBoutons);
|
||||
|
||||
//'Compactage' de la fen<65>tre
|
||||
mainFrame.pack();
|
||||
|
||||
//On quitte l'application quand la fen<65>tre est ferm<72>e
|
||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
//Affichage de la fen<65>tre
|
||||
mainFrame.setVisible(true);}}
|
||||
72
EX-01/src/Stock.java
Normal file
72
EX-01/src/Stock.java
Normal file
@@ -0,0 +1,72 @@
|
||||
import java.util.Arrays;
|
||||
public class Stock {
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
//-----------------------------------------------------
|
||||
// Tableau de type de base
|
||||
//-----------------------------------------------------
|
||||
// D<>clarer les constantes
|
||||
|
||||
// D<>clarer les tableaux
|
||||
char t [] ;
|
||||
double t2 [] ;
|
||||
// DECLARATION d'une REFERENCE de type tableau
|
||||
// CETTE CASE POURRA ENSUITE CONTENIR L<>ADRESSE D<>UN TABLEAU
|
||||
|
||||
//Allouer les tableaux
|
||||
t = new char [3];
|
||||
t2 = new double [3];
|
||||
//ALLOCATION d'une zone memoire pour n entiers dans le TAS
|
||||
|
||||
//Mettre des valeurs dans les cases
|
||||
t[0] = 'A' ;
|
||||
t[1] = 'B';
|
||||
t[2] = 'C' ;
|
||||
|
||||
t2[0] = 10.5 ;
|
||||
t2[1] = 2.5 ;
|
||||
t2[2] = 21.5 ;
|
||||
// AFFECTATION d'une valeur <20> une case du tableau
|
||||
|
||||
//Parcours des deux tableaux avec deux boucles foreach
|
||||
// Avec une boucle foreach
|
||||
//Tableau 1
|
||||
System.out.println ("\n Parcours du tableau avec une boucle foreach : ");
|
||||
for(int i = 0; i < t.length; i++)
|
||||
{
|
||||
System.out.println("<EFBFBD> l'emplacement " + i +" du tableau nous avons = " + t[i]);
|
||||
}
|
||||
//Tableau 2
|
||||
for(int i = 0; i < t2.length; i++)
|
||||
{
|
||||
System.out.println("<EFBFBD> l'emplacement " + i +" du tableau nous avons = " + t2[i]); }
|
||||
//Parcours des deux tableaux en parall<6C>le avec une boucle while et un booleen
|
||||
//Tableau 1
|
||||
boolean fini = false ;
|
||||
int i = 0 ;
|
||||
System.out.println ("\n Parcours du tableau1 avec un booleen et une boucle while :");
|
||||
System.out.println ("--------------------");
|
||||
while (! fini) {
|
||||
System.out.print ("|"+t[i]+"|");
|
||||
i++ ;
|
||||
fini = i == t.length ;
|
||||
}
|
||||
System.out.println ("\n--------------------");
|
||||
//Tableau 2
|
||||
boolean fini1 = false ;
|
||||
int i1 = 0 ;
|
||||
while (! fini1) {
|
||||
System.out.print ("|"+t2[i1]+"|");
|
||||
i1++ ;
|
||||
fini1 = i1 == t2.length ;
|
||||
}
|
||||
System.out.println ("\n--------------------");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user