aliasing

P

palmis

I have 2 problems.

1)my class create a Jframe with a JCombobox in which I can select the
system to monitor.
If I select another system, while monitoring is in course, it stops the
first and starts the most recent selected system monitoring.
I think that the problem is about aliasing of get = new GetClass(); so
that the first and the second get, make reference to the same object
(the second).


2)When I select another system to monitor I wait that it open another
monitoring Jframe with this command
Monitoring mon = new Monitoring();
mon.initComponents();

But appears the only first JFrame monitoring and not two.
Is this another aliasing problem?


Can you help me?
Thanks
Palmis


This is the code


import javax.swing.*;

import com.adventnet.snmp.beans.SnmpTable;
import com.adventnet.snmp.beans.DataException;

import config.LoadProperties;

import java.awt.*;
import java.awt.event.*;

import snmpManager.GetClass;
import Prove.TCPprova;
import snmpManager.GetSetClassCommands;
import tcp.TCPServer;

/*
* Questa classe estende JFrame e costruisce la finestra iniziale
* che consente all'utente di selezionare il sottosistema e far
* partire il suo monitoring.
*/
public class Welcome extends JFrame implements Runnable {

static final long serialVersionUID = 1L;

public static JFrame hello = new JFrame();

// Array di valori che compaiono nel JComboBox
public static String chose[] = { "RIMS A", "RIMS B", "RIMS C", "NLES"
};

public static JComboBox menu = new JComboBox(chose);

public static JPanel panel1 = new JPanel();

public static JButton start = new JButton();

public static JButton exit = new JButton();

public static JLabel text = new JLabel();

// public static GetClass get = new GetClass();

public static GetSetClassCommands gsc;

public static GetClass get;


SnmpTable table;

Thread selfThread = null;

/*
* Questo metodo e' il costruttore della classe
*/
public Welcome() {
}

/*
* Questo metodo viene chiamato automaticamente allo start() del
thread e
* contiene un ciclo infinito
*/
public void run() {
// Costruisce la finestra Monitoring
Monitoring mon = new Monitoring();
mon.initComponents();
while (true) {
if (get.getControl() == true) {
table = new SnmpTable();
get.loadData(table);
}

}
}// Fine metodo run()

/*
* Questo metodo inizializza gli oggetti che compongono la finestra
*/
public void initComponents() {

//Setta alcune proprieta' di JFrame
hello.setBackground(new Color(200, 255, 150));
hello.setTitle("Egnos Information Formatting");
hello.setSize(500, 400);
Container WelcomeContentPane = hello.getContentPane();
WelcomeContentPane.setLayout(new BorderLayout(500, 300));

//Setta alcune proprieta' di JPanel
panel1.setBackground(new Color(200, 255, 150));
panel1.setLayout(null);

//Setta alcune proprieta' di JComboBox e lo aggiunge a JPanel
menu.setBounds(15, 70, 100, 25);
menu.setBackground(new Color(255, 255, 255));
panel1.add(menu);

//Setta alcune proprieta' di JLabel lo aggiunge a JPanel
text.setBounds(15, 8, 400, 50);
text.setText("Selezionare il sottosistema che si desidera
monitorare");
panel1.add(text);

//Setta alcune proprieta' di JButton 'Start' e vi aggiunge un
ActionListener
start.setText("START");
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startActionPerformed(e);
}
});

//Aggiunge JButton 'Start' al pannello e vi setta la posizione in
esso
panel1.add(start);
start.setBounds(15, 180, 80, 25);

//Setta alcune proprieta' di JButton 'Exit' e vi aggiunge un
ActionListener
exit.setText("EXIT");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent g) {
exitActionPerformed(g);
}
});

//Aggiunge JButton 'Exit' al pannello e vi setta la posizione in esso
panel1.add(exit);
exit.setBounds(180, 180, 80, 25);

WelcomeContentPane.add(panel1, BorderLayout.CENTER);

//Posizione JFrame al centro dello schermo
Toolkit tk = Toolkit.getDefaultToolkit();
int xpos = (int) ((tk.getScreenSize().getWidth() / 2) - (hello
.getSize().getWidth() / 2));
int ypos = (int) ((tk.getScreenSize().getHeight() / 2) - (hello
.getSize().getHeight() / 2));
hello.setLocation(xpos, ypos);
hello.show();

}// Fine metodo initComponents()

/*
* Questo metodo determina le azioni da compiere nel momento in cui il
JButton 'Start' viene premuto
*/
private void startActionPerformed(ActionEvent e) {
//Prende il numero del valore selezionato in JComboBox
int scelta = menu.getSelectedIndex();
get = new GetClass();


get.setControl(true);

//A seconda del valore selezionato, setta l'asset
if (scelta == 0) {
get.setAsset("Rims_A");
}
if (scelta == 1) {
get.setAsset("Rims_B");
}
if (scelta == 2) {
get.setAsset("Rims_C");
}
if (scelta == 3) {
get.setAsset("NLES");
}

// Costruisce un oggetto Thread
selfThread = new Thread(Welcome.this);
// start() esegue una inizializzazione speciale per il thread e
chiama
// run()
selfThread.start();
// }


}// Fine metodo startActionPerformed()

/*
* Questo metodo determina le azioni da compiere nel momento in cui il
JButton 'Exit' viene premuto
*/
private void exitActionPerformed(ActionEvent g) {

// Effettua l'exit dall'applicazione
System.exit(0);
}//Fine metodo exitActionPerformed()

/*
* Main dell'applicazione
*/
public static void main(String[] args) {
//Carica le informazioni dal file di configurazione attraverso la
classe LoadProperties
LoadProperties configuration = new LoadProperties();
configuration.load();

//Costruisce la finestra principale
Welcome wel = new Welcome();
wel.initComponents();



}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top