1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| public class Piste extends JPanel
{
private CommandePiste commande;
private GraphiquePiste graphique;
private boolean muet;
public Piste(File fichier)
{
super();
graphique = new GraphiquePiste(this);
commande = new CommandePiste(this);
muet = false;
setSize(1440,200);
setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
setBorder(new LineBorder(java.awt.Color.black));
add(commande);
add(graphique);
}
public void setMuet(boolean b)
{
muet = b;
graphique.repaint();
}
public boolean getMuet()
{
return muet;
}
}
public class CommandePiste extends JPanel implements ItemListener
{
private JCheckBox muetCheck;
private Piste piste;
public CommandePiste(Piste p)
{
piste = p;
setSize(new Dimension(200,200));
setBackground(java.awt.Color.LIGHT_GRAY);
muetCheck = new JCheckBox("Muet");
muetCheck.addItemListener(this);
add(muetCheck);
}
public void itemStateChanged(ItemEvent e)
{
Object source = e.getItemSelectable();
if(source==muetCheck)
{
if(e.getStateChange()==ItemEvent.SELECTED) piste.setMuet(true);
if(e.getStateChange()==ItemEvent.DESELECTED) piste.setMuet(false);
}
}
}
public class GraphiquePiste extends JPanel
{
private Piste piste;
public GraphiquePiste(Piste p)
{
super();
piste = p;
setPreferredSize(new Dimension(1240,200));
}
protected void paintComponent(Graphics g)
{
Dimension d = getSize();
g.setColor(java.awt.Color.WHITE);
g.drawRect(0, 0, d.height, d.width);
if(piste.getMuet()) g.setColor(java.awt.Color.BLUE);
else g.setColor(java.awt.Color.DARK_GRAY);
dessinerSon(g, d);
}
private void dessinerSon(Graphics g, Dimension d)
{
g.drawLine(0,d.height/2, d.width, d.height/2);
}
} |
Partager