-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPanel.java
80 lines (79 loc) · 3.1 KB
/
FPanel.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import javax.mail.MessagingException;
import javax.swing.*;
import java.awt.*;
public class FPanel extends JPanel implements Runnable {
public FFrame frame;
public JTextArea text;
public FPanel(FFrame frame) throws MessagingException {
this.frame=frame;
setLayout(new BorderLayout());
text = new JTextArea();
JScrollPane scroll = new JScrollPane(text, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
text.setFont(new Font("Serif", Font.PLAIN, 13));
String[] options = {"Add Server", "Load", "Quit"};
add(scroll, BorderLayout.CENTER);
JOptionPane.showMessageDialog(null, "This Program Checks If A Server \n Is Up, And Will Notify You If It Is Down");
int option= JOptionPane.showOptionDialog(null, "Choose An Option","Click a button", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0]);
if(option==0){
String ip= JOptionPane.showInputDialog("Type in the IP");
String port= JOptionPane.showInputDialog("Type in the Port");
frame.model.setIP(ip);
frame.model.setPort(port);
frame.model.checkServer();
String newText= (frame.model.getToReturn());
text.removeAll();
text.setText(newText);
validate();
repaint();
this.repaint();
frame.repaint();
}
else if(option==1){
JFileChooser file = new JFileChooser();
int option1 = file.showOpenDialog(this);
if (option1 == JFileChooser.APPROVE_OPTION) {
String filename = file.getSelectedFile().getAbsolutePath();
try {
FileInputStream in = new FileInputStream(filename);
ObjectInputStream objin = new ObjectInputStream(in);
frame.model = (FModel) objin.readObject();
objin.close();
in.close();
validate();
repaint();
//model.checkServer();
String newText= (frame.model.getToReturn());
text.removeAll();
text.setText(newText);
validate();
repaint();
frame.repaint();
this.repaint();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
else if(option==2){
System.exit(0);
}
text.requestFocus();
text.setText(frame.getModel().getToReturn());
repaint();
Thread b= new Thread();
b.start();
}
public void run(){
while(true){
try {
repaint();
revalidate();
this.repaint();
frame.repaint();
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}