SlideShare a Scribd company logo
Need help coding MorseCode in Java:
Create Class MorseCodeClient. This represents a Client that allows a user communicate with a
server across a network. The server saves the message and then relays the message to another
client This is a JFrame application and should extend JFrame and Implement Runnable. The
client application should allow the user to type English-language phrases in a JTextArea. When
the user sends the message, the client application encodes the text into Morse code and sends the
coded message through the server to the other client. Create class MorseCodeClientTest, this is a
test class for morse code client and uses the main method to created new instance of
MorseCodeClient.
Solution
package MorseCode;
import java.util.ArrayList;
public class MorseCodeConverter extends javax.swing.JFrame {
/**
* Creates new form MorseCodeConverter
*/
public MorseCodeConverter() {
initComponents();
}
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
mainWindowContainer = new javax.swing.JPanel();
userSentence = new javax.swing.JTextField();
inputLabel = new javax.swing.JLabel();
outputLabel = new javax.swing.JLabel();
inputConfirmButton = new javax.swing.JButton();
outputField = new javax.swing.JTextField();
title = new javax.swing.JLabel();
javax.swing.GroupLayout mainWindowContainerLayout = new
javax.swing.GroupLayout(mainWindowContainer);
mainWindowContainer.setLayout(mainWindowContainerLayout);
mainWindowContainerLayout.setHorizontalGroup(
mainWindowContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addGap(0, 100, Short.MAX_VALUE)
);
mainWindowContainerLayout.setVerticalGroup(
mainWindowContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addGap(0, 100, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(204, 204, 255));
userSentence.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
userSentenceActionPerformed(evt);
}
});
inputLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
inputLabel.setText("Enter your sentence here");
outputLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
outputLabel.setText("This is your sentence in Morse Code");
outputLabel.setToolTipText("");
inputConfirmButton.setText("OK");
inputConfirmButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
inputConfirmButtonActionPerformed(evt);
}
});
outputField.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
title.setFont(new java.awt.Font("Simplified Arabic", 0, 18)); // NOI18N
title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
title.setText("Morse Code Converter");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(171, 171, 171)
.addComponent(inputConfirmButton))
.addGroup(layout.createSequentialGroup()
.addGap(88, 88, 88)
.addComponent(inputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 148,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(outputLabel, javax.swing.GroupLayout.PREFERRED_SIZE,
212, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(userSentence, javax.swing.GroupLayout.DEFAULT_SIZE,
349, Short.MAX_VALUE)
.addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 346,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(outputField))))
.addContainerGap(30, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[]
{inputLabel, outputLabel});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 26,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(21, 21, 21)
.addComponent(inputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(userSentence, javax.swing.GroupLayout.PREFERRED_SIZE, 27,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(inputConfirmButton)
.addGap(31, 31, 31)
.addComponent(outputLabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(outputField, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(44, 44, 44))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[]
{outputField, userSentence});
pack();
}// //GEN-END:initComponents
/**
* This method is run when the User enters a sentence; it runs
* when the user hits 'enter'.
*/
private void userSentenceActionPerformed(java.awt.event.ActionEvent evt) {
//GEN- FIRST:event_userSentenceActionPerformed
String[] morseCode = {" ", "--..--", ".-.-.-", "..--..", "-----",
".----", "..---", "...---", "....-", ".....", "-....", "--...",
"---..", "----.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
"....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--",
"--.."};
String english = " ,.?0123456789abcdefghijklmnopqrstuvwxyz";
char[] englishArray = english.toCharArray();
ArrayList holdList = new ArrayList<>();
StringBuilder holdBuilder = new StringBuilder();
String userString = userSentence.getText().toLowerCase();
char[] userArray = userString.toCharArray();
for(int i = 0; i < userArray.length; i++) {
for(int n = 0; n < englishArray.length; n++) {
if(userArray[i] == englishArray[n]) {
holdList.add(n);
}
}
}
for(int i = 0; i < holdList.size(); i++) {
holdBuilder.append(morseCode[holdList.get(i)]);
}
String moCode = holdBuilder.toString();
outputField.setText(moCode);
}//GEN-LAST:event_userSentenceActionPerformed
/**
* This method is run when the user clicks the 'OK' button
* in the GUI. It has the same code as the userSentence method
*/
private void inputConfirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-
FIRST:event_inputConfirmButtonActionPerformed
// a string array to hold all of the Morse Code values
String[] morseCode = {" ", "--..--", ".-.-.-", "..--..", "-----",
".----", "..---", "...---", "....-", ".....", "-....", "--...",
"---..", "----.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.",
"....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.",
"--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--",
"--.."};
// a string of english letter, numbers and punctuation that
// corresponds to the Morse Code list
String english = " ,.?0123456789abcdefghijklmnopqrstuvwxyz";
// turn that english string into an array of characters
// this will allow us to iterate over it
char[] englishArray = english.toCharArray();
// make an ArrayList to hold our index values as we find them.
// also initialize a StringBuilder object that will help us in
// printing out a clean string of morse code values
ArrayList holdList = new ArrayList<>();
StringBuilder holdBuilder = new StringBuilder();
// user input, convert to lowercase for simplicity;
// convert the input to a character array. This will
// allow iteration
String userString = userSentence.getText().toLowerCase();
char[] userArray = userString.toCharArray();
// loop through each character in the userArray, and match
// them up with values in the array of english characters.
// save the index value of the english array
for(int i = 0; i < userArray.length; i++) {
for(int n = 0; n < englishArray.length; n++) {
if(userArray[i] == englishArray[n]) {
holdList.add(n);
}
}
}
// append all morse codes associated
// with the english array indexes to the StringBuilder object.
for(int i = 0; i < holdList.size(); i++) {
holdBuilder.append(morseCode[holdList.get(i)]);
}
// convert that object to a string and print it out.
String moCode = holdBuilder.toString();
outputField.setText(moCode);
}//GEN-LAST:event_inputConfirmButtonActionPerformed
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MorseCodeConverter().setVisible(true);
}
});
}
private javax.swing.JButton inputConfirmButton;
private javax.swing.JLabel inputLabel;
private javax.swing.JPanel mainWindowContainer;
private javax.swing.JTextField outputField;
private javax.swing.JLabel outputLabel;
private javax.swing.JLabel title;
private javax.swing.JTextField userSentence;
}

