Exercise: Advanced Programming (Chapter 1 and 2)
Exercise: Advanced Programming (Chapter 1 and 2)
Design a GUI using Swing that accepts a full name and parse it to FName, Mname and LName on a
button click (Button Parse).
Hint: declare a string variable and read the full name to it. Then use susbstring function of string class to
split the provided full name in to three components.
Answer:
String x=txtFullName.getText();
txtFname.setText(y[0]);
txtMname.setText(y[1]);
txtLName.setText(y[2]);
}
2) Write a program that accept a word from a text field and add it to the text area as shown in the figure
below on button Add click. Note that you should have to append it to the existing word while adding the
new one. Use Array List to store all the data.
String x=txtInput.getText();
alldata.add(x);
txtArea.setText("");
for(String i:alldata)
txtArea.append(i+'\n');
Instruction:
On button Add click your program has to both the Afaan Oromo text the translated one to a textfile
(dictionary.text).
For instance if you enter Saree, and Dog, on button Add click the new input will be added as follows;
Saree_Dog
String x=jTextField1.getText();
String y=jTextField2.getText();
String xy=x+"_"+y+'\n';
try {
Writer wr = new FileWriter("C:\\Users\\gaddisa\\Desktop\\dictionary.txt",true);
wr.write(xy);
wr.close();
String x=jTextField1.getText();
BufferedReader reader;
Boolean isfound=false;
try {
String line=reader.readLine();
while(line!=null)
if(stringParts[0].equals(x))
jTextField2.setText(stringParts[1]);
isfound=true;
break;
line=reader.readLine();
if(!isfound)
{ JFrame f=new JFrame();
reader.close();