2 Create a streaming banner thread that moves a simple messa
2. Create a streaming banner thread that moves a simple message across a panel. The message should repeatedly enter at the right edge of the panel and exit from the left edge. Design the banner as a subclass of JPanel and have it implement the Runnable interface. That way it can be added to any user interface. One of its constructors should take a String argument that lets the user set the banner’s message.
3. Write a client/server network application based on sockets that performs the following tasks:
• In the client side application, accept a string value representing the basis for a password from the user. The string can contain letters, numbers, and special characters, but no spaces. Verify that the string is at least 6 characters long, contains at least 1 character, 1 number, and 1 special character. Look at the following info on checking for letters, number, and special characters.
Checking Character Properties
• Send the verified string to the server side application.
• In the server side application, listen for incoming requests on port 9100. Create a char array using the toCharArray method where each element contains a letter in the original string received from the client. Process the array one element at a time and generate a new password string.Send the new output string to the client side application
o If the current character is a vowel, generate 2 random consonants and place them in the output string as 1stConsonantCurrentVowel2ndConsonant
o If the current character is a consonant, place it in the output string followed by a randomly generated vowel and a randomly generated consonant
o If the current character is a number or special character, place it in the output string without any further processing
o For all letters in the new output string, randomly vary whether they are upper or lower case
o Verify that the new output string contains at least 1 upper case character and 1 lower case character. If not, regenerate the output string. For example, an input string of “cat_71” might become ceRNaptoX_71.
• In the client side application, display the new password to the user
Solution
File: Banner.java
import java.awt.FlowLayout;
import java.awt.LayoutManager;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Banner extends JPanel implements Runnable{
private static final long serialVersionUID = -7054224556130637792L;
private JLabel messageLabel; //message Label for storing message
private FlowLayout layout; //Layout of banner
public Banner(String message){ // constructor with only message as argument
super();
messageLabel = new JLabel(message); //Creating message label with message
add(messageLabel); //Add label to panel
layout = new FlowLayout(FlowLayout.LEFT, getPreferredSize().width, 0);
setLayout(layout); // Set FlowLayout for the panel
Thread thread = new Thread(this); //Create a thread
thread.setDaemon(true); //Set the thread as daemon thread
thread.start(); //Start the thread
}
public Banner(String message, LayoutManager layoutManager) { //Constuctor with arguments: message and layout
super(layoutManager);
messageLabel = new JLabel(message); // Creating message label
add(messageLabel);
layout = new FlowLayout(FlowLayout.LEFT, getPreferredSize().width, 0);
setLayout(layout); //Setting layout for panel
Thread thread = new Thread(this); //Creating thread
thread.setDaemon(true); //Set thread as daemon thread
thread.start(); //Start thread
}
@Override
public void run() {
int i = 0;
int messageWidth = messageLabel.getPreferredSize().width;
while(true){
int j = getSize().width - i; //Calculate the value of new horizontal gap between left border of panel and message label
layout.setHgap(j); //Set new horizontal gap
revalidate(); //Revalidate is required for reflecting the change
try {
Thread.sleep(30); // Time delay
} catch (InterruptedException e) {
e.printStackTrace();
}
i++;
if (j <= -1 * messageWidth)
i = 0; //Reseting value for message to reappear in right
}
}
}

