slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Swing par la pratique PowerPoint Presentation
Download Presentation
Swing par la pratique

Loading in 2 Seconds...

play fullscreen
1 / 12

Swing par la pratique - PowerPoint PPT Presentation


  • 83 Views
  • Uploaded on

Swing par la pratique. Cedric.Dumas@emn.fr contrat Creative Commons Paternité-Pas d'Utilisation Commerciale-Partage des Conditions Initiales à l'Identique 2.0 France License. Le minimum. import java.awt.*; import javax.swing.*; public class Test {

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Swing par la pratique' - elsa


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1

Swing par la pratique

Cedric.Dumas@emn.frcontrat Creative Commons Paternité-Pas d'Utilisation Commerciale-Partage des Conditions Initiales à l'Identique 2.0 France License

le minimum
Le minimum

import java.awt.*;

import javax.swing.*;

publicclass Test {

publicstaticvoid main(String args[]) {

JFrame f = new JFrame();

f.setTitle("Fi2");

f.setPreferredSize(new Dimension(400,400));

f.pack();

f.setVisible(true);

}

}

une classe s par e
Une classe séparée

import java.awt.*;

import javax.swing.*;

publicclass Test {

publicstaticvoid main(String args[]) {

Simple f = new Simple();

f.setTitle("Fi2");

f.setPreferredSize(new Dimension(400,400));

f.pack();

f.setVisible(true);

}

}

publicclass Simple extends JFrame { }

un arbre pour simple
Un arbre pour Simple

publicclass Simple extends JFrame {

JPanel jPanelHaut;

JPanel jPanelBas;

public Simple() {

getContentPane().setLayout(new BorderLayout());

jPanelHaut = new JPanel();

jPanelHaut.setPreferredSize(new Dimension(400, 100));

jPanelHaut.setBorder(BorderFactory.createLineBorder(Color.GREEN, 3));

getContentPane().add(jPanelHaut, BorderLayout.NORTH);

jPanelBas = new JPanel();

jPanelBas.setPreferredSize(new Dimension(400, 200));

jPanelBas.setBorder(BorderFactory.createLineBorder(Color.RED, 3));

getContentPane().add(jPanelBas, BorderLayout.SOUTH);

}

}

slide5

publicclass Simple extends JFrame {

JLabel texteDuHaut, texteDuBas;

JPanel jPanelHaut;

JPanel jPanelBas;

public Simple() {

getContentPane().setLayout(new BorderLayout());

jPanelHaut = new JPanel();

jPanelHaut.setPreferredSize(new Dimension(400, 100));

jPanelHaut.setBorder(BorderFactory.createLineBorder(Color.GREEN, 3));

getContentPane().add(jPanelHaut, BorderLayout.NORTH);

jPanelBas = new JPanel();

jPanelBas.setPreferredSize(new Dimension(400, 200));

jPanelBas.setBorder(BorderFactory.createLineBorder(Color.RED, 3));

getContentPane().add(jPanelBas, BorderLayout.SOUTH);

texteDuHaut = new JLabel("l'IHM en Fi1...");

jPanelHaut.add(texteDuHaut);

texteDuBas = new JLabel("...et aprés en Fi2");

jPanelBas.add(texteDuBas);

slide6

publicclass Simple extends JFrame {

public Simple() {

getContentPane().setLayout(new BorderLayout());

/*

*

*/

JPanel jPanelHaut = new JPanel();

jPanelHaut.setPreferredSize(new Dimension(400, 100));

jPanelHaut.setBorder(BorderFactory.createLineBorder(Color.GREEN, 3));

jPanelHaut.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

getContentPane().add(jPanelHaut, BorderLayout.NORTH);

JLabel texteDuHaut = new JLabel("l'IHM en Fi1...");

jPanelHaut.add(texteDuHaut);

JButton boutonDuHaut = new JButton("Bouton Fi1");

jPanelHaut.add(boutonDuHaut);

/*

*

*/

JPanel jPanelBas = new JPanel();

jPanelBas.setPreferredSize(new Dimension(400, 200));

jPanelBas.setBorder(BorderFactory.createLineBorder(Color.RED, 3));

jPanelBas.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

getContentPane().add(jPanelBas, BorderLayout.SOUTH);

JLabel texteDuBas = new JLabel("...et aprés en Fi2");

jPanelBas.add(texteDuBas);

JButton boutonDuBas = new JButton("Bouton Fi2");

jPanelBas.add(boutonDuBas);

slide8

publicclass Simple extends JFrame {

public Simple() {

...

JButton boutonDuHaut = new JButton("Bouton Fi1");

jPanelHaut.add(boutonDuHaut);

boutonDuHaut.addActionListener(new ReponseBouton(texteDuHaut));

....

JButton boutonDuBas = new JButton("Bouton Fi2");

jPanelBas.add(boutonDuBas);

boutonDuBas.addActionListener(new ReponseBouton(texteDuBas));

}

publicclass ReponseBouton implements ActionListener

{

JLabel jbl;

ReponseBouton(JLabel par) { jbl=par; }

publicvoid actionPerformed(ActionEvent ae){

if (jbl != null) jbl.setText("nouveau "+ae.getWhen());

}

}

}

slide9

publicclass Simple extends JFrame {

JLabel texteDuBas,texteDuHaut;

JButton boutonDuBas,boutonDuHaut;

public Simple() {

/.../

texteDuHaut = new JLabel("l'IHM en Fi1...");

jPanelHaut.add(texteDuHaut);

boutonDuHaut = new JButton("Bouton Fi1");

jPanelHaut.add(boutonDuHaut);

boutonDuHaut.addActionListener(new ReponseBouton());

/.../

texteDuBas = new JLabel("...et aprés en Fi2");

jPanelBas.add(texteDuBas);

boutonDuBas = new JButton("Bouton Fi2");

jPanelBas.add(boutonDuBas);

boutonDuBas.addActionListener(new ReponseBouton());

}

publicclass ReponseBouton implements ActionListener

{

publicvoid actionPerformed(ActionEvent ae){

if (ae.getSource().equals(boutonDuBas))

texteDuBas.setText("nouveau bas : "+ae.getWhen());

elseif (ae.getSource().equals(boutonDuHaut))

texteDuHaut.setText("nouveau haut : "+ae.getWhen());

}

}

}

slide10

/.../

JButton boutonDuBas = new JButton("Bouton Fi2");

jPanelBas.add(boutonDuBas);

boutonDuBas.addActionListener(new ActionListener() {

publicvoid actionPerformed(ActionEvent e) {

texteDuBas.setText("nouveau bas : "+e.getWhen());

}

}

);

/.../

slide12

CODE POUR COPIER/COLLER DANS UN FICHIER JAVA

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

publicclass Simple extends JFrame {

// on sort ces deux references du contructeur pour en faire des donnees membres de la classe

// car la classe interne (qui y a acces !) ReponseBouton en a besoin

JLabel texteDuHaut;

JButton boutonDuHaut;

public Simple() {

getContentPane().setLayout(new BorderLayout());

JPanel jPanelHaut = new JPanel();

jPanelHaut.setPreferredSize(new Dimension(400, 100));

jPanelHaut.setBorder(BorderFactory.createLineBorder(Color.GREEN, 3));

jPanelHaut.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

getContentPane().add(jPanelHaut, BorderLayout.NORTH);

texteDuHaut = new JLabel("l'IHM en Fi1...");

jPanelHaut.add(texteDuHaut);

boutonDuHaut = new JButton("Bouton Fi1");

jPanelHaut.add(boutonDuHaut);

boutonDuHaut.addActionListener(new ReponseBouton());

JPanel jPanelBas = new JPanel();

jPanelBas.setPreferredSize(new Dimension(400, 200));

jPanelBas.setBorder(BorderFactory.createLineBorder(Color.RED, 3));

jPanelBas.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));

getContentPane().add(jPanelBas, BorderLayout.SOUTH);

Jlabel texteDuBas = new JLabel("...et aprés en Fi2");

jPanelBas.add(texteDuBas);

Jbutton boutonDuBas = new JButton("Bouton Fi2");

jPanelBas.add(boutonDuBas);

boutonDuBas.addActionListener(new ActionListener() {

// écriture compacte de la classe interne ReponseBouton (sous forme de classe anonyme) mais pour le bouton Bas

publicvoid actionPerformed(ActionEvent e) {

texteDuBas.setText("nouveau bas : "+e.getWhen());

}

}

);

}

// classe interne pour la gestion d'évènement sur le bouton Haut

publicclass ReponseBouton implements ActionListener

{

publicvoid actionPerformed(ActionEvent ae){

if (ae.getSource().equals(boutonDuHaut)) texteDuHaut.setText("nouveau haut : "+ae.getWhen());

}

}

}