Accès rapide :
La vidéo
L'exemple de code proposé dans la vidéo
Cette vidéo vous montre comment coder votre première application graphique avec la librairie Swing fournie par le Java SE. Le plugin WindowBuilder, proposé par l'IDE Eclipse, vous est aussi présenté.
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 |
package fr.koor.swing.samples; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.UIManager; import javax.swing.plaf.nimbus.NimbusLookAndFeel; public class MyWindow extends JFrame { private static final long serialVersionUID = -4939544011287453046L; public MyWindow() { super( "My first Swing application !" ); this.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE ); this.setSize( 600, 400 ); this.setLocationRelativeTo( null ); JPanel contentPane = (JPanel) this.getContentPane(); contentPane.setLayout( new FlowLayout() ); JButton btnPushMe = new JButton( "Push me!" ); contentPane.add( btnPushMe ); JButton btnClickMe = new JButton( "Click me!!!!!!!!!!" ); contentPane.add( btnClickMe ); JCheckBox chkCheckMe = new JCheckBox( "Check me!" ); contentPane.add( chkCheckMe ); JTextField txtEditMe = new JTextField( "Edit me!" ); txtEditMe.setPreferredSize( new Dimension( 120, 30 ) ); contentPane.add( txtEditMe ); } public static void main(String[] args) throws Exception { // Apply a look'n feel UIManager.setLookAndFeel( new NimbusLookAndFeel() ); // Start my window MyWindow myWindow = new MyWindow(); myWindow.setVisible( true ); } } |
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :