-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.java
More file actions
76 lines (73 loc) · 2.9 KB
/
MainFrame.java
File metadata and controls
76 lines (73 loc) · 2.9 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class MainFrame extends JFrame{
int flag = -1;
public MainFrame(String title)
{
super(title);
setLayout(new BorderLayout());
this.setSize(300,120);
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
int xpos = (dim.width/2) - (this.getWidth()/2);
int ypos = (dim.height/2) - (this.getHeight()/2);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocation(xpos, ypos);
this.setResizable(false);
this.setLocationRelativeTo(null);
JButton server = new RoundCornerButton("Server",new Dimension(90,40));
JButton client = new RoundCornerButton("Client",new Dimension(90,40));
server.setToolTipText("Create a Server and send data");
client.setToolTipText("Create a Client and receive data");
JPanel parent = new JPanel();
parent.setBackground(new Color(242,154,26));
JPanel child1 = new JPanel();
child1.setBackground(new Color(242,154,26));
JPanel child2 = new JPanel();
child2.setBackground(new Color(242,154,26));
child1.setLayout(new FlowLayout(FlowLayout.CENTER));
child1.add(server);
child1.add(client);
JLabel jl = new JLabel("Created by soun059");
child2.add(jl);
parent.add(child1);
parent.add(child2);
this.add(parent);
server.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(MainFrame.this.flag==-1){
ServerFrame fs = new ServerFrame("Server");
fs.setVisible(true);
fs.setSize(430,430);
MainFrame.this.flag=1;
fs.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e) {
MainFrame.this.flag=-1;
}
});
}
}
});
client.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
if(MainFrame.this.flag==-1){
ClientFrame fs = new ClientFrame("Client");
fs.setVisible(true);
fs.setSize(300,300);
MainFrame.this.flag=1;
fs.addWindowListener(new WindowAdapter(){
public void windowClosed(WindowEvent e) {
MainFrame.this.flag=-1;
}
});
}
}
});
}
}