abstract class Trial implements ClassLoadingMXBean, ThreadMXBean {
public static void tri() {


ClassLoadingMXBean classmxbean = ManagementFactory.getClassLoadingMXBean();
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
MemoryMXBean memorymxbean = ManagementFactory.getMemoryMXBean();
OperatingSystemMXBean osmxbean = ManagementFactory.getOperatingSystemMXBean();
List<GarbageCollectorMXBean> gcmxbean = ManagementFactory.getGarbageCollectorMXBeans();


int load_class_cnt = classmxbean.getLoadedClassCount();
long unloaded_class_cnt = classmxbean.getUnloadedClassCount();
long total_load_class_cnt = classmxbean.getTotalLoadedClassCount();

// System.out.println("The number of classes loaded are : " + load_class_cnt);
// System.out.println("The number of classes unloaded are : " + unloaded_class_cnt);
// System.out.println("The total number of classes loaded are : " + total_load_class_cnt);

int thread_count = threadmxbean.getThreadCount();
int peak_thread_count = threadmxbean.getPeakThreadCount();
int daemon_thread_count = threadmxbean.getDaemonThreadCount();
long thread_cpu_time = threadmxbean.getCurrentThreadCpuTime();
// System.out.println("Thread count : " + thread_count);
// System.out.println("Peak thread count : " + peak_thread_count);
// System.out.println("Daemon thread count : " + daemon_thread_count);
// System.out.println("Current thread CPU time : " + thread_cpu_time);

MemoryUsage heap_usage = memorymxbean.getHeapMemoryUsage();
MemoryUsage non_heap_usage = memorymxbean.getNonHeapMemoryUsage();
// System.out.println("Heap memory Usage : " + heap_usage);
// System.out.println("Non-heap memory Usage : " + non_heap_usage);

int os_processors = osmxbean.getAvailableProcessors();
String os_name = osmxbean.getName();
String os_ver = osmxbean.getVersion();
// System.out.println("Number of processors available : " + os_processors);
// System.out.println("OS name : " + os_name);
// System.out.println("OS version : " + os_ver);

System.gc();
long coll_count = gcmxbean.get(1).getCollectionCount();
long coll_time = gcmxbean.get(1).getCollectionTime();
// System.out.println("Collection Count : " + coll_count);
// System.out.println("Collection Time : " + coll_time);
}
}