More Related Content

Similar to Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf

JavaParser - A tool to generate, analyze and refactor Java code
JavaParser - A tool to generate, analyze and refactor Java codeJavaParser - A tool to generate, analyze and refactor Java code
JavaParser - A tool to generate, analyze and refactor Java code
Federico Tomassetti
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
Fulvio Corno
 
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. NagpurCore & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
PSK Technolgies Pvt. Ltd. IT Company Nagpur
 
Java 17
Java 17Java 17
Java 17
Mutlu Okuducu
 
Diifeerences In C#
Diifeerences In C#Diifeerences In C#
Diifeerences In C#
rohit_gupta_mrt
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
Shivam Singh
 
Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
Vinod Srivastava
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
anjani pavan kumar
 
Examples from Pune meetup
Examples from Pune meetupExamples from Pune meetup
Examples from Pune meetup
Santosh Ojha
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Spring data ii
Spring data iiSpring data ii
Spring data ii
명철 강
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
jitendral
 
Graphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLetsGraphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLetsJussi Pohjolainen
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]srikanthbkm
 
Java script
 Java script Java script
Java scriptbosybosy
 

Similar to Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf (20)

JavaParser - A tool to generate, analyze and refactor Java code
JavaParser - A tool to generate, analyze and refactor Java codeJavaParser - A tool to generate, analyze and refactor Java code
JavaParser - A tool to generate, analyze and refactor Java code
 
Introduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applicationsIntroduction to JDBC and database access in web applications
Introduction to JDBC and database access in web applications
 
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. NagpurCore & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
Core & Advance Java Training For Beginner-PSK Technologies Pvt. Ltd. Nagpur
 
Java 17
Java 17Java 17
Java 17
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Diifeerences In C#
Diifeerences In C#Diifeerences In C#
Diifeerences In C#
 
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
#18.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_국비지원IT학원/실업자/재직자환급교육/자바/스프링/...
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
Javascripting.pptx
Javascripting.pptxJavascripting.pptx
Javascripting.pptx
 
WD programs descriptions.docx
WD programs descriptions.docxWD programs descriptions.docx
WD programs descriptions.docx
 
SCDJWS 5. JAX-WS
SCDJWS 5. JAX-WSSCDJWS 5. JAX-WS
SCDJWS 5. JAX-WS
 
Examples from Pune meetup
Examples from Pune meetupExamples from Pune meetup
Examples from Pune meetup
 
