JahKnight
Picopat
- Katılım
- 5 Ekim 2024
- Mesajlar
- 104
Daha fazla
- Cinsiyet
- Erkek
// Kaynak Kodları
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.HttpURLConnection;
import java.net.URL;
public class InternetSpeedTest extends JFrame {
private JLabel resultLabel;
private JButton testButton;
public InternetSpeedTest() {
setTitle("İnternet Hız Ölçer");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new FlowLayout());
// Sonuç label'ı
resultLabel = new JLabel("İnternet hızınızı ölçmek için butona tıklayın.");
resultLabel.setFont(new Font("Arial", Font.PLAIN, 16));
resultLabel.setForeground(Color.BLUE);
resultLabel.setOpaque(false); // Saydam
add(resultLabel);
// Buton
testButton = new JButton("Hız Ölç");
testButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
testInternetSpeed();
}
});
add(testButton);
}
private void testInternetSpeed() {
long startTime = System.currentTimeMillis();
try {
URL url = new URL("Google"); // Hız ölçümü için URL
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setConnectTimeout(5000); // 5 saniye zaman aşımı
urlConnection.connect();
long endTime = System.currentTimeMillis();
long duration = endTime - startTime; // Yanıt süresi
resultLabel.setText("İnternet Hızınız: " + duration + " ms");
} catch (Exception ex) {
resultLabel.setText("Hız ölçümünde hata: " + ex.getMessage());
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
InternetSpeedTest app = new InternetSpeedTest();
app.setVisible(true);
});
}
}
// Not : Visual Studio code'dan deneyiniz JDK indirip VSC kurulumunu Yapınız.
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.HttpURLConnection;
import java.net.URL;
public class InternetSpeedTest extends JFrame {
private JLabel resultLabel;
private JButton testButton;
public InternetSpeedTest() {
setTitle("İnternet Hız Ölçer");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setLayout(new FlowLayout());
// Sonuç label'ı
resultLabel = new JLabel("İnternet hızınızı ölçmek için butona tıklayın.");
resultLabel.setFont(new Font("Arial", Font.PLAIN, 16));
resultLabel.setForeground(Color.BLUE);
resultLabel.setOpaque(false); // Saydam
add(resultLabel);
// Buton
testButton = new JButton("Hız Ölç");
testButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
testInternetSpeed();
}
});
add(testButton);
}
private void testInternetSpeed() {
long startTime = System.currentTimeMillis();
try {
URL url = new URL("Google"); // Hız ölçümü için URL
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setConnectTimeout(5000); // 5 saniye zaman aşımı
urlConnection.connect();
long endTime = System.currentTimeMillis();
long duration = endTime - startTime; // Yanıt süresi
resultLabel.setText("İnternet Hızınız: " + duration + " ms");
} catch (Exception ex) {
resultLabel.setText("Hız ölçümünde hata: " + ex.getMessage());
}
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
InternetSpeedTest app = new InternetSpeedTest();
app.setVisible(true);
});
}
}
// Not : Visual Studio code'dan deneyiniz JDK indirip VSC kurulumunu Yapınız.