abstract class Trail1 extends Trial {
public static void tri1() {

JFrame frme = new JFrame();


JLabel cls_load = new JLabel();
JLabel cls_unload= new JLabel();
JLabel thrd_cnt = new JLabel();
JLabel peak_thrd_cnt = new JLabel();
JLabel demon_thrd_cnt = new JLabel();
JLabel os_nme = new JLabel();
JLabel os_vr = new JLabel();
JLabel no_proc = new JLabel();
JLabel gc_cnt = new JLabel();
JLabel gc_tme = new JLabel();
JLabel hp_usge = new JLabel();
JLabel nhp_usge = new JLabel();

JTextField cls_ld = new JTextField();
JTextField cls_unld = new JTextField();
JTextField thrd_ct = new JTextField();
JTextField pk_thrd_ct = new JTextField();
JTextField demon_thrd_ct = new JTextField();
JTextField os_n = new JTextField();
JTextField os_v = new JTextField();
JTextField no_prc = new JTextField();
JTextField gc_ct = new JTextField();
JTextField gc_time = new JTextField();
JTextField hp_usg = new JTextField();
JTextField nhp_usg = new JTextField();


cls_load.setText("Classes Loaded");
cls_load.setBounds(100,100,200,50);
cls_load.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

cls_unload.setText("Classes Unloaded");
cls_unload.setBounds(100,140,200,50);
cls_unload.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

thrd_cnt.setText("Thread Count");
thrd_cnt.setBounds(100,180,200,50);
thrd_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

peak_thrd_cnt.setText("Peak Thread Count");
peak_thrd_cnt.setBounds(100,220,250,50);
peak_thrd_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

demon_thrd_cnt.setText("Daemon Thread Count");
demon_thrd_cnt.setBounds(100,260,250,50);
demon_thrd_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

os_nme.setText("OS name");
os_nme.setBounds(100,300,200,50);
os_nme.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

os_vr.setText("OS version");
os_vr.setBounds(100,340,200,50);
os_vr.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

no_proc.setText("Number of processors");
no_proc.setBounds(100,380,300,50);
no_proc.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

gc_cnt.setText("Garbage Collection Count");
gc_cnt.setBounds(100,420,350,50);
gc_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

gc_tme.setText("Garbage Collection Time");
gc_tme.setBounds(100,460,350,50);
gc_tme.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

hp_usge.setText("Heap Memory Usage");
hp_usge.setBounds(100,500,300,50);
hp_usge.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

nhp_usge.setText("Non Heap Memory Usage");
nhp_usge.setBounds(100,540,400,50);
nhp_usge.setFont(new java.awt.Font("Palatino Linotype", 1, 20));


cls_ld.setBounds(500,100,100,30);
cls_ld.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

cls_unld.setBounds(500,140,100,30);
cls_unld.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

thrd_ct.setBounds(500,180,100,30);
thrd_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

pk_thrd_ct.setBounds(500,220,100,30);
pk_thrd_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

demon_thrd_ct.setBounds(500,260,100,30);
demon_thrd_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

os_n.setBounds(500,300,200,30);
os_n.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

os_v.setBounds(500,340,100,30);
os_v.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

no_prc.setBounds(500,380,100,30);
no_prc.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

gc_ct.setBounds(500,420,100,30);
gc_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

gc_time.setBounds(500,460,100,30);
gc_time.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

hp_usg.setBounds(500,500,100,30);
hp_usg.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

nhp_usg.setBounds(500,540,100,30);
nhp_usg.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

frme.setBackground(new Color(204, 204, 204));
frme.getContentPane().add(cls_load);
frme.getContentPane().add(cls_unload);
frme.getContentPane().add(thrd_cnt);
frme.getContentPane().add(peak_thrd_cnt);
frme.getContentPane().add(demon_thrd_cnt);
frme.getContentPane().add(os_nme);
frme.getContentPane().add(os_vr);
frme.getContentPane().add(no_proc);
frme.getContentPane().add(gc_cnt);
frme.getContentPane().add(gc_tme);
frme.getContentPane().add(hp_usge);
frme.getContentPane().add(nhp_usge);

frme.getContentPane().add(cls_ld);
frme.getContentPane().add(cls_unld);
frme.getContentPane().add(thrd_ct);
frme.getContentPane().add(pk_thrd_ct);
frme.getContentPane().add(demon_thrd_ct);
frme.getContentPane().add(os_n);
frme.getContentPane().add(os_v);
frme.getContentPane().add(no_prc);
frme.getContentPane().add(gc_ct);
frme.getContentPane().add(gc_time);
frme.getContentPane().add(hp_usg);
frme.getContentPane().add(nhp_usg);



//frme.getContentPane().setSize(new Dimension(600, 400));
frme.setTitle("JVM Monitoring");
frme.setLocation(new Point(0, 0));
frme.setSize(new Dimension(1100, 800));
frme.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frme.setResizable(false);



frme.setVisible(true);
frme.getContentPane().setVisible(true);
frme.validate();
frme.getContentPane().validate();
}
}

This is my entire code...
i want to take the values from the function tri() and use them to set the values of textfields in tri1()...
For ex the load_class_cnt should be retrieved in the tri1() so that i can set the text field to its value...

Please help.....

Recommended Answers

All 3 Replies

