• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I think this qstn from Jxam is suitable for Errata.

 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree. I test your code. The result proved your answer.
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem with this type of situation is that each platform may behave differently, some following the Java "by the book" and others, differently. The cause is that the AWT uses native components and as such is at the mercy of the native windowing system which will different from a Mac to Motif (Unix), to Windows, to etc...
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maha anna:
[B]I came across this qstn from Jxam. This qstn says, that text fields do not adjust their size according to font
...
___________________
I agree. Consider the following code which changes the font size after the call to setVisible. TextFields are sized based on the font.
That one should be in Jxam errata.


 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i did some testing with this code and came up with some unexpected result...
if i set the layout to the default borderlayout at the stat , as expected only one button is shown.
if i set the layout to the gridlayout after adding the components, a grid is shown.
but if the earlier layout is kept as flowlayout and i change the layout ot borderlayout after adding the components, a very strange result comes.
the rest of the cases are predictable, but i can't understand this one. please, can anyone explain what happens?
 
Anshuman Acharya
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please somebody do respond to my previous query... and i have one to add to that..
in abhilash's quiz, th o/p of the following code...
//code
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new FlowLayout());
add(bNorth);
add(bSouth);
add(bWest);
add(bEast);
add(bCenter);
setLayout(new BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
//code ends
is given as
Attemping to compile and run the above code
5.Will compile and run cleanly, but no component is visible.
??? please explain.... why not a single button is displayed at the Center?
 
reply
    Bookmark Topic Watch Topic
  • New Topic