import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JPanel; @SuppressWarnings("serial") public class Fenetre extends JFrame { private JPanel container = new JPanel(); private Banniere PanelHaut = new Banniere(); //Creation of all buttons private Bouton bouton1 = new Bouton("Analyse"); private Bouton bouton2 = new Bouton("Débit"); private Bouton bouton3 = new Bouton("Pression & Température"); private Bouton bouton4 = new Bouton("Acquisition & Données"); private Bouton bouton5 = new Bouton("Automates & Supervision"); private Bouton bouton6 = new Bouton("SNCC & Sécurité"); private Bouton bouton7 = new Bouton("Vigilantplant"); private Bouton bouton8 = new Bouton("Home"); //Creation of all "tags" final static String s1 = "fenetre 1"; final static String s2 = "fenetre 2"; final static String s3 = "fenetre 3"; final static String s4 = "fenetre 4"; final static String s5 = "fenetre 5"; final static String s6 = "fenetre 6"; final static String s7 = "fenetre 7"; final static String s8 = "fenetre 8"; //Creation of all Panels private Panneau Cards = new Panneau(); private Analyse pan1 = new Analyse(); private Debit pan2 = new Debit(); private Pression pan3 = new Pression(); private Acquisition pan4 = new Acquisition(); private Automates pan5 = new Automates(); private Sncc pan6 = new Sncc(); private Vigilantplant pan7 = new Vigilantplant(); private Home pan8 = new Home(); public Fenetre() { //Creation of the window this.setIconImage(new ImageIcon("icone.jpg" ).getImage()); this.setTitle("dudule"); this.setSize(800, 600); this.setResizable(false); this.setLocationRelativeTo(null); //Closing the window /*this.addWindowListener ( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { hide(); } } );*/ //Creation of the organization container.setLayout(new BorderLayout()); //Creation of the Top PanelHaut.setLayout(new GridLayout(2,4,5,5)); //Creation of table PanelHaut.add(bouton1); //Add button1 bouton1.addActionListener(new Bouton1Listener()); //Definition of his action PanelHaut.add(bouton2); bouton2.addActionListener(new Bouton2Listener()); PanelHaut.add(bouton3); bouton3.addActionListener(new Bouton3Listener()); PanelHaut.add(bouton4); bouton4.addActionListener(new Bouton4Listener()); PanelHaut.add(bouton5); bouton5.addActionListener(new Bouton5Listener()); PanelHaut.add(bouton6); bouton6.addActionListener(new Bouton6Listener()); PanelHaut.add(bouton7); bouton7.addActionListener(new Bouton7Listener()); PanelHaut.add(bouton8); bouton8.addActionListener(new Bouton8Listener()); container.add(PanelHaut, BorderLayout.NORTH); //Creation of the page Cards.setLayout(new CardLayout()); Cards.add(s8,pan8); Cards.add(s1,pan1); Cards.add(s2,pan2); Cards.add(s3,pan3); Cards.add(s4,pan4); Cards.add(s5,pan5); Cards.add(s6,pan6); Cards.add(s7,pan7); container.add(Cards, BorderLayout.CENTER); //To print the window this.setContentPane(container); this.setVisible(true); } class Bouton1Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s1); } } class Bouton2Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s2); } } class Bouton3Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s3); } } class Bouton4Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s4); } } class Bouton5Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s5); } } class Bouton6Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s6); } } class Bouton7Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s7); } } class Bouton8Listener implements ActionListener { public void actionPerformed(ActionEvent e) { ((CardLayout) Cards.getLayout()).show(Cards,s8); } } }
import java.awt.Color; import java.awt.FontMetrics; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.io.File; import java.io.IOException; import javax.swing.JButton; import javax.imageio.ImageIO; @SuppressWarnings("serial") public class Bouton extends JButton{ private String name; private Image img; Color jauneY = new Color(255,255,1); public Bouton(String str){ super(str); this.name = str; try { img = ImageIO.read(new File("fondBouton.png")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D)g; GradientPaint gp = new GradientPaint(0, 0, Color.blue, 0, 20, Color.cyan, true); g2d.setPaint(gp); g2d.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this); g2d.setColor(jauneY); //Object permits to know properties of font, like the size ! FontMetrics fm = g2d.getFontMetrics(); //Of our font int height = fm.getHeight(); //Of the string, with our font int width = fm.stringWidth(this.name); //To calculate the location of the string g2d.drawString(this.name, this.getWidth() / 2 - (width / 2), (this.getHeight() / 2) + (height / 4)); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question