fall2004quiz2sol

fall2004quiz2sol - 1.00 Introduction to Computers and...

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

View Full Document Right Arrow Icon
1.00 Introduction to Computers and Engineering Problem Solving Quiz 2 / November 5, 2004 Name: Email Address: TA: Section: 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. Question Points Question 1 / 10 Question 2 / 30 Question 3 / 30 Question 4 / 30 Extra Credit / 10 Total / 100 1.00 Quiz 2 1/12 Fall 2004
Background image of page 1

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

View Full DocumentRight Arrow Icon
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 1.00 Quiz 2 2/12 Fall 2004
Background image of page 2
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); } } 1.00 Quiz 2 3/12 Fall 2004
Background image of page 3

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

View Full DocumentRight Arrow Icon
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? public class MyApplication ___
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

fall2004quiz2sol - 1.00 Introduction to Computers and...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online