Answer the following questions as briefly (but completely) as possible:
frame.setSize(400, 300) and
frame.setVisibile(true) (lines 9 and 12)
were swapped in the following program?
import javax.swing.*;
public class MyFrameWithComponents {
public static void main ( String [] args ) {
JFrame frame = new JFrame( "MyFrameWithComponents" );
// Add a button to the frame:
JButton okayBtn = new JButton( "OK" );
frame.add( okayBtn );
frame.setSize( 400, 300 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setLocationRelativeTo( null ); // Center frame on screen
frame.setVisible( true );
}
}
Frame
or JFrame? Frame
or JFrame?
import javax.swing.*;
public class Test extends JFrame {
public Test () {
add( new JButton( "OK" ) );
}
public static void main ( String [] args ) {
JFrame frame = new JFrame();
frame.setSize( 100, 200 );
frame.setVisible( true );
}
}
Color object? Color? new Color(400, 200, 300) new Color(10, 0, 0) new Color(200, 0, 0) Font object with the font name
Courier, size 20 points, and
style bold?
JButton btn = new JButton( "click me" ); JPanel panel = new JPanel(); panel.add( btn ); panel.add( btn ); panel.add( btn );
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
public static void main ( String [] args ) {
JFrame frame = new Test();
frame.setTitle( "Button Icons" );
frame.setSize( 200, 100 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setVisible( true );
}
public Test () {
ImageIcon usIcon = new ImageIcon( "images/us.gif" );
JButton jbt1 = new JButton( usIcon );
JButton jbt2 = new JButton( usIcon );
JPanel p1 = new JPanel();
p1.add( jbt1 );
JPanel p2 = new JPanel();
p2.add( jbt2 );
JPanel p3 = new JPanel();
p3.add( jbt1 );
add( p1, BorderLayout.NORTH );
add( p2, BorderLayout.SOUTH );
add( p3, BorderLayout.CENTER );
}
}
JLabel object jlblMap, write the Java
statements needed to set the label’s foreground to red, background to yellow,
mnemonic to M, tool tip text to
“Map Image”,
horizontal alignment to RIGHT, vertical alignment to
BOTTOM, horizontal text position
to LEFT, vertical text position to TOP, and
the icon text gap to 5.
MouseEvent?
Can a button fire a KeyEvent?
Can a button fire an ActionEvent?
ActionEvent?
ActionListener interface have no listener
interface adapter (that is, no ActionAdapter)?
ImageIcon from the file
image/us.gif (where image is a sub-directory
of the directory containing your Java classes)?
AudioClip from the file
anthem/us.mid (where anthem is a sub-directory
of the directory containing your Java classes)?
Email your homework assignment, by copy-and-paste (no attachments please), to (homework submission). If possible use the “text” and not the “HTML” mode of your email program. Please use the subject similar to “Java Programming I Homework Assignment #7 Submission”, so I can tell which emails are submitted homework assignments.
Homework assignments will not be returned. Please do not send as attachments. Refer to the Homework and the Submitting Assignments sections of your syllabus for more information.
Confused? Send questions about the homework assignment to (homework questions). Please use a subject similar to “Java Programming I Homework Assignment #7 Questions” so I can tell which emails are questions about assignment quiz (and not submissions).