
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

COP3330.01, Fall 2001 Assigned: 9/4, 2001 S. Lang Assignment #1 Due: 9/11 in class The purpose of this assignment is to become familiar with the Java programming environment you will be using for this course, which could be either jdk1.3.1 or JBuilder. You are supposed to prepare the following two Java programs (copy and paste), make the suggested modifications, and answer the questions reporting the results. To turn in your assignment, write the answers on paper and indicate which Java environment (jdk or JBuilder) you used for your answers. Example 1. // The hello-world example class Hello { public static void main(String args[]) { System.out.println("Hello World!"); } } Example 2. // A swing example import javax.swing.; import java.awt.; import java.awt.event.; public class HelloApp extends JFrame { public HelloApp() { super("An Application"); Container contentPane = getContentPane(); Icon icon = new ImageIcon("UCFLogo.gif"); / the gif file UCFLogo.gif is posted at the course website http://www.cs.ucf.edu/courses/cop3330.01-fall2001/homework/UCFLogo.gif / JLabel label = new JLabel("Go UCF!", icon, SwingConstants.CENTER); contentPane.add(label, BorderLayout.CENTER); } public static void main(String args[]) { final JFrame f = new HelloApp(); f.setBounds(100, 100, 300, 250); f.setVisible(true); f.setDefaultCloseOperation(DISPOSE_ON_CLOSE); f.addWindowListener(new WindowAdapter() { public void windowClosed(WindowEvent e) {System.exit(0);} }); } } Now answer each of the following questions using the program of Example 1: (1) Show the changes you need to do in order to display the words Hello and World in two separate lines. (2) Drop the word public in the line for the main method and report any error when compile the program. (3) Save the file as Test.java and report any error when compile the program. (4) Save the file as hello.java (with lowercase h) and report any error when compile the program Answer each of the following questions using the program of Example 2: (5) Drop the import java javax.swing. line and report any error when compile. (6) Drop the import java.awt.event.* line and report any error when compile. (7) Can you run several windows of Example2 at the same time (i.e., keep several open on the screen)? How do you do this? (8) What is the effect of changing BorderLayout.CENTER to BorderLayout.SOUTH? (9) List two other operations (besides closing) you can do to the window when running the program. (10) What is the effect if the gif file is not located in the directory where the program is run from?