mas usando a versão
[quote]java version “1.4.2_06”
Java™ 2 Runtime Environment, Standard Edition (build 1.4.2_06-b03)
Java HotSpot™ Client VM (build 1.4.2_06-b03, mixed mode)[/quote]
Essa classe nao compila…
[code]/*
- Created on 12/07/2005 23:50:06
-
@author Jair Priori Minharo Júnior / Administrador
*/
package servidor.telasInternas;
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JEditorPane;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeSelectionModel;
public class MonitorDaRede extends JInternalFrame implements TreeSelectionListener, InternalFrameListener{
static final int xOffset = 50, yOffset= 30;
private static Container contentor;
private static JLabel jlMonitor = new JLabel(“Java Universal Systems Management Server - jUSMS”, JLabel.CENTER);
//VARIAVEIS
private static JPanel networkPanel;
private JEditorPane htmlPane;
public static JTree tree;
private URL indexURL;
private String str_indexURL;
private static boolean DEBUG = false;
private static boolean playWithLineStyle = false;
private static String lineStyle = "Horizontal";
private static boolean useSystemLookAndFeel = false;
private static String nomHost;
public static DefaultMutableTreeNode comp;
public static DefaultMutableTreeNode top;
//PopUP Menu
public static JPopupMenu popupmenu;
public static JMenuItem jpopMI;
public MonitorDaRede(){
super("Monitor da Rede",
false,
false,
false,
true);
setSize(600,500);
setLocation(xOffset, yOffset);
addInternalFrameListener(this);
PopupMenu();
NetworkView();
ServerName();
contentor = getContentPane();
contentor.setLayout(new BorderLayout());
//J2SE 1.4.0_x
contentor.add(NetworkView());
//J2SE 1.5.0_x
// add(NetworkView());
contentor.add(jlMonitor, BorderLayout.PAGE_END);
jlMonitor.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
}
public Component NetworkView(){
networkPanel = new JPanel(new GridLayout(1,0));
top = new DefaultMutableTreeNode("Servidor: " + nomHost);
criaNodes(top);
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addTreeSelectionListener(this);
if (playWithLineStyle){
System.out.println("line style = " + lineStyle);
tree.putClientProperty("JTree.lineStyle", lineStyle);
}
ImageIcon leafIcon = createImageIcon("img/win_logo.png");
ImageIcon server = createImageIcon("img/network.png");
if (leafIcon != null) {
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(leafIcon);
renderer.setClosedIcon(server);
renderer.setOpenIcon(server);
tree.setCellRenderer(renderer);
} else {
System.err.println("Leaf icon missing; using default.");
}
JScrollPane treeView = new JScrollPane(tree);
htmlPane = new JEditorPane();
htmlPane.setEditable(false);
initHelp();
JScrollPane htmlView = new JScrollPane(htmlPane);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(treeView);
splitPane.setRightComponent(htmlView);
splitPane.setEnabled(false);
Dimension minimumSize = new Dimension(150,350);
htmlView.setMinimumSize(minimumSize);
treeView.setMinimumSize(minimumSize);
splitPane.setDividerLocation(150);
splitPane.setPreferredSize(new Dimension(500,600));
return networkPanel.add(splitPane);
}
public void criaNodes(DefaultMutableTreeNode top) {
comp = null;
String dbURL = "jdbc:mysql://localhost/jusms";
Connection c = null;
ResultSet r = null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
c = DriverManager.getConnection(dbURL, "root", "senha");
Statement s = c.createStatement();
r = s.executeQuery("SELECT * FROM rede ORDER BY pc_name");
while (r.next()){
comp = new DefaultMutableTreeNode(new CompInfo(r.getString("pc_name"),r.getString("pc_name")+".html"));
top.add(comp);
}
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e)
{
e.printStackTrace();
} finally
{
try
{
r.close();
c.close();
} catch (SQLException e1)
{
e1.printStackTrace();
}
}
// comp = new DefaultMutableTreeNode(new CompInfo(“JUNIOR”,“JUNIOR.html”));
// top.add(comp);
}
public void valueChanged(TreeSelectionEvent arg0) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf()) {
CompInfo pc = (CompInfo)nodeInfo;
displayURL(pc.pcURL);
if (DEBUG){
System.out.println(pc.pcURL + ": \n ");
}
}else {
displayURL(str_indexURL);
}
if (DEBUG) {
System.out.println(nodeInfo.toString());
}
}
private class CompInfo{
public String compName;
// public URL compURL;
public String pcURL;
public CompInfo(String comp, String filename) {
compName = comp;
pcURL = "file:///C:/jusms/" + filename;
if (pcURL == null) {
System.err.println("Não foi possivel encontrar o arquivo: " + filename);
}
/* compName = comp;
compURL = MonitorDaRede.class.getResource(filename);
if (compURL == null) {
System.err.println("Não foi possivel encontrar o arquivo: " + filename);
}*/
}
public String toString() {
return compName;
}
}
private void initHelp() {
String s = "NetworkIndex.html";
str_indexURL = "file:///C:/jusms/" + s;
if (str_indexURL == null) {
System.err.println("Não foi possivel encontrar o arquivo: " + s);
} else if (DEBUG) {
System.out.println("Página inicial é " + str_indexURL);
}
displayURL(str_indexURL);
/* String s = “NetworkIndex.html”;
indexURL = MonitorDaRede.class.getResource(s);
if (indexURL == null) {
System.err.println("Não foi possivel encontrar o arquivo: " + s);
} else if (DEBUG) {
System.out.println("Página inicial é " + indexURL);
}
displayURL(indexURL);*/
}
// private void displayURL(URL url){
private void displayURL(String url){
try {
if (url != null) {
htmlPane.setPage(url);
} else {
htmlPane.setText(“Página não encontrada”);
}
if (DEBUG) {
System.out.println(“Tentou exibir uma página que nao existe.”);
}
} catch (IOException e) {
System.err.println("Tentou ler uma página com erros: " + url);
System.out.println(e);
}
/* try {
if (url != null) {
htmlPane.setPage(url);
} else {
htmlPane.setText(“Página não encontrada”);
}
if (DEBUG) {
System.out.println(“Tentou exibir uma página que nao existe.”);
}
} catch (IOException e) {
System.err.println("Tentou ler uma página com erros: " + url);
}*/
}
public void internalFrameOpened(InternalFrameEvent arg0) {
InfoSistema.jtaInformacao.setText(InfoSistema.jtaInformacao.getText() + "\n\n" +
"\t---------------------------------------------\n"+
"\t" + "Monitor da Rede 100% Carregado\n" +
"\t---------------------------------------------");
}
public void internalFrameClosing(InternalFrameEvent arg0) {
}
public void internalFrameClosed(InternalFrameEvent arg0) {
}
public void internalFrameIconified(InternalFrameEvent arg0) {
}
public void internalFrameDeiconified(InternalFrameEvent arg0) {
}
public void internalFrameActivated(InternalFrameEvent arg0) {
}
public void internalFrameDeactivated(InternalFrameEvent arg0) {
}
public Component PopupMenu(){
popupmenu = new JPopupMenu("Monitor da Rede");
jpopMI = new JMenuItem("Atualizar");
jpopMI.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
top.removeAllChildren();
criaNodes(top);
tree.updateUI();
}
});
popupmenu.add(jpopMI);
MonitorDaRede.contentor.add(popupmenu);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
return popupmenu;
}
public void processMouseEvent(MouseEvent e) {
if (e.isPopupTrigger()) {
popupmenu.show(e.getComponent(), e.getX(), e.getY());
}
super.processMouseEvent(e);
}
protected static ImageIcon createImageIcon(String path) {
URL imgURL = MonitorDaRede.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
public static String ServerName(){
try {
InetAddress myAddress = InetAddress.getLocalHost();
nomHost = myAddress.getHostName();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return nomHost;
}
}[/code]
Da erro nesta linha:
[code] public Component PopupMenu(){
popupmenu = new JPopupMenu(“Monitor da Rede”);
jpopMI = new JMenuItem(“Atualizar”);
jpopMI.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent evt){
top.removeAllChildren();
criaNodes(top);
tree.updateUI();
}
});
popupmenu.add(jpopMI);
add(popupmenu); <------------AQUI
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
return popupmenu;
}[/code]
Já tentei usar o contentor.add(); ou MonitorDaRede.contentor.add();
Mas não consigo descobrir onde.