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
| public class MemoThermMain extends JFrame {
private JPanel mainPanel = null;
private JPanel buttonsPanel = null;
private JPanel currentValuesPanel = null;
private JPanel optionsPanel = null;
private JPanel northPanel = null;
private GraphicPanel graphicPanel = null;
private JButton butAffichGraph;
private JButton butVidMem;
private JButton butReglHeure;
private JButton butRafraichir;
private TitledBorder titBordCurrentValues;
private JTextField txtHeureCourante;
private JTextField txtTemperatureCourante;
private ButtonGroup bgOptions;
private JRadioButton rbPointParPoint;
private JRadioButton rbSegments;
mainPanel = new JPanel(new BorderLayout());
northPanel = new JPanel(new BorderLayout());
buttonsPanel = new JPanel(new GridBagLayout());
currentValuesPanel = new JPanel(new GridBagLayout());
optionsPanel = new JPanel(new GridLayout(2, 1));
bgOptions = new ButtonGroup();
rbPointParPoint = new JRadioButton("Point par point");
rbSegments = new JRadioButton("Segments");
titBordCurrentValues = new TitledBorder("Heure et température courante");
butAffichGraph = new JButton();
butVidMem = new JButton();
butReglHeure = new JButton();
butRafraichir = new JButton();
readValues = new ArrayList();
bgOptions.add(rbPointParPoint);
bgOptions.add(rbSegments);
this.setSize(new Dimension(820, 500));
this.setTitle("MemoTherm");
this.addWindowListener(new WindowAdapter()
{
public void windowClosing (WindowEvent e)
{
closeApplication();
}
});
initMenu();
//initialisation des objets
txtHeureCourante = new JTextField("--:--:--");
txtHeureCourante.setColumns(8);
txtTemperatureCourante = new JTextField("- °C");
txtTemperatureCourante.setColumns(8);
txtHeureCourante.setEditable(false);
txtTemperatureCourante.setEditable(false);
butAffichGraph.setText("Afficher le graphique");
butVidMem.setText("Vider la mémoire");
butReglHeure.setText("Mettre à l'heure");
butRafraichir.setText("Rafraîchir");
currentValuesPanel.setBorder(titBordCurrentValues);
optionsPanel.add(rbPointParPoint);
optionsPanel.add(rbSegments);
rbPointParPoint.setSelected(true);
//placement des objets dans les différents panels
currentValuesPanel.add(txtHeureCourante, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(0, 10, 0, 5), 0, 0));
currentValuesPanel.add(txtTemperatureCourante, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(0, 10, 0, 5), 0, 0));
currentValuesPanel.add(butRafraichir, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(0, 10, 0, 5), 0, 0));
buttonsPanel.add(butAffichGraph, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(22, 10, 0, 5), 0, 0));
buttonsPanel.add(butVidMem, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(22, 5, 0, 5), 0, 0));
buttonsPanel.add(butReglHeure, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(22, 5, 0, 5), 0, 0));
buttonsPanel.add(currentValuesPanel, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(5, 5, 5, 5), 0, 0));
buttonsPanel.add(optionsPanel, new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(5, 5, 0, 5), 0, 0));
buttonsPanel.add(Box.createGlue(), new GridBagConstraints(5, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
//initialisation des boutons
initButtons();
//initialisation du graphicPanel
initGraphicPanel();
northPanel.add(buttonsPanel, BorderLayout.WEST);
mainPanel.add(northPanel, BorderLayout.NORTH);
mainPanel.add(graphicPanel, BorderLayout.CENTER);
this.getContentPane().add(mainPanel);
}
private void initGraphicPanel()
{
//initilisation de graphicPanel
graphicPanel = new GraphicPanel();
graphicPanel.setBackground(Color.WHITE);
}
private void initMenu()
{
//initialisation du menu
JMenuBar menuBar = new JMenuBar();
JMenu jMenuFile = new JMenu();
JMenuItem jMenuFileSave = new JMenuItem();
JMenuItem jMenuFileOpen = new JMenuItem();
JMenuItem jMenuFileExit = new JMenuItem();
jMenuFile.setText("Fichier");
jMenuFileSave.setText("Sauver...");
jMenuFileOpen.setText("Ouvrir...");
jMenuFileExit.setText("Quitter");
jMenuFileSave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
saveGraphic();
}
});
jMenuFileOpen.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
openGraphic();
}
});
jMenuFileExit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
closeApplication();
}
});
jMenuFile.add(jMenuFileSave);
jMenuFile.add(jMenuFileOpen);
jMenuFile.add(jMenuFileExit);
menuBar.add(jMenuFile);
this.setJMenuBar(menuBar);
} |
Partager