TP Exceptions
This commit is contained in:
BIN
DEV2.1/TP10/01_Plantages/ArithmeticExceptionApplication.class
Normal file
BIN
DEV2.1/TP10/01_Plantages/ArithmeticExceptionApplication.class
Normal file
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
public class ArithmeticExceptionApplication {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(15/0);
|
||||
}
|
||||
}
|
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
public class ArrayIndexOutOfBoundsExceptionApplication {
|
||||
public static void main(String[] args) {
|
||||
int[] tab = {4,5,8,2,9};
|
||||
System.out.println(tab[15]);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/01_Plantages/NullPointerExceptionApplication.class
Normal file
BIN
DEV2.1/TP10/01_Plantages/NullPointerExceptionApplication.class
Normal file
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
public class NullPointerExceptionApplication {
|
||||
|
||||
private int a;
|
||||
|
||||
public static void main(String[] args) {
|
||||
NullPointerExceptionApplication test = null;
|
||||
test.a = 5;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/01_Plantages/NumberFormatExceptionApplication.class
Normal file
BIN
DEV2.1/TP10/01_Plantages/NumberFormatExceptionApplication.class
Normal file
Binary file not shown.
@@ -0,0 +1,6 @@
|
||||
public class NumberFormatExceptionApplication {
|
||||
public static void main(String[] args) {
|
||||
String texte = "Bonjour";
|
||||
int nombre = Integer.parseInt(texte);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/01_Plantages/RunTimeExceptionApplication.class
Normal file
BIN
DEV2.1/TP10/01_Plantages/RunTimeExceptionApplication.class
Normal file
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
public class RunTimeExceptionApplication {
|
||||
public static void main(String[] args) {
|
||||
throw new RuntimeException("Rip");
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/02_Capture/ArithmeticExceptionApplication.class
Normal file
BIN
DEV2.1/TP10/02_Capture/ArithmeticExceptionApplication.class
Normal file
Binary file not shown.
16
DEV2.1/TP10/02_Capture/ArithmeticExceptionApplication.java
Normal file
16
DEV2.1/TP10/02_Capture/ArithmeticExceptionApplication.java
Normal file
@@ -0,0 +1,16 @@
|
||||
public class ArithmeticExceptionApplication {
|
||||
|
||||
public static int division(int a, int b) {
|
||||
// En mettant l'exception ici, on option une ligne de plus à l'exécution
|
||||
return a/b;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
ArithmeticExceptionApplication.division(7, 0);
|
||||
} catch (ArithmeticException e) {
|
||||
System.out.println("Erreur : Division par 0");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
DEV2.1/TP10/03_Incomplet/Incomplet.class
Normal file
BIN
DEV2.1/TP10/03_Incomplet/Incomplet.class
Normal file
Binary file not shown.
11
DEV2.1/TP10/03_Incomplet/Incomplet.java
Normal file
11
DEV2.1/TP10/03_Incomplet/Incomplet.java
Normal file
@@ -0,0 +1,11 @@
|
||||
import java.io.IOException;
|
||||
|
||||
public class Incomplet {
|
||||
public static void main(String[] args) {
|
||||
byte[] txt = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0D, 0x0A};
|
||||
try {
|
||||
System.out.write(txt);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/04_Apparences/Fond$1.class
Normal file
BIN
DEV2.1/TP10/04_Apparences/Fond$1.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP10/04_Apparences/Fond$2.class
Normal file
BIN
DEV2.1/TP10/04_Apparences/Fond$2.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP10/04_Apparences/Fond$3.class
Normal file
BIN
DEV2.1/TP10/04_Apparences/Fond$3.class
Normal file
Binary file not shown.
BIN
DEV2.1/TP10/04_Apparences/Fond.class
Normal file
BIN
DEV2.1/TP10/04_Apparences/Fond.class
Normal file
Binary file not shown.
58
DEV2.1/TP10/04_Apparences/Fond.java
Normal file
58
DEV2.1/TP10/04_Apparences/Fond.java
Normal file
@@ -0,0 +1,58 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class Fond {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
try {
|
||||
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
} catch (ClassNotFoundException e) {
|
||||
}
|
||||
} catch (InstantiationException e2) {
|
||||
} catch (IllegalAccessException e3) {
|
||||
} catch (UnsupportedLookAndFeelException e4) {
|
||||
} // On constate que les boutons changent d'apparence
|
||||
catch (ClassCastException e5) {
|
||||
System.out.println("Nom de manager incorrect");
|
||||
} // Les boutons restent comme avant
|
||||
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(300,200);
|
||||
fenetre.setLocation(100,100);
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.setLayout(new GridLayout(1, 1));
|
||||
|
||||
JPanel panneau = new JPanel();
|
||||
|
||||
JButton bouton1 = new JButton("Cyan");
|
||||
JButton bouton2 = new JButton("Magenta");
|
||||
JButton bouton3 = new JButton("Jaune");
|
||||
|
||||
bouton1.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.CYAN);
|
||||
}
|
||||
});
|
||||
|
||||
bouton2.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.MAGENTA);
|
||||
}
|
||||
});
|
||||
|
||||
bouton3.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evenement) {
|
||||
panneau.setBackground(Color.YELLOW);
|
||||
}
|
||||
});
|
||||
|
||||
panneau.add(bouton1);
|
||||
panneau.add(bouton2);
|
||||
panneau.add(bouton3);
|
||||
|
||||
fenetre.add(panneau);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/05_Degres/Conversion.class
Normal file
BIN
DEV2.1/TP10/05_Degres/Conversion.class
Normal file
Binary file not shown.
9
DEV2.1/TP10/05_Degres/Conversion.java
Normal file
9
DEV2.1/TP10/05_Degres/Conversion.java
Normal file
@@ -0,0 +1,9 @@
|
||||
public class Conversion {
|
||||
public static double celsiusAFahrenheit(double n) {
|
||||
return n*9/5+32;
|
||||
}
|
||||
|
||||
public static double FahrenheitACelsius(double n) {
|
||||
return (n-32)*5/9;
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/05_Degres/Degres.class
Normal file
BIN
DEV2.1/TP10/05_Degres/Degres.class
Normal file
Binary file not shown.
38
DEV2.1/TP10/05_Degres/Degres.java
Normal file
38
DEV2.1/TP10/05_Degres/Degres.java
Normal file
@@ -0,0 +1,38 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class Degres extends JComponent {
|
||||
|
||||
@Override
|
||||
public void paintComponent(Graphics pinceau) {
|
||||
Graphics secondPinceau = pinceau.create();
|
||||
|
||||
if (this.isOpaque()) {
|
||||
secondPinceau.setColor(this.getBackground());
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
|
||||
secondPinceau.setColor(Color.ORANGE);
|
||||
secondPinceau.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
|
||||
JTextField celsius = new JTextField();
|
||||
JTextField fahrenheit = new JTextField();
|
||||
celsius.setBounds(0, 65, 160, 20);
|
||||
fahrenheit.setBounds(0, 90, 160, 20);
|
||||
|
||||
JLabel texteCelsius = new JLabel("°C");
|
||||
JLabel texteFahrenheit = new JLabel("°F");
|
||||
texteCelsius.setBounds(165, 65, 20, 20);
|
||||
texteFahrenheit.setBounds(165, 90, 20, 20);
|
||||
|
||||
celsius.getDocument().addDocumentListener(new GestionJTextField(celsius, fahrenheit, true));
|
||||
fahrenheit.getDocument().addDocumentListener(new GestionJTextField(fahrenheit, celsius, false));
|
||||
|
||||
this.add(celsius);
|
||||
this.add(fahrenheit);
|
||||
this.add(texteCelsius);
|
||||
this.add(texteFahrenheit);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/05_Degres/Fenetre.class
Normal file
BIN
DEV2.1/TP10/05_Degres/Fenetre.class
Normal file
Binary file not shown.
13
DEV2.1/TP10/05_Degres/Fenetre.java
Normal file
13
DEV2.1/TP10/05_Degres/Fenetre.java
Normal file
@@ -0,0 +1,13 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class Fenetre extends JFrame {
|
||||
public Fenetre() {
|
||||
this.setSize(200, 200);
|
||||
this.setLocation(100, 100);
|
||||
this.setLayout(new GridLayout(1, 1));
|
||||
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
Degres composant = new Degres();
|
||||
this.add(composant);
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/05_Degres/GestionJTextField.class
Normal file
BIN
DEV2.1/TP10/05_Degres/GestionJTextField.class
Normal file
Binary file not shown.
46
DEV2.1/TP10/05_Degres/GestionJTextField.java
Normal file
46
DEV2.1/TP10/05_Degres/GestionJTextField.java
Normal file
@@ -0,0 +1,46 @@
|
||||
import java.awt.event.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
public class GestionJTextField implements DocumentListener {
|
||||
|
||||
|
||||
private JTextField aConvertir;
|
||||
private JTextField convertirVers;
|
||||
private boolean cToF;
|
||||
|
||||
public GestionJTextField(JTextField aConvertir, JTextField convertirVers, boolean cToF) {
|
||||
this.aConvertir = aConvertir;
|
||||
this.convertirVers = convertirVers;
|
||||
this.cToF = cToF;
|
||||
}
|
||||
|
||||
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
}
|
||||
|
||||
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
try {
|
||||
if (this.cToF) {
|
||||
this.convertirVers.setText(Conversion.celsiusAFahrenheit(Double.parseDouble(this.aConvertir.getText())) + "");
|
||||
}
|
||||
else {
|
||||
this.convertirVers.setText(Conversion.FahrenheitACelsius(Double.parseDouble(this.aConvertir.getText())) + "");
|
||||
}
|
||||
} catch (NumberFormatException e2) {
|
||||
try {
|
||||
this.convertirVers.setText("???");
|
||||
} catch (IllegalStateException ee) {
|
||||
}
|
||||
} catch (IllegalStateException e3) {
|
||||
} finally {
|
||||
this.convertirVers.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
}
|
||||
}
|
BIN
DEV2.1/TP10/05_Degres/Main.class
Normal file
BIN
DEV2.1/TP10/05_Degres/Main.class
Normal file
Binary file not shown.
6
DEV2.1/TP10/05_Degres/Main.java
Normal file
6
DEV2.1/TP10/05_Degres/Main.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
Fenetre fenetre = new Fenetre();
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user