Как я могу получить значение Сетевой счетчик для включения в мою Основную цель JButton ?Я делал что-то вроде этого:
Main.java:
package demo;
import java.awt.BorderLayout;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JWindow;
public class Main extends JWindow
{
private static JButton goal = new JButton("old");
private static JWindow j;
private static Process application;
public Main()
{
this.setLayout (new BorderLayout ());
this.setVisible(true);
this.add(goal,BorderLayout.NORTH);
}
public static void main(String[] args)
{
j = new Main();
j.setVisible(true);
try {
application = new Process();
application.start();
// <<<<< Here i want to see the counter, from network.java >>>>>
} catch (Exception ex) {
}
}
}
Process.java
package demo;
import java.util.Vector;
public class Process extends Thread
{
public Network alert;
public Vector listenerList;
private boolean running;
public Process() throws Exception
{
listenerList = new Vector();
alert = new Network();
addNetworkListener(alert);
this.running = true;
}
public void addNetworkListener(Network ls)
{
listenerList.addElement(ls);
}
public void run()
{
System.out.println("Starting..");
try {
while(running)
{
System.out.println("running...");
FireEvent();
}
} catch (Exception ex) {
//
}
}
private void FireEvent()
{
//System.exit(0);
alert.Registered();
}
}
Network.java
package demo;
public class Network implements NetworkListener
{
public int counter = 0 ;
public void Registered()
{
System.out.println("network: " + counter);
counter++;
if (counter>40) System.exit(0);
}
}
NetworkListener.java
package demo;
public interface NetworkListener
{
public void Registered();
}