JavaScript - An Introduction
JavaScript - An IntroductionJavaScript - An Introduction
JavaScript - An Introduction
 
Spring data ii
Spring data iiSpring data ii
Spring data ii
 
J2ee standards > CDI
J2ee standards > CDIJ2ee standards > CDI
J2ee standards > CDI
 
Sqlapi0.1
Sqlapi0.1Sqlapi0.1
Sqlapi0.1
 
Graphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLetsGraphics, Threads and HTTPConnections in MIDLets
Graphics, Threads and HTTPConnections in MIDLets
 
Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]Vb script tutorial for qtp[1]
Vb script tutorial for qtp[1]
 
Java script
 Java script Java script
Java script
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 

More from fastechsrv

What is the purpose of performing a dark reaction Explain why it is.pdf
What is the purpose of performing a dark reaction Explain why it is.pdfWhat is the purpose of performing a dark reaction Explain why it is.pdf
What is the purpose of performing a dark reaction Explain why it is.pdf
fastechsrv
 
What is a tissue _____ What are some identifying features of merist.pdf
What is a tissue _____  What are some identifying features of merist.pdfWhat is a tissue _____  What are some identifying features of merist.pdf
What is a tissue _____ What are some identifying features of merist.pdf
fastechsrv
 
Tonya and Lydia are two senior nursing students assigned to work in .pdf
Tonya and Lydia are two senior nursing students assigned to work in .pdfTonya and Lydia are two senior nursing students assigned to work in .pdf
Tonya and Lydia are two senior nursing students assigned to work in .pdf
fastechsrv
 
This figure shows the stress-strain curve for a polymer. The followi.pdf
This figure shows the stress-strain curve for a polymer. The followi.pdfThis figure shows the stress-strain curve for a polymer. The followi.pdf
This figure shows the stress-strain curve for a polymer. The followi.pdf
fastechsrv
 
There are 6 holes in a wall. A mouse is in one hole I dont know wh.pdf
There are 6 holes in a wall.  A mouse is in one hole I dont know wh.pdfThere are 6 holes in a wall.  A mouse is in one hole I dont know wh.pdf
There are 6 holes in a wall. A mouse is in one hole I dont know wh.pdf
fastechsrv
 
The identity below was verified incorrectly. In which line was an err.pdf
The identity below was verified incorrectly. In which line was an err.pdfThe identity below was verified incorrectly. In which line was an err.pdf
The identity below was verified incorrectly. In which line was an err.pdf
fastechsrv
 
The FED is both centralized and decentralized in its structure. .pdf
The FED is both centralized and decentralized in its structure. .pdfThe FED is both centralized and decentralized in its structure. .pdf
The FED is both centralized and decentralized in its structure. .pdf
fastechsrv
 
The diameter of the Milky Way disc is approximately 9x10^20 meters. .pdf
The diameter of the Milky Way disc is approximately 9x10^20 meters. .pdfThe diameter of the Milky Way disc is approximately 9x10^20 meters. .pdf
The diameter of the Milky Way disc is approximately 9x10^20 meters. .pdf
fastechsrv
 
The Ad Hoc network shown below (including node Q) is currently operat.pdf
The Ad Hoc network shown below (including node Q) is currently operat.pdfThe Ad Hoc network shown below (including node Q) is currently operat.pdf
The Ad Hoc network shown below (including node Q) is currently operat.pdf
fastechsrv
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
fastechsrv
 
RNA is important for all of the following reasons EXCEPT most RNA .pdf
RNA is important for all of the following reasons EXCEPT  most RNA .pdfRNA is important for all of the following reasons EXCEPT  most RNA .pdf
RNA is important for all of the following reasons EXCEPT most RNA .pdf
fastechsrv
 
Patient A got IV (Intravenous) fluid at the hospital that turned out .pdf
Patient A got IV (Intravenous) fluid at the hospital that turned out .pdfPatient A got IV (Intravenous) fluid at the hospital that turned out .pdf
Patient A got IV (Intravenous) fluid at the hospital that turned out .pdf
fastechsrv
 
Novotny et al. The authors of the paper Why are there so many speci.pdf
Novotny et al. The authors of the paper Why are there so many speci.pdfNovotny et al. The authors of the paper Why are there so many speci.pdf
Novotny et al. The authors of the paper Why are there so many speci.pdf
fastechsrv
 
