Thursday, September 2, 2010

ArrayOnFrame - Assignment 2 - Tuesday, August 24, 2010





/*
    Assignment 2
*/

import javax.swing.*;

public class ArrayOnFrame
{
    private static void createAndShowGUI()
    {
        int[] anArray;

        anArray = new int[10];

        anArray[0] = 100;
        anArray[1] = 200;
        anArray[2] = 300;
        anArray[3] = 400;
        anArray[4] = 500;
        anArray[5] = 600;
        anArray[6] = 700;
        anArray[7] = 800;
        anArray[8] = 900;
        anArray[9] = 1000;

        JFrame frame = new JFrame("ArrayOnFrame");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel label = new JLabel("element at index 0: "+anArray[0]);
        frame.getContentPane().add(label);

        frame.pack();
        frame.setVisible(true);
        }

        public static void main(String[]args)
        {
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
        public void run()
        {
        createAndShowGUI();
        }
        });
        }
        }

No comments:

Post a Comment