I came across this qstn from Jxam. This qstn says, that
text fields do not adjust their size according to font changes.. I tested this with the foll. code. Whenever a TextField component is created and added and after some code when we change the font style, the TextField does adjust itself to accomodate the newer size of the chars , still maintaining the Total no of cols which was specified when it was first created. What do you all say? I think the answer shd be 1) 2) 5)
But the author says it is only 1) 2)
regds
maha anna
Question #25
Consider the following piece of code, and select the most appropriate statements. TextField t = new TextField("Hello", 20);
1. The user will be able to edit the
string.
2. The field will be 20 characters wide.
3. The text field will be same size on all platforms, since
Java is platform independent.
4. When entering text into the field, only 20 characters can be entered.
5 If the font is changed, the size of the textfield will adjust to allow 20 characters to be displayed.
Correct Answers given by author Answer 1:
Answer 2:
Answer 5 is incorrect, because text fields do not adjust their size according to font changes.
<pre>
import java.awt.*;
import java.awt.event.*;
class mframe extends Frame{
public mframe(){
super("maha");
setLayout(new FlowLayout());
TextField tf1 = new TextField("12345",10);
TextField tf2 = new TextField("12345",10);
TextField tf3 = new TextField("12345",10);
TextField tf4 = new TextField("12345",10);
tf1.setFont(new Font("Monospaced",Font.PLAIN,24));
tf2.setFont(new Font("Monospaced",Font.PLAIN,44));
tf3.setFont(new Font("Serif",Font.PLAIN,44));
tf4.setFont(new Font("Serif",Font.ITALIC,44));
add(tf1);
add(tf2);
add(tf3);
add(tf4);
tf4.setFont(new Font("Serif",Font.BOLD,84));
setSize(200,100);
setVisible(true);
}
public static void main(String args[]){
Frame f = new mframe();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
</pre>