Match the description with the appropriate term. Where more than one .pdf
Match the description with the appropriate term. Where more than one .pdfMatch the description with the appropriate term. Where more than one .pdf
Match the description with the appropriate term. Where more than one .pdf
fastechsrv
 
How should globalization be viewed as a four dimensional concept.pdf
How should globalization be viewed as a four dimensional concept.pdfHow should globalization be viewed as a four dimensional concept.pdf
How should globalization be viewed as a four dimensional concept.pdf
fastechsrv
 
I want the show the works step by step for Aand B Autism is a seriou.pdf
I want the show the works step by step for Aand B Autism is a seriou.pdfI want the show the works step by step for Aand B Autism is a seriou.pdf
I want the show the works step by step for Aand B Autism is a seriou.pdf
fastechsrv
 
If only one strand of the DNA molecule is transcribed for a particul.pdf
If only one strand of the DNA molecule is transcribed for a particul.pdfIf only one strand of the DNA molecule is transcribed for a particul.pdf
If only one strand of the DNA molecule is transcribed for a particul.pdf
fastechsrv
 
How do each of the factors listed in (1) affect the diffusion of sol.pdf
How do each of the factors listed in (1) affect the diffusion of sol.pdfHow do each of the factors listed in (1) affect the diffusion of sol.pdf
How do each of the factors listed in (1) affect the diffusion of sol.pdf
fastechsrv
 
find the domain of the function f (x)= 2x3 x8SolutionNumerat.pdf
find the domain of the function f (x)= 2x3 x8SolutionNumerat.pdffind the domain of the function f (x)= 2x3 x8SolutionNumerat.pdf
find the domain of the function f (x)= 2x3 x8SolutionNumerat.pdf
fastechsrv
 
Explain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdf
Explain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdfExplain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdf
Explain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdf
fastechsrv
 

More from fastechsrv (20)

What is the purpose of performing a dark reaction Explain why it is.pdf
What is the purpose of performing a dark reaction Explain why it is.pdfWhat is the purpose of performing a dark reaction Explain why it is.pdf
What is the purpose of performing a dark reaction Explain why it is.pdf
 
What is a tissue _____ What are some identifying features of merist.pdf
What is a tissue _____  What are some identifying features of merist.pdfWhat is a tissue _____  What are some identifying features of merist.pdf
What is a tissue _____ What are some identifying features of merist.pdf
 
Tonya and Lydia are two senior nursing students assigned to work in .pdf
Tonya and Lydia are two senior nursing students assigned to work in .pdfTonya and Lydia are two senior nursing students assigned to work in .pdf
Tonya and Lydia are two senior nursing students assigned to work in .pdf
 
This figure shows the stress-strain curve for a polymer. The followi.pdf
This figure shows the stress-strain curve for a polymer. The followi.pdfThis figure shows the stress-strain curve for a polymer. The followi.pdf
This figure shows the stress-strain curve for a polymer. The followi.pdf
 
There are 6 holes in a wall. A mouse is in one hole I dont know wh.pdf
There are 6 holes in a wall.  A mouse is in one hole I dont know wh.pdfThere are 6 holes in a wall.  A mouse is in one hole I dont know wh.pdf
There are 6 holes in a wall. A mouse is in one hole I dont know wh.pdf
 
The identity below was verified incorrectly. In which line was an err.pdf
The identity below was verified incorrectly. In which line was an err.pdfThe identity below was verified incorrectly. In which line was an err.pdf
The identity below was verified incorrectly. In which line was an err.pdf
 
The FED is both centralized and decentralized in its structure. .pdf
The FED is both centralized and decentralized in its structure. .pdfThe FED is both centralized and decentralized in its structure. .pdf
The FED is both centralized and decentralized in its structure. .pdf
 
The diameter of the Milky Way disc is approximately 9x10^20 meters. .pdf
The diameter of the Milky Way disc is approximately 9x10^20 meters. .pdfThe diameter of the Milky Way disc is approximately 9x10^20 meters. .pdf
The diameter of the Milky Way disc is approximately 9x10^20 meters. .pdf
 
The Ad Hoc network shown below (including node Q) is currently operat.pdf
The Ad Hoc network shown below (including node Q) is currently operat.pdfThe Ad Hoc network shown below (including node Q) is currently operat.pdf
The Ad Hoc network shown below (including node Q) is currently operat.pdf
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
RNA is important for all of the following reasons EXCEPT most RNA .pdf
RNA is important for all of the following reasons EXCEPT  most RNA .pdfRNA is important for all of the following reasons EXCEPT  most RNA .pdf
RNA is important for all of the following reasons EXCEPT most RNA .pdf
 
