Sie sind auf Seite 1von 2

Universit Sidi Mohammed Ben Abdellah Facult des sciences Juridique Economique Et Sociales

AU :2011/2012 Licence Professionnelle Management et E-Commerce Travail rendre par E mail avant le 10/05/2012

TP N 5 IHM (Interface Homme Machine)en Java Utilisation de Package Swing


Exercice 1 : Implmenter le programme suivant sous clipse afin dafficher votre propre informations

import javax.swing.*; import java.awt.Component; import java.awt.FlowLayout; public class LabeledTextField extends JPanel { public LabeledTextField(String caption, int size) { setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel l1 = new JLabel(caption+ " : "); JTextField t1 = new JTextField(size); add(l1); add(t1); } public LabeledTextField(String caption, String size) { setLayout(new FlowLayout(FlowLayout.LEFT)); JLabel l1 = new JLabel(caption+ " : "); JTextField t1 = new JTextField(size); add(l1); add(t1);

} } import javax.swing.*; import java.awt.FlowLayout; public class ButtonPanel extends JPanel { public ButtonPanel(String captions[]) { setLayout(new FlowLayout(FlowLayout.LEFT)); for (int i=0; i<captions.length; i++) { JButton b = new JButton(captions[i]); add(b); } } }

Pr:Mostafa El mallahi

Universit Sidi Mohammed Ben Abdellah Facult des sciences Juridique Economique Et Sociales

AU :2011/2012 Licence Professionnelle Management et E-Commerce Travail rendre par E mail avant le 10/05/2012

import javax.swing.*; import java.awt.FlowLayout; import java.awt.BorderLayout; class Exp01 extends JFrame {

TP N 5 IHM (Interface Homme Machine)en Java Utilisation de Package Swing

Exp01() { super("Licence Professionnelle Management et E commerce"); JPanel content = new JPanel();// gr par un FlowLayout par dfaut content.setLayout(new BorderLayout()); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); content.add(new LabeledTextField("IHM", " Je suis entrain de developper un programme en java ")); content.add(new LabeledTextField("Code", 15)); content.add(new LabeledTextField("Nom", "Bouhlala ")); content.add(new LabeledTextField("Prnom", "Wassim")); content.add(new LabeledTextField("Date Naissance", "12/12/1990")); content.add(new LabeledTextField("Telephonne", "000000054")); content.add(new LabeledTextField("Email", "BouhlalaWassim@hotmail.co.ma")); content.add(new LabeledTextField("Licence prof", "Management et E commerce")); content.add(new LabeledTextField("Adresse", "N 45 Rue 13 saaada Fs")); String captions[] = { "OK", "Cancel", "Help" }; ButtonPanel bp = new ButtonPanel(captions); content.add("Left", bp); setContentPane(content);// affichage du panneau setSize(400,300); pack(); } setVisible(true);

public static void main(String ars[]) { new Exp01(); }

Pr:Mostafa El mallahi

Das könnte Ihnen auch gefallen