SSCCE of my graphical interface with memory leak
Hi all,
I tried to write a SSCCE of my graphical interface that has some
problem of memory leak.
I resolved the problem minimizing and maximizing the graphical
interface (f.setState( Frame.ICONIFIED ); f.setState( Frame.NORMAL );)
but i don't understand where the memory leak are...
in the login windows you have to put:
user:guest
PW:guest
Thanks
Sal
<Main Class CODE>
package inter;
import java.io.*;
import java.lang.Object.* ;
import java.util.*;
import javax.comm.CommPortIdentifier;
import javax.swing.JOptionPane;
public class Principale {
public static void main(String[] args) {
try {
Interfaccia2 app = new Interfaccia2();
} catch (NullPointerException e) {}
System.gc();
System.runFinalization();
System.gc();
}
}
</Main Class CODE>
<interface class CODE>
package inter;
import javax.comm.SerialPort;
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.text.DecimalFormat;
import java.util.*;
import java.awt.*;
import java.awt.Color.*;
import java.awt.event.*;
import com.toedter.calendar.*;
public class Interfaccia2 extends JFrame implements ActionListener
{
double impVmin =0;
double impVmax =0;
double impSmax =0;
double impScarto_min_ora =0;
double impScarto_MAX_ora =0;
double impMedia_h_min =0;
double impMedia_h_max =0;
double impValore_limite =0;
double impValore_attenzione =0;
double misuraprecedentevalida =0;
double misuraprecedente =0;
double scarto =0;
double scartomaxDB =0;
int oramisura =0;
int oramisuraprecedente =0;
int giornomisura =0;
int giornomisura_med_h =0;
String string_giornomisura ="";
int giornomisuraprecedente =0;
int giornomisuraprecedente_med_h =0;
int mesemisura =0;
int mesemisuraprecedente =0;
int annomisura =0;
int annomisuraprecedente =0;
int giornidelmese =0;
String anno_mese_giorno ="";
int min_misura_precedente =0;
int scarto_min_misura_precedente =0;
int ora_misura_precedente =0;
int num_misure_NV_h =0;
int num_misure_M_h =0;
int num_misure_F_h =0;
String validazione_media_h="";
int num_mis_el_val =0;
int flag_allarme=0;
int flag_Purge_Air=0;
int flag_Carrier_Gas=0;
int flag_Low_Oven_Temp=0;
int flag_High_Oven_Temp=0;
int ID_misura=0;
String orario_misura="";
double misurappm =0;
double mediagiornaliera;
int mediagiornalieraDB;
int giorno_num_medie_h_valide =0;
double mediamensile;
double num_ore_norm_funz =0;
String string_num_ore_norm_funz ="";
double indice_disp_giornaliero =0;
String string_indice_disp_giornaliero ="";
double num_mediaoraria_125 =0;
double num_mediaoraria_mag_allarme =0;
double num_mediaoraria_mag_attenzione =0;
double perc_dati_el_validi =0;
String String_perc_dati_el_validi ="";
double sommaarray=0;
double sommamediah=0;
String stringmediaoraria;
String stringmediagiornaliera;
String stringmisurappm;
String stringmediamensile;
double mese_num_ore_norm_funz =0;
String string_mese_num_ore_norm_funz ="";
double mese_indice_disp =0;
String string_mese_indice_disp ="";
double mese_num_mediaoraria_110 =0;
double num_mediamensile_mag_allarme =0;
double num_mediamensile_mag_attenzione =0;
String data_med_h = "";
String data_med_g = "";
String data_med_m = "";
String orario_med_h = "";
int mediaorariaDB;
double mediaoraria;
double mediaoraria2;
double Scartomediaoraria =0;
double Scarto_min_mediaoraria =0;
double Scarto_MAX_mediaoraria =0;
//INTERFACCIA LOGIN
JLabel label_utente = null;
JLabel label_pw = null;
JTextField jTextField_utente;
private static String OK = "ok";
private JFrame controllingFrame; //needed for dialogs
private JPasswordField passwordField;
String string_utente ="";
String string_pw ="";
String string_pw_db ="";
JFrame frame_login;
// ORARIO
int day = 0;
int mese = 0;
int anno = 0;
int h = 0;
int m = 0;
int s = 0;
// FINE ORARIO
//FINE INTERFACCIA LOGIN
//interfaccia impostazioni
JLabel labelVmin = null;
JLabel labelVmax = null;
JLabel labelSmax = null;
JLabel labelScarto_MAX_ora = null;
JLabel labelScarto_min_ora = null;
JLabel labelMedia_h_min = null;
JLabel labelMedia_h_max = null;
JLabel labelValore_limite = null;
JLabel labelValore_attenzione = null;
JLabel labelppm1 = null;
JLabel labelppm2 = null;
JLabel labelppm3 = null;
JLabel labelppm4 = null;
JLabel labelppm5 = null;
JLabel labelppm6 = null;
JLabel labelppm7 = null;
JLabel labelppm8 = null;
JLabel labelppm9 = null;
JTextField jTextFieldVmin;
JTextField jTextFieldVmax;
JTextField jTextFieldSmax;
JTextField jTextFieldScarto_MAX_ora;
JTextField jTextFieldScarto_min_ora;
JTextField jTextFieldMedia_h_min = null;
JTextField jTextFieldMedia_h_max = null;
JTextField jTextFieldValore_limite = null;
JTextField jTextFieldValore_attenzione = null;
JButton cancelButton;
JButton cancelButton_comm;
JButton okButton;
JButton okButton_comm;
JButton okButton_info;
JButton okButton_licenza;
JFrame f;
JFrame flicenza;
JFrame fimp;
JFrame fimp_comm;
JFrame finfo;
JFrame fstampa;
//Fine interfaccia impostazioni
//interfaccia Licenza
TextArea area_licenza ;
JTextField jTextField_scadenza_licenza = null;
JLabel label_scadenza_licenza = null;
// fine interfaccia Licenza
// Inizio interfaccia Stampa
JButton stampaButton;
JLabel label_tipo_misura = null;
JLabel label_data_da_stampare = null;
JTextField jTextField_tipo_misura;
JDateChooser scelta_data;
JComboBox combo_misura;
String String_scelta_data;
String misura_da_stampare;
String misura_da_stampare_combo;
String label_report;
String nome_file_jrxml;
int item_combo;
//Fine interfaccia Stampa
double Vmin = 30;
double Vmax= 10030;
double Smax =10030;
String stringVmin = "";
String stringVmax = "";
String stringSmax = "";
String stringScarto_min_ora = "";
String stringScarto_MAX_ora = "";
String stringMedia_h_min = "";
String stringMedia_h_max = "";
String stringValore_limite = "";
String stringValore_attenzione = "";
String misura_per_interfaccia="";
String stringa_letta_da_seriale="";
String controllo_nastro="";
int nastro_interrotto =0;
// INTERFACCIA PRINCIPALE
JComboBox combo_stop;
int item_combo_stop;
JButton StopButton;
JButton RiprendiButton;
JLabel labelStop = null;
JLabel labelAttenzione = null;
JLabel labelAllarme = null;
JLabel labelNastro = null;
boolean acquisisci_misura =true;
String validazione = "";
int Flag_validazione = 0;
String motivo_Stop = "";
// JLabel labelH2Sperc = null;
JLabel labelH2Sppm = null;
JLabel labelmhppm = null;
JLabel labelmgppm = null;
//JLabel labelperc = null;
JLabel labelppm = null;
JLabel labelMediah = null;
JLabel label_ora_Mediah = null;
JLabel labelMediag = null;
JLabel label_giorno_Mediag = null;
JLabel tempo = null;
JLabel tempovis = null;
JLabel labelebc = null;
JLabel pannello_misure= null;
// FINE INTERFACCIA PRINCIPALE
// ALLARMI
Color verde;
Color rosso;
Color grigio;
Color giallo;
Color blu;
JLabel pannello_allarmi= null;
JLabel label_Allarmi = null;
JLabel label_Purge_Air = null;
JLabel label_Carrier_Gas = null;
JLabel label_Low_Oven_Temp = null;
JLabel label_High_Oven_Temp = null;
JLabel led_verde_Purge_Air;
JLabel led_rosso_Purge_Air ;
JLabel led_verde_Carrier_Gas;
JLabel led_rosso_Carrier_Gas;
JLabel led_verde_Low_Oven_Temp;
JLabel led_rosso_Low_Oven_Temp;
JLabel led_verde_High_Oven_Temp;
JLabel led_rosso_High_Oven_Temp;
// FINE ALLARMI
JLabel label_Comm_Port = null;
JLabel label_Baud_Rate = null;
JLabel label_Data_Bits = null;
JLabel label_Parity = null;
JLabel label_Stop_Bits = null;
JLabel label_Controllo_allarmi= null;
JTextField jTextField_Comm_Port;
JTextField jTextField_Baud_Rate;
JTextField jTextField_Data_Bits;
JTextField jTextField_Parity;
JTextField jTextField_Stop_Bits;
JTextField jTextField_Controllo_allarmi;
String string_Comm_Port= "";
String string_Baud_Rate= "";
String string_Data_Bits= "";
String string_Parity= "";
String string_Stop_Bits= "";
String string_Controllo_allarmi= "";
JLabel label_Version = null;
JLabel label_info = null;
JLabel label_Sviluppato = null;
JLabel label_Indirizzo = null;
JTextArea Area_info;
JLabel labelIconEBC;
//JTextField jTextField1;
JTextField jTextFieldppm;
JTextField jTextFieldMediah;
JTextField jTextFieldMediag;
JTextField jTextFieldTime;
private JMenuItem simpleItem;
String misura = "";
private JMenuItem simpleItem2;
private JMenuItem simpleItem5;
private JMenuItem simpleItem6;
private JMenuItem simpleItem7;
private JMenuItem simpleItem3;
private JMenuItem simpleItem4;
JLabel timeField;
int int_Baud_rate;
public Interfaccia2()
{
// ********* INIZIO GESTIONE LOGIN ***************
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
controllingFrame = f;
passwordField = new JPasswordField(11);
passwordField.setActionCommand(OK);
passwordField.addActionListener(this);
label_utente = new JLabel(" Utente: ");
label_pw = new JLabel("Password: ");
label_utente.setLabelFor(passwordField);
jTextField_utente = new JTextField (10);
label_pw.setLabelFor(jTextField_utente);
JButton ok_Button_login = new JButton("OK");
ok_Button_login.setActionCommand(OK);
ok_Button_login.addActionListener(this);
JPanel textPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
textPane.add(label_utente);
textPane.add(jTextField_utente);
JPanel textPane2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
textPane2.add(label_pw);
textPane2.add(passwordField);
textPane2.add(ok_Button_login);
frame_login = new JFrame("Login TK Data");
frame_login.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame_login.getContentPane().setLayout(new GridLayout(0,1));
frame_login.getContentPane().add(textPane);
frame_login.getContentPane().add(textPane2);
frame_login.pack();
frame_login.setVisible(true);
// ********* FINE GESTIONE LOGIN ***************
// ********* INIZIO FRAME PRINCIPALE ***************
Dimension screenSize =Toolkit.getDefaultToolkit().getScreenSize();
verde = new Color(0,153,0);
rosso = new Color(255,0,0);
grigio = new Color (224,223,227);
giallo = new Color (255,255,0);
blu = new Color (0,0,255);
//Font Label
Font fontlabel = new Font( "Verdana",Font.PLAIN,14);
Font fontlabelBold = new Font( "Verdana",Font.BOLD,14);
// System.out.println("screenSize: "+screenSize.toString());
// imposta il Look&Feel di sistema
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
// Menu
JMenuBar menubar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenu menu_imp = new JMenu("Impostazioni");
JMenu menu_info = new JMenu("?");
simpleItem = new JMenuItem("Impostazioni Validazione");
simpleItem5 = new JMenuItem("Login");
simpleItem6 = new JMenuItem("Stampa");
simpleItem2 = new JMenuItem("Chiudi");
simpleItem3 = new JMenuItem("Impostazioni Comunicazione");
simpleItem4 = new JMenuItem("Informazioni");
simpleItem7 = new JMenuItem("Licenza Software");
menu.add(simpleItem5);
menu.add(simpleItem6);
menu.add(simpleItem2);
menu_imp.add(simpleItem);
menu_imp.add(simpleItem3);
menu_info.add(simpleItem4);
menu_info.add(simpleItem7);
menubar.add(menu);
menubar.add(menu_imp);
menubar.add(menu_info);
// Aggiunge la menubar al JFrame
setJMenuBar(menubar);
simpleItem.addActionListener(this);
simpleItem2.addActionListener(this);
simpleItem3.addActionListener(this);
simpleItem4.addActionListener(this);
simpleItem5.addActionListener(this);
simpleItem6.addActionListener(this);
simpleItem7.addActionListener(this);
// fine aggiunta menu
//Inizio Orologio
// Create a 1-second timer and action listener for it.
// Specify package because there are two Timer classes
timeField = new JLabel("");
javax.swing.Timer t = new javax.swing.Timer(1000,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
Calendar now = Calendar.getInstance();
day = now.get(Calendar.DAY_OF_MONTH);
mese = now.get(Calendar.MONTH)+1;
anno = now.get(Calendar.YEAR);
h = now.get(Calendar.HOUR_OF_DAY);
m = now.get(Calendar.MINUTE);
s = now.get(Calendar.SECOND);
timeField.setText("Data: "+ day + "-" + mese + "-" + anno + "
Ore: " + h + ":" + m + ":" + s);
if (s % 20 == 1){
//with this 2 lines i'Ve resolved the memory leak problem but i
dont know where they are
f.setState( Frame.ICONIFIED );
f.setState( Frame.NORMAL );
//System.out.println("20 sec");
}
System.gc();
System.runFinalization();
System.gc();
}
}
);
t.start(); // Start the timer
timeField.setFont(fontlabel);
// Label
labelH2Sppm = new JLabel("H2S:");
labelH2Sppm.setFont(fontlabel);
labelMediah = new JLabel("Media Ora Precedente:");
labelMediah.setFont(fontlabel);
labelMediag = new JLabel("Media Giorno Precedente:");
labelMediag.setFont(fontlabel);
labelppm = new JLabel(" ppm ");
labelppm.setFont(fontlabel);
labelmhppm = new JLabel(" ppm ");
labelmhppm.setFont(fontlabel);
labelmgppm = new JLabel(" ppm ");
labelmgppm.setFont(fontlabel);
// fine Label
//Text Field
jTextFieldppm = new javax.swing.JTextField(5);
jTextFieldppm.setEditable(false);
jTextFieldppm.setFont(fontlabel);
jTextFieldMediag = new javax.swing.JTextField(5);
jTextFieldMediag.setEditable(false);
jTextFieldMediag.setFont(fontlabel);
jTextFieldMediah = new javax.swing.JTextField();
jTextFieldMediah.setEditable(false);
jTextFieldMediah.setFont(fontlabel);
combo_stop = new JComboBox();
combo_stop.addItem(" ");
combo_stop.addItem("Avvio-Spegnimento-Fermo");
combo_stop.addItem("Manutenzione-Calibrazione");
combo_stop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
item_combo_stop =((JComboBox)e.getSource()).getSelectedIndex();
switch (item_combo_stop){
case 0:
break;
case 1:
break;
case 2:
break;
}
}
});
StopButton = new JButton("Invalida Dati");
StopButton.addActionListener(this);
RiprendiButton = new JButton("Ripristina Validazione");
RiprendiButton.addActionListener(this);
labelStop = new JLabel(" DATI INVALIDATI! ");
labelStop.setForeground(rosso);
labelStop.setFont(fontlabelBold);
labelStop.setVisible(false);
labelAttenzione = new JLabel("SUPERAMENTO SOGLIA DI ATTENZIONE! ");
labelAttenzione.setForeground(blu);
labelAttenzione.setFont(fontlabelBold);
labelAttenzione.setVisible(false);
labelAllarme = new JLabel(" SUPERAMENTO SOGLIA DI ALLARME! ");
labelAllarme.setForeground(rosso);
labelAllarme.setFont(fontlabelBold);
labelAllarme.setVisible(false);
labelNastro = new JLabel(" ATTENZIONE NASTRO INTERROTTO! ");
labelNastro.setForeground(rosso);
labelNastro.setFont(fontlabelBold);
labelNastro.setVisible(false);
// FINE Text Field
pannello_misure = new JLabel(new ImageIcon("C://Programmi/images/
pannello.gif"));
//PANEL
JPanel Panel_principale = new JPanel();
Panel_principale.setPreferredSize (new Dimension
(screenSize.width-10, screenSize.height-65));
Panel_principale.setLayout (null);
Panel_principale.add (menubar);
Panel_principale.add (timeField);
// Panel_principale.add (labelH2Sperc);
Panel_principale.add (labelH2Sppm);
Panel_principale.add (labelMediah);
Panel_principale.add (labelMediag);
// Panel_principale.add (jTextField1);
Panel_principale.add (jTextFieldppm);
Panel_principale.add (jTextFieldMediah);
Panel_principale.add (jTextFieldMediag);
// Panel_principale.add (labelperc);
Panel_principale.add (labelppm);
Panel_principale.add (labelmhppm);
Panel_principale.add (labelmgppm);
Panel_principale.add (pannello_misure);
Panel_principale.add (combo_stop);
Panel_principale.add (StopButton);
Panel_principale.add (RiprendiButton);
Panel_principale.add (labelStop);
Panel_principale.add (labelAttenzione);
Panel_principale.add (labelAllarme);
Panel_principale.add (labelNastro);
menubar.setBounds (0, 5, screenSize.width, 25);
timeField.setBounds (210, 180, 300, 25);
labelAttenzione.setBounds (168, 240, 400, 25);
labelAttenzione.setVisible(false);
labelAllarme.setBounds (168, 240, 400, 25);
labelAllarme.setVisible(false);
labelNastro.setBounds (168, 200, 400, 25);
labelNastro.setVisible(false);
labelH2Sppm.setBounds (170, 270, 200, 25);
jTextFieldppm.setBounds (350, 270, 100, 25);
labelppm.setBounds (450, 270, 150, 25);
labelMediah.setBounds (170, 300, 200, 25);
jTextFieldMediah.setBounds (350, 300, 100, 25);
labelmhppm.setBounds (450, 300, 150, 25);
labelMediag.setBounds (170, 330, 200, 25);
jTextFieldMediag.setBounds (350, 330, 100, 25);
labelmgppm.setBounds (450, 330, 150, 25);
pannello_misure.setBounds (80, 60, 500, 500);
combo_stop.setBounds (187, 380, 153, 25);
StopButton.setBounds (344, 380, 137, 25);
RiprendiButton.setBounds (344, 380, 137, 25);
RiprendiButton.setVisible(false);
labelStop.setBounds (230, 410, 200, 25);
labelStop.setVisible(false);
//FRAME
f = new JFrame ("TK Data");
f.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
f.getContentPane().add (Panel_principale);
f.pack();
f.setVisible (false);
// ********* FINE FRAME PRINCIPALE ***************
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{ System.exit(0);
}
});
}
// **************** ASCOLTATORE ***************
public void actionPerformed(ActionEvent ae) {
String cmd = ae.getActionCommand();
if (OK.equals(cmd)) { //Process the password.
string_utente = jTextField_utente.getText();
string_pw = passwordField.getText();
string_pw_db="guest";
if (string_pw.equals(string_pw_db)) {
System.out.println(""+ day + "-" + mese + "-" + anno + " Ore: "
+ h + ":" + m + ":" + s+" - Utente Autorizzato");
frame_login.setVisible(false);
f.setVisible(true);
}else {
System.out.println(""+ day + "-" + mese + "-" + anno + " Ore: "
+ h + ":" + m + ":" + s+" - Utente NON Autorizzato");
JOptionPane.showMessageDialog(null, "Utente non Autorizzato",
"Errore", JOptionPane.ERROR_MESSAGE);
}
System.gc();
System.runFinalization();
System.gc();
}
if( ae.getSource().equals(simpleItem5)){
f.setVisible(false);
frame_login.setVisible(true);
}
if( ae.getSource().equals(simpleItem2)){
System.exit(0);
}
if( ae.getSource().equals(simpleItem)){
// **************** Inizio interfaccia impostazioni Validazione
********************
// imposta il Look&Feel di sistema
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
labelVmin = new JLabel(" Valore elementare minimo : ");
labelVmax = new JLabel(" Valore elemetare massimo : ");
labelSmax = new JLabel(" Scarto massimo misura precedente : ");
labelScarto_min_ora = new JLabel(" Valore minimo scarto orario :
");
labelScarto_MAX_ora = new JLabel(" Valore massimo scarto orario :
");
labelMedia_h_min = new JLabel(" Valore medio orario minimo : ");
labelMedia_h_max = new JLabel(" Valore medio orario massimo : ");
labelValore_attenzione = new JLabel(" Valore di attenzione : ");
labelValore_limite = new JLabel(" Valore di allarme : ");
labelppm1 = new JLabel(" ppm ");
labelppm2 = new JLabel(" ppm ");
labelppm3 = new JLabel(" ppm ");
labelppm4 = new JLabel(" ppm ");
labelppm5 = new JLabel(" ppm ");
labelppm6 = new JLabel(" ppm ");
labelppm7 = new JLabel(" ppm ");
labelppm8 = new JLabel(" ppm ");
labelppm9 = new JLabel(" ppm ");
jTextFieldVmin = new javax.swing.JTextField();
jTextFieldVmin.setSize(20,100);
jTextFieldVmax = new javax.swing.JTextField();
jTextFieldSmax = new javax.swing.JTextField();
jTextFieldScarto_min_ora = new javax.swing.JTextField();
jTextFieldScarto_MAX_ora = new javax.swing.JTextField();
jTextFieldMedia_h_min = new javax.swing.JTextField();
jTextFieldMedia_h_max = new javax.swing.JTextField();
jTextFieldValore_limite = new javax.swing.JTextField();
jTextFieldValore_attenzione = new javax.swing.JTextField();
jTextFieldVmin.setEditable(false);
jTextFieldVmax.setEditable(false);
jTextFieldSmax.setEditable(false);
jTextFieldScarto_min_ora.setEditable(false);
jTextFieldScarto_MAX_ora.setEditable(false);
jTextFieldMedia_h_min.setEditable(false);
jTextFieldMedia_h_max.setEditable(false);
jTextFieldValore_limite.setEditable(false);
jTextFieldValore_attenzione.setEditable(false);
// CONTROLLO PASSWORD DI AMMINISTRATORE
if (string_pw.equals("pw")){
jTextFieldVmin.setEditable(true);
jTextFieldVmax.setEditable(true);
jTextFieldSmax.setEditable(true);
jTextFieldScarto_min_ora.setEditable(true);
jTextFieldScarto_MAX_ora.setEditable(true);
jTextFieldMedia_h_min.setEditable(true);
jTextFieldMedia_h_max.setEditable(true);
jTextFieldValore_limite.setEditable(true);
jTextFieldValore_attenzione.setEditable(true);
}
try
{
}
catch(Exception e) {
System.out.println("errore:"+e);
}
// Primo Componente
JTextField textField = new JTextField("Premi OK");
textField.setEditable(false);
// Secondo Componente
JLabel labelIcon = new JLabel(new ImageIcon("img.gif"));
labelIcon.setBorder(BorderFactory.createLineBorder(Color.black));
// Terzo Componente
okButton = new JButton("OK");
okButton.addActionListener(this);
// Quarto Componente
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(this);
// Pannello Time
JPanel PanelTime = new JPanel();
PanelTime.setLayout(new GridLayout(1,0));
PanelTime.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
PanelTime.add(labelVmin);
PanelTime.add(jTextFieldVmin);
PanelTime.add(labelppm1);
// Pannello 2
JPanel Panel2 = new JPanel();
Panel2.setLayout(new GridLayout(1,0));
Panel2.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel2.add(labelVmax);
Panel2.add(jTextFieldVmax);
Panel2.add(labelppm2);
// Pannello 3
JPanel Panel3 = new JPanel();
Panel3.setLayout(new GridLayout(1,0));
Panel3.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel3.add(labelSmax);
Panel3.add(jTextFieldSmax);
Panel3.add(labelppm3);
// Pannello 4
JPanel Panel4 = new JPanel();
Panel4.setLayout(new GridLayout(1,0));
Panel4.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel4.add(labelScarto_min_ora);
Panel4.add(jTextFieldScarto_min_ora);
Panel4.add(labelppm4);
// Pannello 5
JPanel Panel5 = new JPanel();
Panel5.setLayout(new GridLayout(1,0));
Panel5.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel5.add(labelScarto_MAX_ora);
Panel5.add(jTextFieldScarto_MAX_ora);
Panel5.add(labelppm5);
// Pannello 6
JPanel Panel6 = new JPanel();
Panel6.setLayout(new GridLayout(1,0));
Panel6.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel6.add(labelMedia_h_min );
Panel6.add(jTextFieldMedia_h_min );
Panel6.add(labelppm6);
// Pannello 7
JPanel Panel7 = new JPanel();
Panel7.setLayout(new GridLayout(1,0));
Panel7.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel7.add(labelMedia_h_max );
Panel7.add(jTextFieldMedia_h_max );
Panel7.add(labelppm7);
// Pannello 8
JPanel Panel8 = new JPanel();
Panel8.setLayout(new GridLayout(1,0));
Panel8.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel8.add(labelValore_attenzione);
Panel8.add(jTextFieldValore_attenzione );
Panel8.add(labelppm8);
// Pannello 9
JPanel Panel9 = new JPanel();
Panel9.setLayout(new GridLayout(1,0));
Panel9.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel9.add(labelValore_limite );
Panel9.add(jTextFieldValore_limite );
Panel9.add(labelppm9);
// Pannello SOUTH
JPanel southPanel = new JPanel();
southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
southPanel.add(cancelButton);
southPanel.add(okButton);
// Top Level Container
fimp = new JFrame("Impostazioni Validazione");
fimp.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fimp.getContentPane().setLayout(new GridLayout(0,1));
fimp.getContentPane().add(PanelTime);
fimp.getContentPane().add(Panel2);
fimp.getContentPane().add(Panel3);
fimp.getContentPane().add(Panel4);
fimp.getContentPane().add(Panel5);
fimp.getContentPane().add(Panel6);
fimp.getContentPane().add(Panel7);
fimp.getContentPane().add(Panel8);
fimp.getContentPane().add(Panel9);
fimp.getContentPane().add(southPanel);
fimp.pack();
fimp.show();
fimp.setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
}
});
System.gc();
System.runFinalization();
System.gc();
}
if( ae.getSource().equals(StopButton)){
try {
switch (item_combo_stop){
case 0:
JOptionPane.showMessageDialog(null, "Scegliere una motivazione
per la invalidazione dei dati!", "Errore", JOptionPane.ERROR_MESSAGE);
break;
case 1:
validazione = "F";
Flag_validazione =1;
labelStop.setVisible(true);
StopButton.setVisible(false);
RiprendiButton.setVisible(true);
System.out.println(""+ day + "-" + mese + "-" + anno + " Ore: "
+ h + ":" + m + ":" + s+" DATI INVALIDATI");
f.repaint();
break;
case 2:
validazione = "M";
Flag_validazione =2;
labelStop.setVisible(true);
StopButton.setVisible(false);
RiprendiButton.setVisible(true);
System.out.println(""+ day + "-" + mese + "-" + anno + " Ore: "
+ h + ":" + m + ":" + s+" DATI INVALIDATI");
f.repaint();
break;
}
} catch (Exception ex) {}
}
if( ae.getSource().equals(RiprendiButton)){
try {
System.out.println(""+ day + "-" + mese + "-" + anno + " Ore: "
+ h + ":" + m + ":" + s+" VALIDAZIONE RIPRISTINATA");
Flag_validazione=0;
StopButton.setVisible(true);
RiprendiButton.setVisible(false);
labelStop.setVisible(false);
//acquisisci_misura = true;
f.repaint();
} catch (Exception ex) {}
}
if( ae.getSource().equals(okButton)){
try {
stringVmin=jTextFieldVmin.getText();
stringVmax=jTextFieldVmax.getText();
stringSmax=jTextFieldSmax.getText();
stringScarto_min_ora=jTextFieldScarto_min_ora.getText();
stringScarto_MAX_ora=jTextFieldScarto_MAX_ora.getText();
stringMedia_h_min=jTextFieldMedia_h_min.getText();
stringMedia_h_max=jTextFieldMedia_h_max.getText();
stringValore_attenzione=jTextFieldValore_attenzione.getText();
stringValore_limite=jTextFieldValore_limite.getText();
fimp.setVisible(false);
f.repaint();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("formato errato: usare il . per i decimali");
}
}
if( ae.getSource().equals(cancelButton)){
fimp.setVisible(false);
f.repaint();
}
// ********************* Fine interfaccia impostazioni
if( ae.getSource().equals(simpleItem3)){
// **************** Inizio interfaccia impostazioni Comunicazione
********************
// imposta il Look&Feel di sistema
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
label_Comm_Port = new JLabel(" Porta Seriale : ");
label_Baud_Rate = new JLabel(" Baud Rate : ");
label_Data_Bits = new JLabel(" Data Bits : ");
label_Parity = new JLabel(" Parity : ");
label_Stop_Bits = new JLabel(" Stop Bits : ");
label_Controllo_allarmi= new JLabel(" Controllo Allarmi : ");
jTextField_Comm_Port = new javax.swing.JTextField();
jTextField_Baud_Rate = new javax.swing.JTextField();
jTextField_Data_Bits = new javax.swing.JTextField();
jTextField_Parity = new javax.swing.JTextField();
jTextField_Stop_Bits = new javax.swing.JTextField();
jTextField_Controllo_allarmi = new javax.swing.JTextField();
jTextField_Comm_Port.setEditable(false);
jTextField_Baud_Rate.setEditable(false);
jTextField_Data_Bits.setEditable(false);
jTextField_Parity.setEditable(false);
jTextField_Stop_Bits.setEditable(false);
jTextField_Controllo_allarmi.setEditable(false);
// CONTROLLO PASSWORD DI AMMINISTRATORE
if (string_pw.equals("pw")){
jTextField_Comm_Port.setEditable(true);
jTextField_Baud_Rate.setEditable(true);
jTextField_Data_Bits.setEditable(true);
jTextField_Parity.setEditable(true);
jTextField_Stop_Bits.setEditable(true);
jTextField_Controllo_allarmi.setEditable(true);
}
try
{
}
catch(Exception e) {
System.out.println("errore:"+e);
}
// Bottone OK
okButton_comm = new JButton("OK");
okButton_comm.addActionListener(this);
// Bottone Cancel
cancelButton_comm = new JButton("Cancel");
cancelButton_comm.addActionListener(this);
// Pannello 1
JPanel Panel1 = new JPanel();
Panel1.setLayout(new GridLayout(1,0));
Panel1.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel1.add(label_Comm_Port);
Panel1.add(jTextField_Comm_Port);
// Pannello 2
JPanel Panel2 = new JPanel();
Panel2.setLayout(new GridLayout(1,0));
Panel2.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel2.add(label_Baud_Rate);
Panel2.add(jTextField_Baud_Rate);
// Pannello 3
JPanel Panel3 = new JPanel();
Panel3.setLayout(new GridLayout(1,0));
Panel3.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel3.add(label_Data_Bits);
Panel3.add(jTextField_Data_Bits);
// Pannello 4
JPanel Panel4 = new JPanel();
Panel4.setLayout(new GridLayout(1,0));
Panel4.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel4.add(label_Parity);
Panel4.add(jTextField_Parity);
// Pannello 5
JPanel Panel5 = new JPanel();
Panel5.setLayout(new GridLayout(1,0));
Panel5.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel5.add(label_Stop_Bits);
Panel5.add(jTextField_Stop_Bits);
// Pannello 6
JPanel Panel6 = new JPanel();
Panel6.setLayout(new GridLayout(1,0));
Panel6.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel6.add(label_Controllo_allarmi);
Panel6.add(jTextField_Controllo_allarmi);
// Pannello SOUTH
JPanel southPanel = new JPanel();
southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
southPanel.add(cancelButton_comm);
southPanel.add(okButton_comm);
// Top Level Container
fimp_comm = new JFrame("Impostazioni Comunicazioni");
fimp_comm.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fimp_comm.getContentPane().setLayout(new GridLayout(0,1));
fimp_comm.getContentPane().add(Panel1);
fimp_comm.getContentPane().add(Panel2);
fimp_comm.getContentPane().add(Panel3);
fimp_comm.getContentPane().add(Panel4);
fimp_comm.getContentPane().add(Panel5);
fimp_comm.getContentPane().add(Panel6);
fimp_comm.getContentPane().add(southPanel);
fimp_comm.pack();
fimp_comm.show();
fimp_comm.setVisible(true);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
}
});
System.gc();
System.runFinalization();
System.gc();
}
if( ae.getSource().equals(okButton_comm)){
try {
string_Comm_Port=jTextField_Comm_Port.getText();
string_Baud_Rate=jTextField_Baud_Rate.getText();
string_Data_Bits=jTextField_Data_Bits.getText();
string_Parity=jTextField_Parity.getText();
string_Stop_Bits=jTextField_Stop_Bits.getText();
string_Controllo_allarmi=jTextField_Controllo_allarmi.getText();
fimp_comm.setVisible(false);
f.repaint();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("errore inserimento dati");
}
System.gc();
System.runFinalization();
System.gc();
}
if( ae.getSource().equals(cancelButton_comm)){
fimp_comm.setVisible(false);
f.repaint();
}
if( ae.getSource().equals(simpleItem4)){
// **************** Inizio interfaccia impostazioni Informazioni
********************
// imposta il Look&Feel di sistema
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
labelIconEBC = new JLabel(new ImageIcon("C:/Programmi/GC_Data/
images/logo_200x68.gif"));
JLabel labelIconENI = new JLabel(new ImageIcon("Logo.bmp"));
label_Version = new JLabel(" Versione 3.0");
Area_info = new JTextArea (" TXT");
Area_info.setBackground(grigio);
Area_info.setEditable(false);
// Bottone OK
okButton_info = new JButton("OK");
okButton_info.addActionListener(this);
//PANEL
JPanel Panel_info = new JPanel();
Panel_info.setPreferredSize (new Dimension (255, 400));
Panel_info.setLayout (null);
Panel_info.add (label_Version);
Panel_info.add (labelIconEBC);
//Panel_info.add (label_Sviluppato);
Panel_info.add (Area_info);
Panel_info.add (okButton_info);
label_Version.setBounds (10, 10, 600, 20);
labelIconEBC.setBounds (10, 30, 200, 68);
// label_Sviluppato.setBounds (40, 100, 300, 25);
Area_info.setBounds (15, 100, 230, 160);
okButton_info.setBounds (83, 300, 80, 25);
// Top Level Container
finfo = new JFrame("Informazioni");
finfo.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
finfo.getContentPane().add(Panel_info);
finfo.pack();
finfo.setVisible(true);
System.gc();
System.runFinalization();
System.gc();
}
if( ae.getSource().equals(simpleItem7)){
// **************** Inizio interfaccia impostazioni Licenza
********************
// imposta il Look&Feel di sistema
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
area_licenza = new TextArea ();
area_licenza.setBackground(grigio);
area_licenza.setEditable(false);
label_Version = new JLabel(" TK Data Versione 3.0");
labelIconEBC = new JLabel(new ImageIcon("C:/Programmi/GC_Data/
images/logo_ebc200x68.gif"));
okButton_licenza = new JButton("OK");
okButton_licenza.addActionListener(this);
label_scadenza_licenza = new JLabel(" Scadenza licenza: ");
//jTextField_scadenza_licenza =
//PANEL
JPanel Panel_licenza = new JPanel();
Panel_licenza.setPreferredSize (new Dimension (800, 590));
Panel_licenza.setLayout (null);
Panel_licenza.add (area_licenza);
Panel_licenza.add (labelIconEBC);
Panel_licenza.add (label_Version);
Panel_licenza.add (okButton_licenza);
label_Version.setBounds (10, 10, 200, 20);
labelIconEBC.setBounds (10, 30, 200, 68);
area_licenza.setBounds (0, 105, 798, 445);
okButton_licenza.setBounds (360, 565, 80, 25);
flicenza = new JFrame("Licenza Software");
flicenza.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
flicenza.getContentPane().add(Panel_licenza);
flicenza.pack();
flicenza.setVisible(true);
System.gc();
System.runFinalization();
System.gc();
}
if( ae.getSource().equals(okButton_licenza)){
flicenza.setVisible(false);
f.repaint();
}
if( ae.getSource().equals(okButton_info)){
finfo.setVisible(false);
f.repaint();
}
if( ae.getSource().equals(simpleItem6)){
// **************** Inizio interfaccia Stampa ********************
// imposta il Look&Feel di sistema
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e) {}
label_data_da_stampare = new JLabel ("Scegli il giorno: ");
scelta_data = new JDateChooser();
label_tipo_misura = new JLabel ("Tipo misura: ");
combo_misura = new JComboBox();
combo_misura.addItem(" ");
combo_misura.addItem("Misure elementari");
combo_misura.addItem("Medie orarie del giorno");
combo_misura.addItem("Media mensile e giornaliere");
combo_misura.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
item_combo =((JComboBox)e.getSource()).getSelectedIndex();
switch (item_combo){
case 1:
misura_da_stampare_combo ="m";
nome_file_jrxml ="C:/Programmi/GC_Data/rep_mis_el";
break;
case 2:
misura_da_stampare_combo ="h";
nome_file_jrxml ="C:/Programmi/GC_Data/rep_med_h";
break;
case 3:
misura_da_stampare_combo ="g";
nome_file_jrxml ="C:/Programmi/GC_Data/rep_med_g";
break;
}
label_report
=((JComboBox)e.getSource()).getSelectedItem().toString()+" H2S";
}
});
// Bottone Stampa
stampaButton = new JButton("Stampa");
stampaButton.addActionListener(this);
// Pannello 1
JPanel Panel1 = new JPanel();
Panel1.setLayout(new GridLayout(1,0));
Panel1.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel1.add(label_data_da_stampare);
Panel1.add(scelta_data);
JPanel Panel2 = new JPanel();
Panel2.setLayout(new GridLayout(1,0));
Panel2.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel2.add(label_tipo_misura);
Panel2.add(combo_misura);
//Pannello 3
JPanel Panel3 = new JPanel();
Panel3.setLayout(new FlowLayout(FlowLayout.CENTER));
Panel3.setBorder(BorderFactory.createEmptyBorder(10,4,10,4));
Panel3.add(stampaButton);
// Top Level Container
fstampa = new JFrame("Genera report");
fstampa.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
fstampa.getContentPane().setLayout(new GridLayout(0,1));
fstampa.getContentPane().add(Panel1);
fstampa.getContentPane().add(Panel2);
fstampa.getContentPane().add(Panel3);
fstampa.setSize(310,160);
fstampa.setVisible(true);
}
if( ae.getSource().equals(stampaButton)){
try {
fstampa.setVisible(false);
Date now = new Date();
now = scelta_data.getDate();
DateFormat df = DateFormat.getDateInstance();
java.text.SimpleDateFormat dateFormatter =
new java.text.SimpleDateFormat("yyyy-MM-dd");
String_scelta_data = dateFormatter.format(now);
f.repaint();
} catch (java.lang.NullPointerException e) {}
}
System.gc();
System.runFinalization();
System.gc();
}
}
</interface class CODE>