Patient A got IV (Intravenous) fluid at the hospital that turned out .pdf
Patient A got IV (Intravenous) fluid at the hospital that turned out .pdfPatient A got IV (Intravenous) fluid at the hospital that turned out .pdf
Patient A got IV (Intravenous) fluid at the hospital that turned out .pdf
 
Novotny et al. The authors of the paper Why are there so many speci.pdf
Novotny et al. The authors of the paper Why are there so many speci.pdfNovotny et al. The authors of the paper Why are there so many speci.pdf
Novotny et al. The authors of the paper Why are there so many speci.pdf
 
Match the description with the appropriate term. Where more than one .pdf
Match the description with the appropriate term. Where more than one .pdfMatch the description with the appropriate term. Where more than one .pdf
Match the description with the appropriate term. Where more than one .pdf
 
How should globalization be viewed as a four dimensional concept.pdf
How should globalization be viewed as a four dimensional concept.pdfHow should globalization be viewed as a four dimensional concept.pdf
How should globalization be viewed as a four dimensional concept.pdf
 
I want the show the works step by step for Aand B Autism is a seriou.pdf
I want the show the works step by step for Aand B Autism is a seriou.pdfI want the show the works step by step for Aand B Autism is a seriou.pdf
I want the show the works step by step for Aand B Autism is a seriou.pdf
 
If only one strand of the DNA molecule is transcribed for a particul.pdf
If only one strand of the DNA molecule is transcribed for a particul.pdfIf only one strand of the DNA molecule is transcribed for a particul.pdf
If only one strand of the DNA molecule is transcribed for a particul.pdf
 
How do each of the factors listed in (1) affect the diffusion of sol.pdf
How do each of the factors listed in (1) affect the diffusion of sol.pdfHow do each of the factors listed in (1) affect the diffusion of sol.pdf
How do each of the factors listed in (1) affect the diffusion of sol.pdf
 
find the domain of the function f (x)= 2x3 x8SolutionNumerat.pdf
find the domain of the function f (x)= 2x3 x8SolutionNumerat.pdffind the domain of the function f (x)= 2x3 x8SolutionNumerat.pdf
find the domain of the function f (x)= 2x3 x8SolutionNumerat.pdf
 
Explain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdf
Explain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdfExplain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdf
Explain a) advantage of dispersing seeds, andexplain b) two (2) neat.pdf
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 