abstract class Trial implements ClassLoadingMXBean, ThreadMXBean {
public static void tri() {

ClassLoadingMXBean classmxbean = ManagementFactory.getClassLoadingMXBean();
ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();

int load_class_cnt = classmxbean.getLoadedClassCount();
long unloaded_class_cnt = classmxbean.getUnloadedClassCount();
long total_load_class_cnt = classmxbean.getTotalLoadedClassCount();

int thread_count = threadmxbean.getThreadCount();
int peak_thread_count = threadmxbean.getPeakThreadCount();
int daemon_thread_count = threadmxbean.getDaemonThreadCount();
}
}

abstract class Trail1 extends Trial {
public static void tri1() {

JFrame frme = new JFrame();
JLabel cls_load = new JLabel();
JLabel cls_unload= new JLabel();
JLabel thrd_cnt = new JLabel();
JLabel peak_thrd_cnt = new JLabel();
JLabel demon_thrd_cnt = new JLabel();

JTextField cls_ld = new JTextField();
JTextField cls_unld = new JTextField();
JTextField thrd_ct = new JTextField();
JTextField pk_thrd_ct = new JTextField();
JTextField demon_thrd_ct = new JTextField();

cls_load.setBounds(100,100,200,50);
cls_load.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

cls_unload.setText("Classes Unloaded");
cls_unload.setBounds(100,140,200,50);
cls_unload.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

thrd_cnt.setText("Thread Count");
thrd_cnt.setBounds(100,180,200,50);
thrd_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

peak_thrd_cnt.setText("Peak Thread Count");
peak_thrd_cnt.setBounds(100,220,250,50);
peak_thrd_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

demon_thrd_cnt.setText("Daemon Thread Count");
demon_thrd_cnt.setBounds(100,260,250,50);
demon_thrd_cnt.setFont(new java.awt.Font("Palatino Linotype", 1, 20));

cls_ld.setBounds(500,100,100,30);
cls_ld.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

cls_unld.setBounds(500,140,100,30);
cls_unld.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

thrd_ct.setBounds(500,180,100,30);
thrd_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

pk_thrd_ct.setBounds(500,220,100,30);
pk_thrd_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

demon_thrd_ct.setBounds(500,260,100,30);
demon_thrd_ct.setFont(new java.awt.Font("Palatine Linotype", 1, 20));

frme.setBackground(new Color(204, 204, 204));
frme.getContentPane().add(cls_load);
frme.getContentPane().add(cls_unload);
frme.getContentPane().add(thrd_cnt);
frme.getContentPane().add(peak_thrd_cnt);
frme.getContentPane().add(demon_thrd_cnt);

frme.getContentPane().add(cls_ld);
frme.getContentPane().add(cls_unld);
frme.getContentPane().add(thrd_ct);
frme.getContentPane().add(pk_thrd_ct);
frme.getContentPane().add(demon_thrd_ct);

frme.setTitle("JVM Monitoring");
frme.setLocation(new Point(0, 0));
frme.setSize(new Dimension(1100, 800));
frme.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frme.setResizable(false);
frme.setLayout(new FLowLayout());
frme.getContentPane().setVisible(true);

}
}

Now I hope the code appears much better and small as compared to the earlier one...

Here you see that I have retrieved the values in the class Trial's tri() function.. I want to reflect these values in the JTextfield in the Trail1's tri1() function.. When I try to do this using the setText method, it does not support.. Basically I need to access the variables in Trial class through Trail1() and I am unable to do that..

Can you help please???

That is because the variables you are using to store the values in tri() cannot be used outside that method; they are local variables and can be used only inside that method.
One suggestion is to make your methods non static, and declare the variables that you will store the values outside the methods so they will be global. Then since you are using two different classes you should pass those variables as arguments at the method where you are setting the text.

I have tried my hand at what you suggested and also been able to resolve the problem to some extent...
thanks for the help..

but when i retrieve the values in the class and try to print them in the JTextField, it does not give any ouput..
the text fields remain blank..
Can you see what the problem exactly is..??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.