update
This commit is contained in:
BIN
DEV.2.1/TP/TP10-Exceptions/1./MainArithmetic.class
Normal file
BIN
DEV.2.1/TP/TP10-Exceptions/1./MainArithmetic.class
Normal file
Binary file not shown.
@@ -1,6 +1,5 @@
|
||||
public class MainArtihmetic {
|
||||
public void main(String[] args) {
|
||||
String truc = "abc";
|
||||
System.out.println(Integer.parse.Int(truc));
|
||||
public class MainArithmetic {
|
||||
public static void main(String[] args) {
|
||||
System.out.println(15/0);
|
||||
}
|
||||
}
|
15
DEV.2.1/TP/TP10-Exceptions/2./Capture.java
Normal file
15
DEV.2.1/TP/TP10-Exceptions/2./Capture.java
Normal file
@@ -0,0 +1,15 @@
|
||||
public class Capture {
|
||||
|
||||
public static int ArithmeticPB(int val) {
|
||||
return val/0;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
int res = ArithmeticPB(5);
|
||||
System.out.println(res);
|
||||
} catch(ArithmeticException e) {
|
||||
System.err.println("cannot divide by 0");
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV.2.1/TP/TP10-Exceptions/3./Incomplet.class
Normal file
BIN
DEV.2.1/TP/TP10-Exceptions/3./Incomplet.class
Normal file
Binary file not shown.
6
DEV.2.1/TP/TP10-Exceptions/3./Incomplet.java
Normal file
6
DEV.2.1/TP/TP10-Exceptions/3./Incomplet.java
Normal file
@@ -0,0 +1,6 @@
|
||||
public class Incomplet {
|
||||
public static void main(String[] args) {
|
||||
byte[] txt = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x0D, 0x0A};
|
||||
System.out.print(new String(txt));
|
||||
}
|
||||
}
|
9
DEV.2.1/TP/TP10-Exceptions/5./Conversion.java
Normal file
9
DEV.2.1/TP/TP10-Exceptions/5./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;
|
||||
}
|
||||
}
|
38
DEV.2.1/TP/TP10-Exceptions/5./Degres.java
Normal file
38
DEV.2.1/TP/TP10-Exceptions/5./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);
|
||||
}
|
||||
}
|
46
DEV.2.1/TP/TP10-Exceptions/5./GestionJTextField.java
Normal file
46
DEV.2.1/TP/TP10-Exceptions/5./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) {
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user