Need help coding MorseCode in JavaCreate Class MorseCodeClient. T.pdf

  • 1. Need help coding MorseCode in Java: Create Class MorseCodeClient. This represents a Client that allows a user communicate with a server across a network. The server saves the message and then relays the message to another client This is a JFrame application and should extend JFrame and Implement Runnable. The client application should allow the user to type English-language phrases in a JTextArea. When the user sends the message, the client application encodes the text into Morse code and sends the coded message through the server to the other client. Create class MorseCodeClientTest, this is a test class for morse code client and uses the main method to created new instance of MorseCodeClient. Solution package MorseCode; import java.util.ArrayList; public class MorseCodeConverter extends javax.swing.JFrame { /** * Creates new form MorseCodeConverter */ public MorseCodeConverter() { initComponents(); } @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { mainWindowContainer = new javax.swing.JPanel(); userSentence = new javax.swing.JTextField(); inputLabel = new javax.swing.JLabel(); outputLabel = new javax.swing.JLabel(); inputConfirmButton = new javax.swing.JButton(); outputField = new javax.swing.JTextField(); title = new javax.swing.JLabel(); javax.swing.GroupLayout mainWindowContainerLayout = new javax.swing.GroupLayout(mainWindowContainer); mainWindowContainer.setLayout(mainWindowContainerLayout); mainWindowContainerLayout.setHorizontalGroup(
  • 2. mainWindowContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING) .addGap(0, 100, Short.MAX_VALUE) ); mainWindowContainerLayout.setVerticalGroup( mainWindowContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING) .addGap(0, 100, Short.MAX_VALUE) ); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setBackground(new java.awt.Color(204, 204, 255)); userSentence.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { userSentenceActionPerformed(evt); } }); inputLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); inputLabel.setText("Enter your sentence here"); outputLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); outputLabel.setText("This is your sentence in Morse Code"); outputLabel.setToolTipText(""); inputConfirmButton.setText("OK"); inputConfirmButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { inputConfirmButtonActionPerformed(evt); } }); outputField.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N title.setFont(new java.awt.Font("Simplified Arabic", 0, 18)); // NOI18N title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); title.setText("Morse Code Converter"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(
  • 3. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(171, 171, 171) .addComponent(inputConfirmButton)) .addGroup(layout.createSequentialGroup() .addGap(88, 88, 88) .addComponent(inputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 148, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(86, 86, 86) .addComponent(outputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(userSentence, javax.swing.GroupLayout.DEFAULT_SIZE, 349, Short.MAX_VALUE) .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(outputField)))) .addContainerGap(30, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {inputLabel, outputLabel}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(21, 21, 21)
  • 4. .addComponent(inputLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(userSentence, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(inputConfirmButton) .addGap(31, 31, 31) .addComponent(outputLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(outputField, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(44, 44, 44)) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {outputField, userSentence}); pack(); }// //GEN-END:initComponents /** * This method is run when the User enters a sentence; it runs * when the user hits 'enter'. */ private void userSentenceActionPerformed(java.awt.event.ActionEvent evt) { //GEN- FIRST:event_userSentenceActionPerformed String[] morseCode = {" ", "--..--", ".-.-.-", "..--..", "-----", ".----", "..---", "...---", "....-", ".....", "-....", "--...", "---..", "----.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}; String english = " ,.?0123456789abcdefghijklmnopqrstuvwxyz"; char[] englishArray = english.toCharArray(); ArrayList holdList = new ArrayList<>(); StringBuilder holdBuilder = new StringBuilder();
  • 5. String userString = userSentence.getText().toLowerCase(); char[] userArray = userString.toCharArray(); for(int i = 0; i < userArray.length; i++) { for(int n = 0; n < englishArray.length; n++) { if(userArray[i] == englishArray[n]) { holdList.add(n); } } } for(int i = 0; i < holdList.size(); i++) { holdBuilder.append(morseCode[holdList.get(i)]); } String moCode = holdBuilder.toString(); outputField.setText(moCode); }//GEN-LAST:event_userSentenceActionPerformed /** * This method is run when the user clicks the 'OK' button * in the GUI. It has the same code as the userSentence method */ private void inputConfirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN- FIRST:event_inputConfirmButtonActionPerformed // a string array to hold all of the Morse Code values String[] morseCode = {" ", "--..--", ".-.-.-", "..--..", "-----", ".----", "..---", "...---", "....-", ".....", "-....", "--...", "---..", "----.", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."}; // a string of english letter, numbers and punctuation that // corresponds to the Morse Code list String english = " ,.?0123456789abcdefghijklmnopqrstuvwxyz"; // turn that english string into an array of characters // this will allow us to iterate over it char[] englishArray = english.toCharArray();
  • 6. // make an ArrayList to hold our index values as we find them. // also initialize a StringBuilder object that will help us in // printing out a clean string of morse code values ArrayList holdList = new ArrayList<>(); StringBuilder holdBuilder = new StringBuilder(); // user input, convert to lowercase for simplicity; // convert the input to a character array. This will // allow iteration String userString = userSentence.getText().toLowerCase(); char[] userArray = userString.toCharArray(); // loop through each character in the userArray, and match // them up with values in the array of english characters. // save the index value of the english array for(int i = 0; i < userArray.length; i++) { for(int n = 0; n < englishArray.length; n++) { if(userArray[i] == englishArray[n]) { holdList.add(n); } } } // append all morse codes associated // with the english array indexes to the StringBuilder object. for(int i = 0; i < holdList.size(); i++) { holdBuilder.append(morseCode[holdList.get(i)]); } // convert that object to a string and print it out. String moCode = holdBuilder.toString(); outputField.setText(moCode); }//GEN-LAST:event_inputConfirmButtonActionPerformed public static void main(String args[]) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() {
  • 7. new MorseCodeConverter().setVisible(true); } }); } private javax.swing.JButton inputConfirmButton; private javax.swing.JLabel inputLabel; private javax.swing.JPanel mainWindowContainer; private javax.swing.JTextField outputField; private javax.swing.JLabel outputLabel; private javax.swing.JLabel title; private javax.swing.JTextField userSentence; }