{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

fall04quiz2sol - 1.00/1.001 Introduction to Computers and...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1.00/1.001 Quiz 2 1/12 Fall 2004 1.00/1.001 Introduction to Computers and Engineering Problem Solving Quiz 2 / November 5, 2004 Name: Email Address: TA: Section: Question Points Question 1 / 10 Question 2 / 30 Question 3 / 30 Question 4 / 30 Extra Credit / 10 Total / 100 You have 90 minutes to complete this exam. For coding questions, you do not need to include comments, and you should assume that all necessary files have already been imported. Good luck.
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1.00/1.001 Quiz 2 2/12 Fall 2004 Question 1. True / False (10 points) 1. An event source in Swing can have more than one event listener registered with it. TRUE FALSE 2. An event listener in Swing can respond to events from more than one event source. TRUE FALSE 3. A Java class can inherit from more than one class. TRUE FALSE 4. A Java class can implement multiple interfaces. TRUE FALSE 5. Consider the following classes defined in separate Java source files: public class Animal { private int age; } public class Lion extends Animal { public Lion(int a) { age = a; } } The above code would compile. TRUE FALSE
Image of page 2
1.00/1.001 Quiz 2 3/12 Fall 2004 Question 2. Swing Components and Events (30 points) Read the following code carefully and answer questions. Please assume that all the necessary packages are imported. public class MyApplication Part 1 { private JLabel message; private Font myFont = new Font("SansSerif", Font.BOLD, 18); public MyApplication() { JButton yesButton = new JButton("Yes"); JButton noButton = new JButton("No"); message = new JLabel("IS LEARNING JAVA A FUN EXPERIENCE??"); message.setFont(myFont); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel buttonPanel = new JPanel(); buttonPanel.add(yesButton); buttonPanel.add(noButton); panel.add(message, BorderLayout.CENTER); panel.add(buttonPanel, BorderLayout.SOUTH); Container con = this.getContentPane(); con.add(panel); yesButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // // Implementation hidden // } }); noButton.addActionListener( // Part 3 ); } public static void main(String[] args) { MyApplication app = new MyApplication(); app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); app.pack(); app.setVisible(true); } }
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
1.00/1.001 Quiz 2 4/12 Fall 2004 In the above piece of code, new Java learners are asked a question as shown in Figure 1. Depending on the answer, the application either displays the message of Figure 2 on a green background or that of Figure 3 on a yellow background. Look at the code carefully and answer the questions given below: Figure 1 Figure 2 Figure 3 Part 1. The main() method invokes the object of the class MyApplication and displays it on screen. What should be the correct declaration of the class?
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern