Salve familia, sou iniciante no mundo e tou tentando fazer um programa de monitoramento que ping para varios ips e de acordo com o retorno muda a cor do JPanel criado. Até aqui consegui fazer o teste de ping, porem percebi que o retorno é lento, talvez seja até isso que está implicando com o codigo pois a criacaçao do paineis está rodando tranquilo. segue o codigo:
import javax.swing.;
import java.awt.;
import java.util.ArrayList;
import java.util.Arrays;
public class Screen extends Pingar{
JPanel [][] jPanels = new JPanel[170][100];
JFrame jFrame1 = new JFrame();
JPanel jPanel = new JPanel();
JPanel titulo = new JPanel();
JLabel [][] textip = new JLabel[1700][1000];
public void Painel1(){
jFrame1.setVisible(true);
jFrame1.setTitle(“PINGS”);
jFrame1.setSize(800,6000);
jFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame1.setLocationRelativeTo(null);
Pingar p = new Pingar();
String [] ip = new String[1900];
for(int i = 0 ; i < 170 ; i++){
for (int j = 0 ; j < 30 ; j++){
int z = 10;
if(j < 5){
jPanels[i][j] = new JPanel();
textip[i][j] = new JLabel();
jPanels[i][j].setBackground(Color.red);
jPanels[i][j].setPreferredSize(new Dimension(100,100));
jPanels[i][j].setOpaque(true);
textip[i][j].setFont(new Font("Arial",Font.BOLD,20));
textip[i][j].setText("10.10." + (i+1) + "." + (j+1));
jPanels[i][j].add(textip[i][j]);
jPanel.add(jPanels[i][j]);
}else if (j > 9 && j < 15){
jPanels[i][j] = new JPanel();
textip[i][j] = new JLabel();
jPanels[i][j].setBackground(Color.red);
jPanels[i][j].setPreferredSize(new Dimension(100,100));
jPanels[i][j].setOpaque(true);
textip[i][j].setFont(new Font("Arial",Font.BOLD,20));
textip[i][j].setText("10.10." + (i + 1) + "." + (j+1));
jPanels[i][j].add(textip[i][j]);
jPanel.add(jPanels[i][j]);
}else if (j > 15){
jPanels[i][j] = new JPanel();
textip[i][j] = new JLabel();
jPanels[i][j].setBackground(Color.red);
jPanels[i][j].setPreferredSize(new Dimension(100,100));
jPanels[i][j].setOpaque(true);
textip[i][j].setFont(new Font("Arial",Font.BOLD,20));
textip[i][j].setText("10.10." + (i+1) + "." + 250);
jPanels[i][j].add(textip[i][j]);
jPanel.add(jPanels[i][j]);
break;
}
}
}
jPanel.setLayout(new GridLayout(0,11,10,10));
JScrollPane scrool = new JScrollPane(jPanel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JLabel tituloLabel = new JLabel("PINGTEST");
tituloLabel.setFont(new Font("Arial",Font.BOLD,30));
titulo.add(tituloLabel);
jFrame1.setLayout(new BorderLayout());
jFrame1.add(tituloLabel,BorderLayout.NORTH);
jFrame1.add(scrool,BorderLayout.CENTER);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> new Screen().Painel1());
}
}
import java.net.InetAddress;
public class Pingar {
private String ip;
private final int maxTemp = 10;
public boolean PingTo(String ip) {
try {
InetAddress address = InetAddress.getByName(ip);
return address.isReachable(this.maxTemp);
} catch (Exception e) {
System.out.println(e);
}
return false;
}
//METODOS ESPECIAIS
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
}
Tou precisando desse help. Iniciei a pouco tempo quero só uma luz para dar continuidade. Esses ips são do dominio, são 170 lojas com + - 10 computadores cada.