two eyes you are
Second assignment already and my face is smiling because I got to make gifs. Giftastic. The actual assignment was to practice GUI (graphic user interface, pronounced goo-ey as in slime). Requirements were to have images and labels, and that the labels are relevant to the images.
It looks a bit like this (screen shot):
but the fun part is that it is animated like this:
if you are interested here is the code:
/* Course: CS111B @ CCSF
* Section: 002
* Assignment: #2
* Date due: 2 February 2015
* Title: Many Eyes Lable Demo
*
* Program: designed and created by Becca Rose
* Based on code by: Lewis/Loftus
* Images: designed and created by Becca Rose
*
* Description:
* This is the second assignment of the CS111B course. It is a GUI
* program that displays labels and animated gifs.
*
* Steps:
* 1 - Make a frame
* 2 - assign images (reference in same folder as source code)
* 3 - make label variables
* 4 - set where labels and images are, from left to right
* 5 - make settings in panel, and add images
* 6 - link the panel to frame
*
*/
//import classes
import java.awt.*;
import javax.swing.*;
public class LabelDemo2 //name of class
{
public static void main (String[] args)
{
//make a new frame
JFrame frame = new JFrame ("Many Eyes Label Demo");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
//set all the images
ImageIcon eye1 = new ImageIcon ("eye1.gif");
ImageIcon eye2 = new ImageIcon ("eye2.gif");
ImageIcon eye3 = new ImageIcon ("eye3.gif");
ImageIcon eye4 = new ImageIcon ("eye4.gif");
JLabel label1, label2, label3, label4; //define the labels
//labels and images from left to right
label1 = new JLabel ("eyes", eye1, SwingConstants.LEFT); //text and image alignment
label1.setHorizontalTextPosition (SwingConstants.CENTER); //horizontal text
label1.setVerticalTextPosition (SwingConstants.BOTTOM); //vertical text
label2 = new JLabel ("stary eyes", eye2, SwingConstants.LEFT);
label2.setHorizontalTextPosition (SwingConstants.CENTER);
label2.setVerticalTextPosition (SwingConstants.BOTTOM);
label3 = new JLabel ("face", eye3, SwingConstants.LEFT);
label3.setHorizontalTextPosition (SwingConstants.CENTER);
label3.setVerticalTextPosition (SwingConstants.TOP);
label4 = new JLabel ("raining rainbows", eye4, SwingConstants.LEFT);
label4.setHorizontalTextPosition (SwingConstants.CENTER);
label4.setVerticalTextPosition (SwingConstants.BOTTOM);
//define panel
JPanel panel = new JPanel();
panel.setBackground (Color.white); //background colour
panel.setPreferredSize (new Dimension (780, 320)); //window size
panel.add (label1); //add all the images in to the window
panel.add (label2);
panel.add (label3);
panel.add (label4);
//get info from panel to frame
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}