TP06 - TP07 début

This commit is contained in:
HORVILLE 2022-03-07 17:26:31 +01:00
parent 975abd0e19
commit a5665f3b23
24 changed files with 175 additions and 2 deletions

Binary file not shown.

View File

@ -37,6 +37,6 @@ public class Segment {
}
public boolean equals(Segment s2) {
return this.start == s2.start && this.end == s2.end;
return (this.start.equals(s2.start) && this.end.equals(s2.end));
}
}

View File

@ -3,6 +3,6 @@ public class TestSegment {
Segment s = new Segment(0, 10, 10, 0);
Segment s2 = new Segment(0, 10, 10, 0);
System.out.println(s.equals(s2));
}
}

Binary file not shown.

View File

@ -0,0 +1,9 @@
public class Documentation {
public static void main(String[] args) {
for (String str : args) {
System.out.println(str.toUpperCase());
}
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
public class ToBase8 {
public static void main(String[] args) {
for (String str : args) {
int nb = Integer.parseInt(str, 8);
System.out.println(Integer.toHexString(nb).toUpperCase());
}
}
}

View File

@ -0,0 +1,4 @@
1. java.lang.Object
2. La classe Object
3. 10 (8 dont 2 surcharges)
4. 0 ?

BIN
APL2.1/TP06/Gris/Gris.class Normal file

Binary file not shown.

View File

@ -0,0 +1,7 @@
import java.awt.Color;
public class Gris extends Color {
public Gris(int l) {
super(l, l, l);
}
}

Binary file not shown.

View File

@ -0,0 +1,24 @@
import javax.swing.*;
import java.awt.*;
public class TestGris {
public static void main(String[] args) {
int size = Integer.parseInt(args[0]);
JFrame fenetre = new JFrame("Damier");
fenetre.setSize(size * 50, size * 50);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout grid = new GridLayout(size, size);
fenetre.setLayout(grid);
for (int i = 0; i < size * size; i++) {
JPanel panel = new JPanel();
if (i % 2 == 0) panel.setBackground(new Gris(150));
else panel.setBackground(Color.WHITE);
fenetre.add(panel);
}
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@ -0,0 +1,33 @@
import java.awt.print.Paper;
public class MetricPaper extends Paper {
private static double toMetric(double inch) {
return inch * 2.54d;
}
private static double toInch(double metric) {
return metric / 2.54d;
}
public double getMetricHeight() {
return toMetric(this.getHeight());
}
public double getMetricWidth() {
return toMetric(this.getWidth());
}
public double getMetricImageableX() {
return toMetric(this.getImageableX());
}
public double getMetricImageableY() {
return toMetric(this.getImageableY());
}
public MetricPaper() {
super();
this.setSize(toInch(210d), toInch(297d));
this.setImageableArea(toInch(15), toInch(15), toInch(180), toInch(267));
}
}

Binary file not shown.

View File

@ -0,0 +1,8 @@
import java.awt.print.Paper;
public class MetricTest {
public static void main(String[] args) {
MetricPaper p = new MetricPaper();
System.out.println(p.getMetricHeight());
}
}

Binary file not shown.

View File

@ -0,0 +1,30 @@
import java.awt.*;
import javax.swing.*;
public class Nuance extends Panel {
private Panel tagBox;
private Label colorTag;
private Color color;
private void createNuance(String colorCode) {
tagBox = new Panel();
tagBox.setBackground(Color.BLACK);
tagBox.setSize(new Dimension(getWidth(), 20));
color = Color.decode(colorCode);
this.setBackground(color);
this.add(tagBox);
}
public Nuance(String colorCode) {
super();
setPreferredSize(new Dimension(100, 100));
createNuance(colorCode);
}
public Nuance(String colorCode, int x, int y) {
super();
setPreferredSize(new Dimension(100, 100));
setSize(new Dimension(x, y));
createNuance(colorCode);
}
}

Binary file not shown.

View File

@ -0,0 +1,18 @@
import javax.swing.*;
import java.awt.*;
public class TestNuance {
public static void main(String[] args) {
JFrame fenetre = new JFrame("Damier");
fenetre.setSize(500, 300);
fenetre.setLocation(100, 100);
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenetre.setLayout(new GridLayout(1, 3));
fenetre.add(new Nuance("#FF0000", 100, 100));
fenetre.add(new Nuance("#00FF00", 100, 100));
fenetre.add(new Nuance("#0000FF", 100, 100));
fenetre.setVisible(true);
}
}

Binary file not shown.

View File

@ -0,0 +1,32 @@
import javax.swing.*;
import java.awt.*;
class NewJFrame extends JComponent {
public NewJFrame() {
super();
}
@Override
protected void paintComponent(Graphics brush) {
Graphics newBrush = brush.create();
if (this.isOpaque()) {
newBrush.setColor(this.getBackground());
newBrush.fillRect(0, 0, this.getWidth(), this.getHeight());
}
newBrush.setColor(this.getForeground());
}
}
public class Formes {
public static void main(String[] args) {
JFrame f = new JFrame("Formes");
f.setSize(500, 500);
f.setLocation(100, 100);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB