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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
/*FrameBase*/
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.border.Border;
import java.util.*;
import java.text.DateFormat;
public class FrameBase extends JFrame {
//static Vector notes=new Vector();
ImageIcon ip=new ImageIcon("icon_planning.jpg");
ImageIcon ic=new ImageIcon("icon_contacts2.jpg");
ImageIcon ie=new ImageIcon("icon_edt.jpg");
ImageIcon in=new ImageIcon("icon_notes2.jpg");
JButton bplanning = new JButton(ip);
JButton bcontact = new JButton(ic);
JButton bedt = new JButton(ie);
JButton bnote = new JButton(in);
//JToolBar bar=new JToolBar(1);
JLabel espace=new JLabel(" ");
JLabel espace2=new JLabel(" ");
JLabel espace3=new JLabel(" ");
/*JLabel espace4=new JLabel(" ",SwingConstants.LEFT);
JLabel espace5=new JLabel(" ",SwingConstants.CENTER);*/
JLabel fonc=new JLabel(" Fonctionnalités ");
JMenuBar menubar=new JMenuBar();
JMenu menu=new JMenu("Fichier");
JMenuItem j1=new JMenuItem("Quitter");
// Border me sert a diviser en 5 ma frame
BorderLayout bl=new BorderLayout(10,10);
// je creer un pane2 pr y mettre les notes
JPanel panel_principal=new JPanel();
// je creer un panel pr y mettre les boutton a la vertical
JPanel panel_bouttons=new JPanel();
// je cree une grille ds lakel je v disposer mes buttons
GridBagLayout bouttons = new GridBagLayout();
GridBagConstraints constraints ;
//private static CadreNote cn;
FrameBase(){
super("ProAgenda - Note");
setAlwaysOnTop(true);//tjrs laisser la fenetre au 1er plan
setSize(800,600);
//setBounds(125,50,800,600);
//je centre par rapport a ma fenetre parent
setLocationRelativeTo(getParent());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(menubar);
//je met un separateur ds le menu
menu.addSeparator();
//je met "quitter" ds le menu
menu.add(j1);
//menu ds menubar
menubar.add(menu);
setLayout(bl);//je rajoute le bl ds ma frame
//je creer une instance date
Date maDate=new Date();
//format de la date jeudi 22 decembre
DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL);
//mettre le label en haut a droite
add(new JLabel("Aujourd'hui, "+dateFormat.format(maDate)+" ",SwingConstants.RIGHT),BorderLayout.NORTH);
// je creer des espaces entre les bords de la frame
add(espace2,BorderLayout.EAST);
add(espace3,BorderLayout.SOUTH);
//je creer un contour pr panel_bouttons
Border borderLine = BorderFactory.createLineBorder(Color.BLACK);
panel_bouttons.setBorder(borderLine);
// je met ce panel 1 a louest
add(panel_bouttons,BorderLayout.WEST);
panel_bouttons.setLayout(bouttons);//je met le gridbag "bouttons" ds panel_bouttons
//je place mon label fonc:
constraints = new GridBagConstraints();
constraints.gridx = 0;//position de cellule : 0,0
constraints.gridy = 0;
constraints.gridwidth = 2;//nb de cellule occupées à l'horizontal
constraints.gridheight = 1;//nb de cellule occupées à la vertical
constraints.weightx = 100;//taille de ce composant=100% en fct des autre composants de cette ligne
constraints.weighty = 10;//10% par rapport au 100% de la colonne entiere
constraints.fill = GridBagConstraints.NONE;
constraints.anchor =GridBagConstraints.SOUTH;
bouttons.setConstraints(fonc, constraints);
panel_bouttons.add(fonc);
//je place mon boutton planning:
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.weightx = 100;
constraints.weighty = 22;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor =GridBagConstraints.CENTER;
bouttons.setConstraints(bplanning, constraints);
panel_bouttons.add(bplanning);
// je place mon boutton bcontact:
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 2;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.weightx = 100;
constraints.weighty = 22;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor =GridBagConstraints.CENTER;
bouttons.setConstraints(bcontact, constraints);
panel_bouttons.add(bcontact);
// je place mon boutton bedt:
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 3;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.weightx = 100;
constraints.weighty = 22;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor =GridBagConstraints.CENTER;
bouttons.setConstraints(bedt, constraints);
panel_bouttons.add(bedt);
// je place mon boutton bnote:
constraints = new GridBagConstraints();
constraints.gridx = 0;
constraints.gridy = 4;
constraints.gridwidth = 3;
constraints.gridheight = 1;
constraints.weightx = 100;
constraints.weighty = 22;
constraints.fill = GridBagConstraints.NONE;
constraints.anchor =GridBagConstraints.CENTER;
bouttons.setConstraints(bnote, constraints);
panel_bouttons.add(bnote);
// je creer un panel_principal pr y mettre les notes
//JPanel panel_principal=new JPanel();
// je met ce panel 2 au centre
add(panel_principal,BorderLayout.CENTER);
//je creer un contour pr panel_principal
Border borderLine2 = BorderFactory.createLineBorder(Color.BLACK);
panel_principal.setBorder(borderLine2);
//tt ceci est visible
setVisible(true);
}
public JPanel getPanelPrincipal(){
return panel_principal;
}
public static void main(String[] arguments){
FrameBase fn=new FrameBase();
//cn=new CadreNote();
//System.out.println("ds le main : "+fn.getPanelPrincipal());
//fn.getPanelPrincipal().add(new JLabel("zizi"));
fn.test();
}
} |
Partager