SlideShare a Scribd company logo
1 of 7
Implement the following in my java program which is written under the requirements:
When a new member joins, the server will check if it is the first member. If it is, the member will
be informed and become the coordinator. If not, the member will request details of existing
members from the server and receive everyone's IDs, IP addresses, and ports, including the
current group coordinator.
The new member will then contact everyone through the server to let them know that they can
update their set of members to include the new member.
If some members do not respond, the new member will inform the server, and the server will
inform other members to update their local list of existing members.
If the coordinator does not respond, any new member will become the coordinator. The
coordinator will maintain the state of group members by checking periodically how many of
them are not responding and inform active members about it so they can update their state of
members.
Implement a messaging system for members to send private or broadcast messages to every other
member through the server.
Print out messages sent to and by the members.
Allow the program to run either automatically or manually. In the former case, simulate the task
automatically without accepting any input parameters from users. In the latter case, the program
will require user input to simulate the task.
My java program code:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class MemberServer {
private JFrame frame;
private JTextField idField;
private JTextField ipField;
private JTextField portField;
private JLabel statusLabel;
private static ServerSocket serverSocket;
private boolean isRunning;
// Frame 1
public MemberServer() {
frame = new JFrame("Member Server");
frame.setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(null);
JLabel idLabel = new JLabel("ID:");
idLabel.setBounds(10, 10, 100, 25);
panel.add(idLabel);
idField = new JTextField();
idField.setBounds(120, 10, 165, 25);
panel.add(idField);
JLabel ipLabel = new JLabel("IP Address:");
ipLabel.setBounds(10, 40, 100, 25);
panel.add(ipLabel);
ipField = new JTextField();
ipField.setBounds(120, 40, 165, 25);
panel.add(ipField);
JLabel portLabel = new JLabel("Port:");
portLabel.setBounds(10, 70, 100, 25);
panel.add(portLabel);
portField = new JTextField();
portField.setBounds(120, 70, 165, 25);
panel.add(portField);
// Start Button
JButton startButton = new JButton("Start Server");
startButton.setBounds(10, 100, 125, 25);
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startServer();
Frame2 frame = new Frame2();
frame.setVisible(true);
frame.setSize(500, 200);
frame.setResizable(false);
}
});
panel.add(startButton);
// Quit Button
JButton quitButton = new JButton("Quit");
quitButton.setBounds(290, 100, 125, 25);
;
quitButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
panel.add(quitButton);
// Save Button
JButton saveButton = new JButton("Save");
saveButton.setBounds(150, 100, 125, 25);
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveData();
}
});
panel.add(saveButton);
statusLabel = new JLabel();
statusLabel.setBounds(10, 140, 275, 25);
panel.add(statusLabel);
frame.add(panel, BorderLayout.CENTER);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setSize(500, 200);
frame.setResizable(false);
}
// Saving data
private void saveData() {
// Write code here to save data to a file or database
JOptionPane.showMessageDialog(this, "Data saved successfully.", "Success",
JOptionPane.INFORMATION_MESSAGE);
}
// Frame 2
public class Frame2 extends JFrame {
public Frame2() {
setTitle("Member Server P2");
setSize(500, 200);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
private void startServer() {
String id = idField.getText();
String ip = ipField.getText();
int port = Integer.parseInt(portField.getText());
if (id.isEmpty() || ip.isEmpty() || port <= 0) {
statusLabel.setText("Please enter a valid ID, IP address, and port.");
return;
}
String uniqueId = UUID.randomUUID().toString();
statusLabel.setText("Server started with ID: " + uniqueId);
isRunning = true;
new Thread(new Runnable() {
@Override
public void run() {
try {
serverSocket = new ServerSocket(port);
while (isRunning) {
Socket socket = serverSocket.accept();
// process incoming connection from member
}
} catch (IOException e) {
statusLabel.setText("Error starting server: " + e.getMessage());
}
}
}).start();
}
public static void main(String[] args) {
new MemberServer();
}
}

More Related Content

Similar to Implement the following in my java program which is written under the.docx

Vpd Virtual Private Database By Saurabh
Vpd   Virtual Private Database By SaurabhVpd   Virtual Private Database By Saurabh
Vpd Virtual Private Database By Saurabh
guestd83b546
 
C mode class
C mode classC mode class
C mode class
Accenture
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
lhkslkdh89009
 
Automate That! Scripting Atlassian applications in Python
Automate That! Scripting Atlassian applications in PythonAutomate That! Scripting Atlassian applications in Python
Automate That! Scripting Atlassian applications in Python
Atlassian
 
Automate that
Automate thatAutomate that
Automate that
Atlassian
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
ARORACOCKERY2111
 

Similar to Implement the following in my java program which is written under the.docx (20)

Back-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NETBack-2-Basics: Exception & Event Instrumentation in .NET
Back-2-Basics: Exception & Event Instrumentation in .NET
 
Core java
Core javaCore java
Core java
 
Java
Java Java
Java
 
Introduction to Shib 2.0 (Chad La Joie)
Introduction to Shib 2.0 (Chad La Joie)Introduction to Shib 2.0 (Chad La Joie)
Introduction to Shib 2.0 (Chad La Joie)
 
Puppet quick start guide
Puppet quick start guidePuppet quick start guide
Puppet quick start guide
 
Linux class 10 15 oct 2021-6
Linux class 10   15 oct 2021-6Linux class 10   15 oct 2021-6
Linux class 10 15 oct 2021-6
 
INTERNAL MAILING SYSTEM-Project report
INTERNAL MAILING SYSTEM-Project reportINTERNAL MAILING SYSTEM-Project report
INTERNAL MAILING SYSTEM-Project report
 
Vpd Virtual Private Database By Saurabh
Vpd   Virtual Private Database By SaurabhVpd   Virtual Private Database By Saurabh
Vpd Virtual Private Database By Saurabh
 
Puppet At Twitter - Puppet Camp Silicon Valley
Puppet At Twitter - Puppet Camp Silicon ValleyPuppet At Twitter - Puppet Camp Silicon Valley
Puppet At Twitter - Puppet Camp Silicon Valley
 
Technical Requirements of the UK Access Management Federation
Technical Requirements of the UK Access Management FederationTechnical Requirements of the UK Access Management Federation
Technical Requirements of the UK Access Management Federation
 
Instruction on creating a cluster on jboss eap environment
Instruction on creating a cluster on jboss eap environmentInstruction on creating a cluster on jboss eap environment
Instruction on creating a cluster on jboss eap environment
 
C mode class
C mode classC mode class
C mode class
 
Implementações paralelas
Implementações paralelasImplementações paralelas
Implementações paralelas
 
Ch ch-changes cake php2
Ch ch-changes cake php2Ch ch-changes cake php2
Ch ch-changes cake php2
 
Java 17
Java 17Java 17
Java 17
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
Automate That! Scripting Atlassian applications in Python
Automate That! Scripting Atlassian applications in PythonAutomate That! Scripting Atlassian applications in Python
Automate That! Scripting Atlassian applications in Python
 
Automate that
Automate thatAutomate that
Automate that
 
PandoraFMS: Free Monitoring System
PandoraFMS: Free Monitoring SystemPandoraFMS: Free Monitoring System
PandoraFMS: Free Monitoring System
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
 

More from Blake0FxCampbelld

In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
Blake0FxCampbelld
 
In a Word document- you will need to list and define all key terms wit.docx
In a Word document- you will need to list and define all key terms wit.docxIn a Word document- you will need to list and define all key terms wit.docx
In a Word document- you will need to list and define all key terms wit.docx
Blake0FxCampbelld
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
Blake0FxCampbelld
 
import java-util--- import java-io--- class Vertex { -- Constructo.docx
import java-util--- import java-io---   class Vertex {   -- Constructo.docximport java-util--- import java-io---   class Vertex {   -- Constructo.docx
import java-util--- import java-io--- class Vertex { -- Constructo.docx
Blake0FxCampbelld
 
Implement the Plates class buildMap function so that it populates the.docx
Implement the Plates class buildMap function so that it populates the.docxImplement the Plates class buildMap function so that it populates the.docx
Implement the Plates class buildMap function so that it populates the.docx
Blake0FxCampbelld
 

More from Blake0FxCampbelld (20)

In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
In Arevalo- Aravind- Ayuso and Roca's (2013) article- we learn that th.docx
In Arevalo- Aravind- Ayuso and Roca's (2013) article- we learn that th.docxIn Arevalo- Aravind- Ayuso and Roca's (2013) article- we learn that th.docx
In Arevalo- Aravind- Ayuso and Roca's (2013) article- we learn that th.docx
 
In a Word document- you will need to list and define all key terms wit.docx
In a Word document- you will need to list and define all key terms wit.docxIn a Word document- you will need to list and define all key terms wit.docx
In a Word document- you will need to list and define all key terms wit.docx
 
In a survey of 2918 adults- 1477 say they have started paying bills on.docx
In a survey of 2918 adults- 1477 say they have started paying bills on.docxIn a survey of 2918 adults- 1477 say they have started paying bills on.docx
In a survey of 2918 adults- 1477 say they have started paying bills on.docx
 
In a population of yellow mushrooms- a mutation resulted in a new purp (1).docx
In a population of yellow mushrooms- a mutation resulted in a new purp (1).docxIn a population of yellow mushrooms- a mutation resulted in a new purp (1).docx
In a population of yellow mushrooms- a mutation resulted in a new purp (1).docx
 
In a particular hospital- 5 newborn babies were delivered yesterday- H.docx
In a particular hospital- 5 newborn babies were delivered yesterday- H.docxIn a particular hospital- 5 newborn babies were delivered yesterday- H.docx
In a particular hospital- 5 newborn babies were delivered yesterday- H.docx
 
In a paper written by Bendey Coliege econonists Patricia M- Flynn and.docx
In a paper written by Bendey Coliege econonists Patricia M- Flynn and.docxIn a paper written by Bendey Coliege econonists Patricia M- Flynn and.docx
In a paper written by Bendey Coliege econonists Patricia M- Flynn and.docx
 
In a given population of Drosophila- curly wings (c) is recessive to t.docx
In a given population of Drosophila- curly wings (c) is recessive to t.docxIn a given population of Drosophila- curly wings (c) is recessive to t.docx
In a given population of Drosophila- curly wings (c) is recessive to t.docx
 
In a large population- 51- of the people have been vaccinated- If 4 pe.docx
In a large population- 51- of the people have been vaccinated- If 4 pe.docxIn a large population- 51- of the people have been vaccinated- If 4 pe.docx
In a large population- 51- of the people have been vaccinated- If 4 pe.docx
 
In a geographic isolate- a small population has been studied for a gen.docx
In a geographic isolate- a small population has been studied for a gen.docxIn a geographic isolate- a small population has been studied for a gen.docx
In a geographic isolate- a small population has been studied for a gen.docx
 
In a democracy- politicians may be shortsighted because they want to w.docx
In a democracy- politicians may be shortsighted because they want to w.docxIn a democracy- politicians may be shortsighted because they want to w.docx
In a democracy- politicians may be shortsighted because they want to w.docx
 
In a certain city- the daily consumption of water (in millions of lite.docx
In a certain city- the daily consumption of water (in millions of lite.docxIn a certain city- the daily consumption of water (in millions of lite.docx
In a certain city- the daily consumption of water (in millions of lite.docx
 
In a certain geographic location 15- of individuals have disease A- 15.docx
In a certain geographic location 15- of individuals have disease A- 15.docxIn a certain geographic location 15- of individuals have disease A- 15.docx
In a certain geographic location 15- of individuals have disease A- 15.docx
 
In 2014- the General Social Survey incuded a question about the role o.docx
In 2014- the General Social Survey incuded a question about the role o.docxIn 2014- the General Social Survey incuded a question about the role o.docx
In 2014- the General Social Survey incuded a question about the role o.docx
 
In 1993- when Fischer began his tenure at Kodak- the film industry was.docx
In 1993- when Fischer began his tenure at Kodak- the film industry was.docxIn 1993- when Fischer began his tenure at Kodak- the film industry was.docx
In 1993- when Fischer began his tenure at Kodak- the film industry was.docx
 
In search engines analyzes the sequences of search queries to identif.docx
In  search engines analyzes the sequences of search queries to identif.docxIn  search engines analyzes the sequences of search queries to identif.docx
In search engines analyzes the sequences of search queries to identif.docx
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
 
import java-util--- import java-io--- class Vertex { -- Constructo.docx
import java-util--- import java-io---   class Vertex {   -- Constructo.docximport java-util--- import java-io---   class Vertex {   -- Constructo.docx
import java-util--- import java-io--- class Vertex { -- Constructo.docx
 
Implement the Plates class buildMap function so that it populates the.docx
Implement the Plates class buildMap function so that it populates the.docxImplement the Plates class buildMap function so that it populates the.docx
Implement the Plates class buildMap function so that it populates the.docx
 
Implementing AES- Native Instructions (AES-NI) is faster than other im.docx
Implementing AES- Native Instructions (AES-NI) is faster than other im.docxImplementing AES- Native Instructions (AES-NI) is faster than other im.docx
Implementing AES- Native Instructions (AES-NI) is faster than other im.docx
 

Recently uploaded

Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 

Implement the following in my java program which is written under the.docx

  • 1. Implement the following in my java program which is written under the requirements: When a new member joins, the server will check if it is the first member. If it is, the member will be informed and become the coordinator. If not, the member will request details of existing members from the server and receive everyone's IDs, IP addresses, and ports, including the current group coordinator. The new member will then contact everyone through the server to let them know that they can update their set of members to include the new member. If some members do not respond, the new member will inform the server, and the server will inform other members to update their local list of existing members. If the coordinator does not respond, any new member will become the coordinator. The coordinator will maintain the state of group members by checking periodically how many of them are not responding and inform active members about it so they can update their state of members. Implement a messaging system for members to send private or broadcast messages to every other member through the server. Print out messages sent to and by the members. Allow the program to run either automatically or manually. In the former case, simulate the task automatically without accepting any input parameters from users. In the latter case, the program will require user input to simulate the task. My java program code: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.ServerSocket; import java.net.Socket;
  • 2. import java.util.ArrayList; import java.util.List; import java.util.UUID; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class MemberServer { private JFrame frame; private JTextField idField; private JTextField ipField; private JTextField portField; private JLabel statusLabel; private static ServerSocket serverSocket; private boolean isRunning; // Frame 1 public MemberServer() { frame = new JFrame("Member Server"); frame.setLayout(new BorderLayout()); JPanel panel = new JPanel(); panel.setLayout(null);
  • 3. JLabel idLabel = new JLabel("ID:"); idLabel.setBounds(10, 10, 100, 25); panel.add(idLabel); idField = new JTextField(); idField.setBounds(120, 10, 165, 25); panel.add(idField); JLabel ipLabel = new JLabel("IP Address:"); ipLabel.setBounds(10, 40, 100, 25); panel.add(ipLabel); ipField = new JTextField(); ipField.setBounds(120, 40, 165, 25); panel.add(ipField); JLabel portLabel = new JLabel("Port:"); portLabel.setBounds(10, 70, 100, 25); panel.add(portLabel); portField = new JTextField(); portField.setBounds(120, 70, 165, 25); panel.add(portField); // Start Button JButton startButton = new JButton("Start Server"); startButton.setBounds(10, 100, 125, 25); startButton.addActionListener(new ActionListener() { @Override
  • 4. public void actionPerformed(ActionEvent e) { startServer(); Frame2 frame = new Frame2(); frame.setVisible(true); frame.setSize(500, 200); frame.setResizable(false); } }); panel.add(startButton); // Quit Button JButton quitButton = new JButton("Quit"); quitButton.setBounds(290, 100, 125, 25); ; quitButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); panel.add(quitButton); // Save Button JButton saveButton = new JButton("Save"); saveButton.setBounds(150, 100, 125, 25);
  • 5. saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveData(); } }); panel.add(saveButton); statusLabel = new JLabel(); statusLabel.setBounds(10, 140, 275, 25); panel.add(statusLabel); frame.add(panel, BorderLayout.CENTER); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setSize(500, 200); frame.setResizable(false); } // Saving data private void saveData() { // Write code here to save data to a file or database JOptionPane.showMessageDialog(this, "Data saved successfully.", "Success", JOptionPane.INFORMATION_MESSAGE); } // Frame 2
  • 6. public class Frame2 extends JFrame { public Frame2() { setTitle("Member Server P2"); setSize(500, 200); setLocationRelativeTo(null); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } private void startServer() { String id = idField.getText(); String ip = ipField.getText(); int port = Integer.parseInt(portField.getText()); if (id.isEmpty() || ip.isEmpty() || port <= 0) { statusLabel.setText("Please enter a valid ID, IP address, and port."); return; } String uniqueId = UUID.randomUUID().toString(); statusLabel.setText("Server started with ID: " + uniqueId); isRunning = true; new Thread(new Runnable() { @Override public void run() { try {
  • 7. serverSocket = new ServerSocket(port); while (isRunning) { Socket socket = serverSocket.accept(); // process incoming connection from member } } catch (IOException e) { statusLabel.setText("Error starting server: " + e.getMessage()); } } }).start(); } public static void main(String[] args) { new MemberServer(); } }