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
|
import javax.swing.* ;
import java.awt.* ;
import java.awt.event.* ;
class Fen2Boutons extends JFrame
{ final int NBOUTONS = 4 ;
public Fen2Boutons ()
{ setTitle ("Modif taille boutons") ;
setSize (300, 150) ;
Container contenu = getContentPane() ;
contenu.setLayout(new FlowLayout()) ;
boutons = new JButton[NBOUTONS] ;
for (int i=0 ; i<NBOUTONS ; i++)
{ boutons[i] = new JButton ("NUM "+i) ;
contenu.add(boutons[i]) ;
}
}
public void setTaillBout (int num, int l, int h)
{ boutons[num].setPreferredSize(new Dimension(l, h)) ;
boutons[num].revalidate() ;
}
private JButton boutons[] ;
}
public class Projet4
{ public static java.util.Scanner sc = new java.util.Scanner (System.In);
public static void main (String args[])
{ Fen2Boutons fen = new Fen2Boutons() ;
fen.setVisible(true) ;
int num, l, h ;
while (true)
{ System.out.print ("num bouton : ") ;
num = sc.nextInt() ;
System.out.print ("larg bouton : ") ;
l = sc.nextInt() ;
System.out.print ("haut bouton : ") ;
h = sc.nextInt() ;
fen.setTaillBout (num, l, h) ;
}
}
} |