Skip to content

Commit db35d7f

Browse files
committed
Image dans l'affichage (Manque quelques types de pont)
1 parent 4746158 commit db35d7f

File tree

6 files changed

+45
-7
lines changed

6 files changed

+45
-7
lines changed

ressources/bridge_arc.png

31.8 KB
Loading

ressources/bridge_beam.png

27.2 KB
Loading

ressources/bridge_hanging.png

27.3 KB
Loading

ressources/bridge_shroud.png

27.3 KB
Loading

src/bridgeconstructor/AskInterface.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,22 +413,22 @@ private void launchForwardChaining(){
413413
Affirmation A = (Affirmation) w;
414414
if(A.equals(BA)) {
415415
System.out.println("Pont en Arc");
416-
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont en Arc", Material.Wood, 1));
416+
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont en arc", Material.Wood, 1));
417417
} else if(A.equals(BB)) {
418418
System.out.println("Pont à Poutres");
419-
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont à Poutres", Material.Wood, 1));
419+
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont à poutres", Material.Wood, 1));
420420
} else if(A.equals(BH)) {
421421
System.out.println("Pont Suspendu");
422-
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont Suspendu", Material.Wood, 1));
422+
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont suspendu", Material.Wood, 1));
423423
} else if(A.equals(BS)) {
424424
System.out.println("Pont à hauban");
425-
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont à Hauban", Material.Wood, 1));
425+
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont à hauban", Material.Wood, 1));
426426
} else if(A.equals(BV)) {
427427
System.out.println("Pont à Voûtes");
428-
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont à Voûtes", Material.Wood, 1));
428+
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont à voûtes", Material.Wood, 1));
429429
} else if(A.equals(DB)) {
430430
System.out.println("Pont Levis !");
431-
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont-Levis", Material.Wood, 1));
431+
LB.add(new Bridge(Environment.getHeight(),0 , 0, Environment.getLength(), "Pont-levis", Material.Wood, 1));
432432
}
433433
}
434434
}

src/bridgeconstructor/ResponseInterface.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import javax.swing.BorderFactory;
88
import javax.swing.BoxLayout;
9+
import javax.swing.ImageIcon;
910
import javax.swing.JFrame;
1011
import javax.swing.JLabel;
1112
import javax.swing.JPanel;
@@ -22,6 +23,11 @@ public class ResponseInterface extends JFrame {
2223

2324
List<Bridge> list;
2425

26+
private String[] imageFileNames = { "bridge_arc.png", "bridge_beam.png", "bridge_hanging.png", "bridge_shroud.png"};
27+
private String path = "./ressources/";
28+
29+
private ImageIcon icon;
30+
2531
// Panel
2632
private JPanel main_panel;
2733
private JPanel up_panel;
@@ -30,6 +36,7 @@ public class ResponseInterface extends JFrame {
3036
private JLabel order;
3137
// Composition de la description d'un pont
3238
private JPanel bridge_panel;
39+
private JLabel image;
3340
private JLabel type;
3441
private JLabel height;
3542
private JLabel width; // MIN - MAX Width
@@ -95,6 +102,12 @@ private void buildComposants() {
95102
bridge_panel = new JPanel();
96103
bridge_panel.setBorder(raisedetched);
97104
bridge_panel.setLayout(new BoxLayout(bridge_panel, BoxLayout.Y_AXIS));
105+
icon = createImageIcon(getPath(B.getType()));
106+
image = new JLabel(icon);
107+
image.setVerticalTextPosition(JLabel.BOTTOM);
108+
image.setHorizontalTextPosition(JLabel.CENTER);
109+
image.setHorizontalAlignment(JLabel.CENTER);
110+
image.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
98111
type = new JLabel(B.getType());
99112
type.setAlignmentX(Component.CENTER_ALIGNMENT);
100113
height = new JLabel("Hauteur : " + B.getHeight());
@@ -103,6 +116,7 @@ private void buildComposants() {
103116
material = new JLabel("Matériau : " + B.getMaterial());
104117
price = new JLabel("Prix : " + B.getPrice());
105118
// Affichage
119+
bridge_panel.add(image);
106120
bridge_panel.add(type);
107121
bridge_panel.add(height);
108122
bridge_panel.add(width);
@@ -113,7 +127,7 @@ private void buildComposants() {
113127
list_panel.add(bridge_panel);
114128
}
115129
}
116-
130+
117131
private void buildInterface() {
118132
main_panel.add(up_panel);
119133
main_panel.add(list_panel);
@@ -124,4 +138,28 @@ private void buildInterface() {
124138
private void buildEvents() {
125139
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
126140
}
141+
142+
private String getPath(String type) {
143+
switch(type) {
144+
case "Pont en arc" :
145+
return path+imageFileNames[0];
146+
case "Pont à poutres" :
147+
return path+imageFileNames[1];
148+
case "Pont suspendu" :
149+
return path+imageFileNames[2];
150+
case "Pont à hauban" :
151+
return path+imageFileNames[3];
152+
default :
153+
return null;
154+
}
155+
}
156+
157+
private ImageIcon createImageIcon(String path) {
158+
if (path != null) {
159+
return new ImageIcon(path);
160+
} else {
161+
System.err.println("Couldn't find file: " + path);
162+
return null;
163+
}
164+
}
127165
}

0 commit comments

Comments
 (0)