Programming and Problem Solving with Java

(やまだぃちぅ) #1
423

outPane = out.getContentPane();
out.setSize( 300 , 200 );
out.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
outPane.setLayout(new GridLayout( 0 , 1 ));
price = 30 ;
cost = price * LBS;
ch = 'A';
outPane.add(newJLabel("Cost is "));
outPane.add(newJLabel(""+ cost));
outPane.add(newJLabel("Price is " + price + "Cost is "+ cost));
outPane.add(newJLabel("Grade "+ ch + " costs "));
outPane.add(newJLabel(""+ cost));
out.setVisible(true);
}
}

3.To use each of the following statements, a Java application must importwhich
package(s)?
a.outPane.add(new JLabel("x"));
b.private static classButtonHandler implementsActionListener
c. outPane.setLayout(new GridLayout( 0 , 2 ));


4.Given the statements


String heading;
String str;

heading = "Exam Preparation Exercises";
what is the output of each of the following code segments?
a.outPane.add(newJLabel(""+ heading.length()));
b.outPane.add(newJLabel(heading.substring( 6 , 16 )));
c. outPane.add(newJLabel(""+ heading.indexOf("Ex")));

5.Name three kinds of objects that can be contained in the content pane of a
JFrameobject.


6.What are the steps in adding a data entry field to the content pane of a JFrame
object in Java?


7.What determines the amount of information in a prompt?


8.(True or False?) A JPanelcan hold just one user interface element.

Free download pdf