-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatagramPanel.java
More file actions
58 lines (46 loc) · 1.66 KB
/
Copy pathDatagramPanel.java
File metadata and controls
58 lines (46 loc) · 1.66 KB
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;
import java.net.*;
import java.io.*;
/* Place holder for ip-address and port number for internet addressing */
public class DatagramPanel extends JPanel {
public static final long serialVersionUID = 2L;
JTextField address;
JTextField port;
public DatagramPanel() {
/* default dummy values */
this("192.168.255.254", 65535);
}
public DatagramPanel(String address, int port) {
/* create a JPanel populated with border and text fields */
super( new FlowLayout( FlowLayout.LEFT, 5, 0));
this.setBorder( BorderFactory.createTitledBorder("Socket Address"));
this.add(new JLabel("IP:"));
this.address = new JTextField(address);
this.add(this.address);
this.add(new JLabel("port:"));
this.port = new JTextField(Integer.toString(port));
this.add(this.port);
}
public void setAddress(String address){
this.address.setText(address);
}
public void setAddress(String address, boolean edit){
this.address.setText(address);
this.address.setEditable(edit);
}
public void setPort(int port){
this.port.setText(Integer.toString(port));
}
public void setPort(int port, boolean edit){
this.port.setText(Integer.toString(port));
this.port.setEditable(edit);
}
public InetSocketAddress getSocketAddress() {
return new InetSocketAddress(address.getText(),
Integer.parseInt(port.getText()));
}
}