Professional Documents
Culture Documents
Lab Assignment 3 - CSF206 Advanced Java Programming, Even Sem, 2022
Lab Assignment 3 - CSF206 Advanced Java Programming, Even Sem, 2022
Lab Assignment 3 - CSF206 Advanced Java Programming, Even Sem, 2022
Instructions
In this lab assignment, you will solve problem(s) based on what you have learnt in
GUI.
There are 2 questions in this assignment.
Email/paper/other modes of submissions will not be accepted.
Upload a pdf version of this document.
You will submit (upload) this assignment in MS Teams. Name this document as
A3_AJPEVEN2022_John_Doe.pdf in case your name is John Doe. Paste your code and
snapshot of output after each question, save and upload the document.
Question 1: Write a program that has a method commonPre (String str1, String str2) that
returns the common prefix of two strings. For example, the common prefix of “distance”
and “disinfection” is “dis”. If the two strings have no common prefix, the method displays
“No common prefix”. The user should be prompted to enter two strings in JOptionPane and
display their common prefix, if any. Use JOptionPane for all inputs and outputs.
Question 2: Using FlowLayout Manager, write a program that meets the following require-
ments (see figure below):
Create a frame and set its layout to FlowLayout
Create 2 panels and add them to the frame.
Each panel contains three buttons. The panel uses FlowLayout.
Lab Assignment 3 – CSF206 Advanced Java Programming, Even Sem, 2022
Question 1 code:
package com.java;
import javax.swing.JOptionPane;
if (commonPrefix.length() > 0) {
return commonPrefix;
} else {
break;
}
}
}
if (commonPrefix.length() > 0) {
return commonPrefix;
}
return "No common prefix. :(";
}
}
OUTPUT:
Lab Assignment 3 – CSF206 Advanced Java Programming, Even Sem, 2022
Question 2 code:
Lab Assignment 3 – CSF206 Advanced Java Programming, Even Sem, 2022
package com.java;
import javax.swing.*;
import java.awt.*;
public flowlayout() {
setLayout(new FlowLayout());
this.setLayout(new FlowLayout());
panel1.setLayout(new FlowLayout());
panel2.setLayout(new FlowLayout());
this.add(panel1);
this.add(panel2);
}
Output:
Lab Assignment 3 – CSF206 Advanced Java Programming, Even Sem, 2022