Java Server Monitoring Frame
Code:
/*
* ===============================
* Class Details:
* ===============================
* Name: MonitorFrame.java
* Package: net.sf.odinms.gui
* Created By: Zygon
* Version: 1
*/
package net.sf.odinms.gui;
import java.awt.*;
import javax.swing.*;
public class MonitorFrame extends JFrame implements Runnable {
public static Box ct1 = Box.createVerticalBox(), ct2 = Box.createVerticalBox();
private JLabel status = new JLabel(), clients = new JLabel();
private JTabbedPane tp = new JTabbedPane();
private JTextArea eta = new JTextArea(10, 10);
private Font f = new Font(Font.MONOSPACED, Font.ITALIC, 20);
private String servername;
private MonitorFrame() {}
public MonitorFrame(String name) {
servername = name;
registerFrame();
}
private void registerFrame() {
setVisible(true);
setSize(350, 350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle(servername + " - Server Monitoring Frame");
setOnline(true);
setConnectedClients(0);
addErrorPane();
addTabs();
update();
}
private void update() {
Thread t = new Thread(this);
t.start();
}
private void addTabs() {
tp.addTab("Status", null, ct1, "Status of your server is displayed here.");
tp.addTab("Errors", null, ct2, "Exceptions thrown by your server are displayed here.");
this.add(tp);
}
private void addErrorPane() {
JScrollPane ep = new JScrollPane(eta, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ct2.add(ep);
}
public void setOnline(boolean cond) {
if (cond == true) {
status.setText("Online");
status.setForeground(Color.GREEN);
status.setFont(f);
ct1.add(status);
} else {
status.setText("Offline");
status.setForeground(Color.RED);
status.setFont(f);
ct1.add(status);
}
}
public void setConnectedClients(int num) {
clients.setText("Connected Clients: " + Integer.toString(num));
clients.setFont(f);
ct1.add(clients);
}
public void addError(String error) {
eta.append(error);
eta.append("\n");
}
public void run() {
while (true) {
tp.repaint();
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Here's a SS:
http://i194.photobucket.com/albums/z...xmaster/ss.png
This is mainly to make things look a little nicer. You may edit it anyway you wish. (I was just using a random server name for the title of the JFrame.)
Re: Java Server Monitoring Frame
awesome release! i like it
gonna use this.
Merry christmas. (belated)
Re: Java Server Monitoring Frame
The gui is perfect you dont have to wast eyour life editing. Its not like anyone else is going to see it