0% found this document useful (0 votes)
59 views3 pages

Quiz2 CS CS151 141 1 22

This document is a quiz for a computer science course that contains a question asking students to complete code to reproduce a GUI interface. The interface allows a user to control a "Display Light" by pressing buttons to change the light color, and displays the active light in a label. The code skeleton provided is for a class that creates the GUI elements like buttons and labels, adds them to panels, and needs to be completed with event handling code to update the active light label when a button is pressed. The question asks students to complete the code and submit the Java file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views3 pages

Quiz2 CS CS151 141 1 22

This document is a quiz for a computer science course that contains a question asking students to complete code to reproduce a GUI interface. The interface allows a user to control a "Display Light" by pressing buttons to change the light color, and displays the active light in a label. The code skeleton provided is for a class that creates the GUI elements like buttons and labels, adds them to panels, and needs to be completed with event handling code to update the active light label when a button is pressed. The question asks students to complete the code and submit the Java file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Al Imam Mohammad Ibn Saud Islamic University

College of Computer and Information Sciences


Computer Science Department
CS141 and CS151 – Quiz 2
(13/07/1443 - 15/02/2022, 8:25 AM, 30 minutes, 5 marks)

Student Name:

Student ID:
Course Code:
Section No.:

Instructions:
1. Write your answers directly on the question sheets. Use the ends of the question
pages for rough work or if you need extra space for your answer.
2. If information appears to be missing from a question, make a reasonable
assumption, state your assumption, and proceed.

Page 1 of 3

Imam University | CCIS | Doc. No. 006-02-20170316


Question 1: To be answered in (15) Minutes / 2.5 Marks

A user can control the Display light in the application by pressing on the buttons at the
top of the main Jframe (using FlowLayout). When a button is pressed, the label ‘activeLight’ on
the right of the label "Display Light" (both labels are inside a panel that uses Flowlayout)
changes according to the corresponding light. The default text of activeLight is "Green".

Complete the following code skeleton (next page) to reproduce the same interface and
interaction using Java Swing/Awt libraries and event handling components. Upload your java
file or compress and upload it.

Page 2 of 3

Imam University | CCIS | Doc. No. 006-02-20170316


import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class GraphicTest {


public static void main(String[] args) {
// fill in code here
}
}
// Complete the missing parts in Tlight class for GUI
// Class declaration part (0.5 pt)

class ChangeLight { // you must correct the class declaration


// Components declaration and instantiation
JPanel lights = new JPanel();
JPanel display = new JPanel();
JLabel disLabel = new JLabel("Display Light:");
JLabel activeLight = new JLabel("Green");

JButton green = new JButton("Green");


JButton yellow = new JButton("Yellow");
JButton red = new JButton("Red");

public ChangeLight() {
//fill in the missing code under here,
//all components and panels have been
//declared previously.

// set other properties of JFrame


setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 150);
setTitle("GUI Example");
}

@Override
public void actionPerformed(ActionEvent ae) {
// complete handling the events and setting the text of the activeLight label to
// the corresponding light

}
}

Page 3 of 3

Imam University | CCIS | Doc. No. 006-02-20170316

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy