Java League of Legends ping checker












2














I'm still a freshman and this one of my first projects I made using Java and Swing.



The program is a simple League of Legends multi-threaded ping checker that pings the server 10 times to get an average ping and determine the max and minimum ranges.



How can I make my code cleaner instead of writing so many if statements? Any suggestions or tips are greatly appreciated.



To check your ping you can download the software here.



import java.awt.Color;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.net.InetAddress;
import java.util.GregorianCalendar;
import java.util.*;

import javax.swing.JProgressBar;
/**
*
* @author User
*/
public class App {


public static void sendPingRequest2(String ipAddress, javax.swing.JTextPane jTextPane1, javax.swing.JTextPane jTextPane2, javax.swing.JTextField jTextField1) {

try {
for (int i = 0; i < 10; i++) {
InetAddress inet = InetAddress.getByName(ipAddress);
long finish = 0;
long start = new GregorianCalendar().getTimeInMillis();
System.out.println("Sending Ping Request to " + ipAddress);
long sum = 0;

List < Long > list = new ArrayList < > ();



if (inet.isReachable(5000)) {

finish = new GregorianCalendar().getTimeInMillis();
long value = finish - start;

list.add(value);
long lowest = Collections.min(list);
System.out.println("value" + lowest);
sum = value + value / 10;
if (value < 250) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.green);
jTextPane2.setForeground(Color.green);
jTextField1.setBackground(Color.green);
} else if (value > 250 || value < 500) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.yellow);
jTextPane2.setBackground(Color.yellow);
jTextField1.setBackground(Color.yellow);

} else {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText(" " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.red);
jTextPane2.setBackground(Color.red);
jTextField1.setBackground(Color.red);
}

} else {
System.out.println(ipAddress + " NOT reachable.");
}
}
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
}

public static void main(String args) {
App m = new App();
NewJFrame jf = new NewJFrame();



}

void sendPingRequest(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}


Gui.java



package selenium;

import java.net.InetAddress;
import java.util.GregorianCalendar;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

/**
*
* @author User



public class NewJFrame extends javax.swing.JFrame {

* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}




private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


constants.java



public enum Constants {
NA ("104.160.131.3"), EUW("104.160.141.3"),EUNE("104.160.142.3"),KOR("104.160.156.1"),LAN("104.160.136.3");

private String ip;

Constants(String ip){
this.ip = ip;
}

public String getIp(){
return ip;
}
}









share|improve this question
























  • Not sure whether this counts as an answer but I think there is strong reason to switch to JavaFX instead of using Swing. See here.
    – Dair
    15 mins ago










  • Also, I haven't used Swing, but it seems part of the reason you should use JavaFX is that it better supports the MVC paradigm. In particular, you can utilize FXML/CSS to design the UI and let the logic be controlled in Java. This isn't particularly in depth since I don't do much Java development, but the general rule of thumb for GUI applications is to not write static UIs in Java/C/etc. and use a markup-esque language to do so instead.
    – Dair
    10 mins ago


















2














I'm still a freshman and this one of my first projects I made using Java and Swing.



The program is a simple League of Legends multi-threaded ping checker that pings the server 10 times to get an average ping and determine the max and minimum ranges.



How can I make my code cleaner instead of writing so many if statements? Any suggestions or tips are greatly appreciated.



To check your ping you can download the software here.



import java.awt.Color;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.net.InetAddress;
import java.util.GregorianCalendar;
import java.util.*;

import javax.swing.JProgressBar;
/**
*
* @author User
*/
public class App {


public static void sendPingRequest2(String ipAddress, javax.swing.JTextPane jTextPane1, javax.swing.JTextPane jTextPane2, javax.swing.JTextField jTextField1) {

try {
for (int i = 0; i < 10; i++) {
InetAddress inet = InetAddress.getByName(ipAddress);
long finish = 0;
long start = new GregorianCalendar().getTimeInMillis();
System.out.println("Sending Ping Request to " + ipAddress);
long sum = 0;

List < Long > list = new ArrayList < > ();



if (inet.isReachable(5000)) {

finish = new GregorianCalendar().getTimeInMillis();
long value = finish - start;

list.add(value);
long lowest = Collections.min(list);
System.out.println("value" + lowest);
sum = value + value / 10;
if (value < 250) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.green);
jTextPane2.setForeground(Color.green);
jTextField1.setBackground(Color.green);
} else if (value > 250 || value < 500) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.yellow);
jTextPane2.setBackground(Color.yellow);
jTextField1.setBackground(Color.yellow);

} else {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText(" " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.red);
jTextPane2.setBackground(Color.red);
jTextField1.setBackground(Color.red);
}

} else {
System.out.println(ipAddress + " NOT reachable.");
}
}
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
}

public static void main(String args) {
App m = new App();
NewJFrame jf = new NewJFrame();



}

void sendPingRequest(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}


Gui.java



package selenium;

import java.net.InetAddress;
import java.util.GregorianCalendar;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

/**
*
* @author User



public class NewJFrame extends javax.swing.JFrame {

* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}




private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


constants.java



public enum Constants {
NA ("104.160.131.3"), EUW("104.160.141.3"),EUNE("104.160.142.3"),KOR("104.160.156.1"),LAN("104.160.136.3");

private String ip;

Constants(String ip){
this.ip = ip;
}

public String getIp(){
return ip;
}
}









share|improve this question
























  • Not sure whether this counts as an answer but I think there is strong reason to switch to JavaFX instead of using Swing. See here.
    – Dair
    15 mins ago










  • Also, I haven't used Swing, but it seems part of the reason you should use JavaFX is that it better supports the MVC paradigm. In particular, you can utilize FXML/CSS to design the UI and let the logic be controlled in Java. This isn't particularly in depth since I don't do much Java development, but the general rule of thumb for GUI applications is to not write static UIs in Java/C/etc. and use a markup-esque language to do so instead.
    – Dair
    10 mins ago
















2












2








2







I'm still a freshman and this one of my first projects I made using Java and Swing.



The program is a simple League of Legends multi-threaded ping checker that pings the server 10 times to get an average ping and determine the max and minimum ranges.



How can I make my code cleaner instead of writing so many if statements? Any suggestions or tips are greatly appreciated.



To check your ping you can download the software here.



import java.awt.Color;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.net.InetAddress;
import java.util.GregorianCalendar;
import java.util.*;

import javax.swing.JProgressBar;
/**
*
* @author User
*/
public class App {


public static void sendPingRequest2(String ipAddress, javax.swing.JTextPane jTextPane1, javax.swing.JTextPane jTextPane2, javax.swing.JTextField jTextField1) {

try {
for (int i = 0; i < 10; i++) {
InetAddress inet = InetAddress.getByName(ipAddress);
long finish = 0;
long start = new GregorianCalendar().getTimeInMillis();
System.out.println("Sending Ping Request to " + ipAddress);
long sum = 0;

List < Long > list = new ArrayList < > ();



if (inet.isReachable(5000)) {

finish = new GregorianCalendar().getTimeInMillis();
long value = finish - start;

list.add(value);
long lowest = Collections.min(list);
System.out.println("value" + lowest);
sum = value + value / 10;
if (value < 250) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.green);
jTextPane2.setForeground(Color.green);
jTextField1.setBackground(Color.green);
} else if (value > 250 || value < 500) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.yellow);
jTextPane2.setBackground(Color.yellow);
jTextField1.setBackground(Color.yellow);

} else {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText(" " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.red);
jTextPane2.setBackground(Color.red);
jTextField1.setBackground(Color.red);
}

} else {
System.out.println(ipAddress + " NOT reachable.");
}
}
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
}

public static void main(String args) {
App m = new App();
NewJFrame jf = new NewJFrame();



}

void sendPingRequest(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}


Gui.java



package selenium;

import java.net.InetAddress;
import java.util.GregorianCalendar;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

/**
*
* @author User



public class NewJFrame extends javax.swing.JFrame {

* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}




private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


constants.java



public enum Constants {
NA ("104.160.131.3"), EUW("104.160.141.3"),EUNE("104.160.142.3"),KOR("104.160.156.1"),LAN("104.160.136.3");

private String ip;

Constants(String ip){
this.ip = ip;
}

public String getIp(){
return ip;
}
}









share|improve this question















I'm still a freshman and this one of my first projects I made using Java and Swing.



The program is a simple League of Legends multi-threaded ping checker that pings the server 10 times to get an average ping and determine the max and minimum ranges.



How can I make my code cleaner instead of writing so many if statements? Any suggestions or tips are greatly appreciated.



To check your ping you can download the software here.



import java.awt.Color;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import java.net.InetAddress;
import java.util.GregorianCalendar;
import java.util.*;

import javax.swing.JProgressBar;
/**
*
* @author User
*/
public class App {


public static void sendPingRequest2(String ipAddress, javax.swing.JTextPane jTextPane1, javax.swing.JTextPane jTextPane2, javax.swing.JTextField jTextField1) {

try {
for (int i = 0; i < 10; i++) {
InetAddress inet = InetAddress.getByName(ipAddress);
long finish = 0;
long start = new GregorianCalendar().getTimeInMillis();
System.out.println("Sending Ping Request to " + ipAddress);
long sum = 0;

List < Long > list = new ArrayList < > ();



if (inet.isReachable(5000)) {

finish = new GregorianCalendar().getTimeInMillis();
long value = finish - start;

list.add(value);
long lowest = Collections.min(list);
System.out.println("value" + lowest);
sum = value + value / 10;
if (value < 250) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.green);
jTextPane2.setForeground(Color.green);
jTextField1.setBackground(Color.green);
} else if (value > 250 || value < 500) {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText("average ping: " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.yellow);
jTextPane2.setBackground(Color.yellow);
jTextField1.setBackground(Color.yellow);

} else {

jTextPane1.setText("Ping RTT: " + value + "ms");
jTextPane2.setText(" " + sum + "ms");
jTextField1.setText("" + lowest + "ms");
jTextPane1.setBackground(Color.red);
jTextPane2.setBackground(Color.red);
jTextField1.setBackground(Color.red);
}

} else {
System.out.println(ipAddress + " NOT reachable.");
}
}
} catch (Exception e) {
System.out.println("Exception:" + e.getMessage());
}
}

public static void main(String args) {
App m = new App();
NewJFrame jf = new NewJFrame();



}

void sendPingRequest(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}


Gui.java



package selenium;

import java.net.InetAddress;
import java.util.GregorianCalendar;
import javax.swing.JProgressBar;
import javax.swing.JTextField;

/**
*
* @author User



public class NewJFrame extends javax.swing.JFrame {

* Creates new form NewJFrame
*/
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:

App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}




private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
App m = new App();


if (jRadioButton1.isSelected()) {



Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.141.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();

t1.start();
}
if (jRadioButton2.isSelected()) {


Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.156.1", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();
}


if (jRadioButton3.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.142.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton4.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.136.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}

if (jRadioButton5.isSelected()) {




Thread t1 = new Thread(new progress(jProgressBar1));
t1.start();
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
m.sendPingRequest2("104.160.131.3", jTextPane1, jTextPane2, jTextField1); // Insert some method call here.
}



});

t2.start();


}



}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}

private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}


constants.java



public enum Constants {
NA ("104.160.131.3"), EUW("104.160.141.3"),EUNE("104.160.142.3"),KOR("104.160.156.1"),LAN("104.160.136.3");

private String ip;

Constants(String ip){
this.ip = ip;
}

public String getIp(){
return ip;
}
}






java multithreading swing networking benchmarking






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 18 mins ago









200_success

128k15152413




128k15152413










asked 2 hours ago









Leon BogodLeon Bogod

3113




3113












  • Not sure whether this counts as an answer but I think there is strong reason to switch to JavaFX instead of using Swing. See here.
    – Dair
    15 mins ago










  • Also, I haven't used Swing, but it seems part of the reason you should use JavaFX is that it better supports the MVC paradigm. In particular, you can utilize FXML/CSS to design the UI and let the logic be controlled in Java. This isn't particularly in depth since I don't do much Java development, but the general rule of thumb for GUI applications is to not write static UIs in Java/C/etc. and use a markup-esque language to do so instead.
    – Dair
    10 mins ago




















  • Not sure whether this counts as an answer but I think there is strong reason to switch to JavaFX instead of using Swing. See here.
    – Dair
    15 mins ago










  • Also, I haven't used Swing, but it seems part of the reason you should use JavaFX is that it better supports the MVC paradigm. In particular, you can utilize FXML/CSS to design the UI and let the logic be controlled in Java. This isn't particularly in depth since I don't do much Java development, but the general rule of thumb for GUI applications is to not write static UIs in Java/C/etc. and use a markup-esque language to do so instead.
    – Dair
    10 mins ago


















Not sure whether this counts as an answer but I think there is strong reason to switch to JavaFX instead of using Swing. See here.
– Dair
15 mins ago




Not sure whether this counts as an answer but I think there is strong reason to switch to JavaFX instead of using Swing. See here.
– Dair
15 mins ago












Also, I haven't used Swing, but it seems part of the reason you should use JavaFX is that it better supports the MVC paradigm. In particular, you can utilize FXML/CSS to design the UI and let the logic be controlled in Java. This isn't particularly in depth since I don't do much Java development, but the general rule of thumb for GUI applications is to not write static UIs in Java/C/etc. and use a markup-esque language to do so instead.
– Dair
10 mins ago






Also, I haven't used Swing, but it seems part of the reason you should use JavaFX is that it better supports the MVC paradigm. In particular, you can utilize FXML/CSS to design the UI and let the logic be controlled in Java. This isn't particularly in depth since I don't do much Java development, but the general rule of thumb for GUI applications is to not write static UIs in Java/C/etc. and use a markup-esque language to do so instead.
– Dair
10 mins ago












0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211070%2fjava-league-of-legends-ping-checker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f211070%2fjava-league-of-legends-ping-checker%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'