...
 
Commits (2)
......@@ -26,7 +26,7 @@ public class CarriereActeur {
private JPanel test;
private JPanel panel2;
private JButton carriereButton;
private Color sombre = new Color(89,91,93);
public static Color sombre = new Color(89,91,93);
private Color blue = new Color(53,146,196);
private CarriereDlg carriereDlg;
......
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="presentation.CarriereArbo">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<scrollpane id="c7664">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="45839" class="javax.swing.JTree" binding="treeGenre">
<constraints/>
<properties/>
<clientProperties>
<JTree.lineStyle class="java.lang.String" value=""/>
</clientProperties>
</component>
</children>
</scrollpane>
<scrollpane id="ac771">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="5fd09" class="javax.swing.JTextArea" binding="textAreaInfo">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
</children>
</grid>
</form>
package presentation;
import dto.FilmDTO;
import dto.GenreDTO;
import metier.DAOMetier;
import metier.IDAOMetier;
import javax.swing.*;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeSelectionModel;
import java.awt.*;
import java.io.FileInputStream;
import static presentation.CarriereActeur.sombre;
public class CarriereArbo {
private JPanel rootPanel;
private JTree treeGenre;
private JTextArea textAreaInfo;
//variable d'instance liaison avec la partie metier
private IDAOMetier cinema;
private TreeModel creationModele(){
DefaultMutableTreeNode racine = new DefaultMutableTreeNode("genre");
try {
for (GenreDTO g : cinema.ensGenres()){
DefaultMutableTreeNode noeud = new DefaultMutableTreeNode(g);
racine.add(noeud);
for (FilmDTO film : cinema.ensFilmsDuGenre(g.getNgenre())){
noeud.add(new DefaultMutableTreeNode(film));
}
}
}catch (Exception e){
System.err.println(e.getMessage());
}
return new DefaultTreeModel(racine);
}
private void init(){
try {
cinema = DAOMetier.getInstance();
}catch (Exception e){
System.err.println(e.getMessage());
}
}
public CarriereArbo(){
init();
//color
treeGenre.setBackground(sombre);
textAreaInfo.setBackground(sombre);
textAreaInfo.setForeground(Color.white);
treeGenre.setModel(creationModele());
treeGenre.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
treeGenre.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent treeExpansionEvent) {
try{ DefaultMutableTreeNode noeud = (DefaultMutableTreeNode) treeExpansionEvent.getPath().getLastPathComponent();
Object obj = noeud.getUserObject();
if(obj instanceof GenreDTO) {
GenreDTO genre = (GenreDTO) noeud.getUserObject();
textAreaInfo.setText("Nombre de film du genre " + genre + " : " + cinema.nbreFilmDuGenre(genre.getNgenre()));
}
}catch (Exception e){
System.err.println(e.getMessage());
}
}
@Override
public void treeCollapsed(TreeExpansionEvent treeExpansionEvent) {
}
});
treeGenre.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent treeSelectionEvent) {
if (treeGenre.getSelectionPath() != null && treeGenre.getSelectionPath().getPathCount()==3){
DefaultMutableTreeNode noeud = (DefaultMutableTreeNode) treeGenre.getLastSelectedPathComponent();
if (noeud.isLeaf()){
try{
FilmDTO film = (FilmDTO) noeud.getUserObject();
textAreaInfo.setText("Informatiopn sur le film : " + film.getTitre() + "\n\n"
+ "Réalisateur : " + film.getNomRealisateur() + "\n"
+ "Acrteur principal : " + film.getNomActeur());
}catch (Exception ex){
System.err.println(ex.getMessage());
}
}
}
}
});
}
public static void main(String[] args) {
JFrame frame = new JFrame("CarriereArbo");
frame.setContentPane(new CarriereArbo().rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
}