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 86 87 88 89 90 91 92 93 94 95 96
|
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.Timer;
import swing.JRoundedPanel;
public class JvContentPane extends JRoundedPanel implements ActionListener {
private int rounded;
private Dimension maxDim;
private boolean etat;
private Timer t;
private int height;
JvContentPane(int rounded) {
super(rounded);
this.rounded = rounded;
this.maxDim = new Dimension(200, 50);
this.height = 0;
this.etat = false; // par defaut il est repliŽ
setSize(getPreferredSize().width, this.height);
this.setBackground(Color.gray);
this.t = new Timer(10, this);
System.out.println(getHeight() + " " + this.etat);
JPanel p = new JPanel();
p.setMinimumSize(new Dimension(100, 100));
p.setPreferredSize(new Dimension(100, 100));
p.setMaximumSize(new Dimension(100, 100));
p.setBackground(Color.red);
add(p);
}
/*public void setMaxSize(Dimension d) {
this.maxDim = d;
}
public void setMaxSize(int width, int height) {
this.maxDim = new Dimension(width, height);
}*/
public Dimension getPreferredSize() {
return new Dimension(maxDim.width, height);
}
public void changeEtat() {
if(! this.t.isRunning()) {
this.t.start();
this.etat = ! this.etat;
}
}
private void setHeight(int height) {
//this.setSize(this.getWidth(), height);
this.height = height;
this.setSize(getWidth(), height);
}
public void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRoundRect(0, 0, getWidth(), getHeight(), rounded, rounded);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object o = e.getSource();
if(o == this.t) {
//System.out.println(getHeight() + " " + this.etat);
if(this.etat) {
setVisible(true);
if(getHeight() < super.getPreferredSize().height) {
this.setHeight(getHeight() + 1);
}
else {
this.t.stop();
}
}
else {
if(getHeight() > 0) {
this.setHeight(getHeight() - 1);
}
else {
this.t.stop();
}
}
revalidate();
repaint();
}
}
} |
Partager