1.Screen shot :
- Start.
- When you click on JCheckBox. The text on JLabel is changed.
- When you click on JButton. The text on JLabel is changed.
- When you click on JRadioButton, the text changes again.
Here is part of the code. You can implement interface or extend class after the
class declaration.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ButtonTest extends JFrame
{
// your codes
public ButtonTest() {
// your codes
}
// your codes
public static void main(String[] args) {
JFrame f = new ButtonTest();
f.setSize(200,100);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
2.
A yellow circle with diameter 20 shows up for a single click.
A green square with side length 20 shows up for a double click.

Here is part of the code. You can implement interface or extend class after the
class declaration.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ClickTest extends JFrame
{
// your codes
public ClickTest() {
// your codes
}
public void paint(Graphics g) {
// your codes
}
// your other codes
public static void main(String[] args) {
JFrame f = new ClickTest();
f.setSize(200,200);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
3.
What is the output of the following program?
import java.util.*;
public class VectorTest {
public static void main(String[] args) {
Vector v = new Vector();
v.add("Java");
v.add(new Integer(10));
System.out.println(v);
v.add(new Double(5.2));
v.add(1, "PIC");
System.out.println(v);
v.set(2, new Integer(7));
System.out.println(v);
System.out.println(v.indexOf("Java"));
}
}
4.
Write a method Vector bigger(Vector v, int num)
returns a Vector consists of Integer bigger than
num.
Notice that not all the elements in Vector v are
Integer.
Hint: Use obj instanceof Integer. The statment
returns true if obj is an instance of
Integer.
5.
Write a class extends JFrame. It has a number on it to represent the number of seconds
remaining. The number decreases by 1 every second till it reaches 0.
- At the beginning.
- After 11 seconds

The font I use is new Font("Westminster", Font.BOLD, 50).
Here is part of the code. You can implement interface or extend class after the
class declaration.
import java.awt.*;
import javax.swing.*;
public class CountdownClock extends JFrame
{
private JLabel timeLabel = new JLabel();
private int initialTime;
public CountdownClock(int initialTime) {
this.initialTime = initialTime;
timeLabel.setBackground(Color.white);
timeLabel.setForeground(Color.green.darker());
// other codes
}
// other coddes
public static void main(String[] args) {
CountdownClock clock = new CountdownClock(1000);
clock.pack();
clock.setVisible(true);
clock.setDefaultCloseOperation(EXIT_ON_CLOSE);
// start the thread
// add codes
}
}
6. Write a class, extends JFrame.
- After 28 seconds, almost half of the circle is blue.

- After 45 seconds, 3 quarters of the circle is blue.

- After one min and 5 seconds. Small portion of the circle is blue.

- The process goes forever.
Here is part of the code. You can implement interface or extend class after the
class declaration.
import java.awt.*;
import javax.swing.*;
public class Clock extends JFrame implements Runnable {
private int time = 0; // from 1 to 60
// your codes
public static void main(String[] args) {
Clock clock = new Clock();
clock.setSize(200,200);
clock.setVisible(true);
clock.setResizable(false);
clock.setDefaultCloseOperation(EXIT_ON_CLOSE);
// your codes
}
}