/***************************************************************/ /* Program Name: Lab 2 Experiment Code */ /* */ /* */ /* Program Overview: */ /* Sample code for Lab 2 */ /* */ /* Input: */ /* There is no user input to this program. */ /* */ /* */ /***************************************************************/ import java.awt.*; import javax.swing.*; public class Lab2ExperimentCode extends JFrame { Font myFont = new Font("Times",Font.ITALIC,14); Image img; ImageIcon imgIcon; JLabel imageL; JLabel label1 = new JLabel("Label1"); JLabel passwdLabel = new JLabel("Password:",Label.RIGHT); JTextField password = new JTextField(10); JCheckBox probation = new JCheckBox("Probation?"); JButton cancel = new JButton("Cancel"); JTextArea comments = new JTextArea("Will it wordwrap? Nope!\nThis appears on the next line.",5,8); DefaultListModel list = new DefaultListModel(); JList myList = new JList(list); JComboBox myChoice = new JComboBox(); public static void main(String args[]) { // Construct the frame new Lab2ExperimentCode(); } public Lab2ExperimentCode() { // set properties of individual widgets label1.setBackground(Color.pink); label1.setFont(myFont); label1.setSize(80,40); label1.setLocation(200,200); passwdLabel.setBackground(Color.green); passwdLabel.setForeground(Color.blue); passwdLabel.setFont(myFont); // add items to List widget list.add(0,"Potatoes"); list.add(1,"Green Beans"); list.add(2,"Okra"); list.add(3,"Squash"); list.add(4,"Asparagus"); list.add(5,"Corn"); // add items to Choice widget myChoice.addItem("Soccer"); myChoice.addItem("Football"); myChoice.addItem("Baseball"); // read and get the imageL img = Toolkit.getDefaultToolkit().getImage("images/ss.jpg" ); imgIcon = new ImageIcon( img ); imageL = new JLabel(); imageL.setIcon( imgIcon ); // add widgets to applet add(label1); add(probation); add(passwdLabel); add(password); add(cancel); add(comments); add(myList); add(myChoice); add(imageL); setLayout(new FlowLayout()); setBounds(200,300,500,500); setVisible(true); } }