Is everything running smoothly with this code, can some please review I get errors when I try to run the program. I have attached the code, as well at the picture. Name:  grapes.gif
Views: 1063
Size:  3.0 KB


Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;

public class Exercise17_09 extends JFrame {
        private ImageIcon icGrapes = new ImageIcon("C:\temp");	
        private JPanel top;
	private JPanel bottom;
	private JPanel text;
	private JPanel align;
	private JPanel txtcom;
	private JPanel lblpane;
        private JPanel lblpnl;
	private JPanel AlignPanel;
        private JLabel jlblGrapes;
        private JLabel jlbltwo;
	private JLabel jlblthree;
        private JLabel jlblfour;
	private JLabel jlblfive;
        private JComboBox jcboone;
        private JComboBox jcbotwo;
	private JComboBox jcbothree;
        private JComboBox jcbofour;




public static void main(String[] args) {
	SwingUtilities.invokeLater(new Runnable() {
		public void run() {
		Exercise17_09 inst = new Exercise17_09();
		inst.setLocationRelativeTo(null);
		inst.setVisible(true);
			}});
	}//end main
	
	public Exercise17_09() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		{
			top = new JPanel();
			getContentPane().add(top, BorderLayout.NORTH);
			top.setPreferredSize(new java.awt.Dimension(392, 122));
			
                        {
                        jlblGrapes = new JLabel("Grapes", icGrapes, SwingConstants.CENTER);
                        jlblGrapes.setPreferredSize(new java.awt.Dimension(392,122));
                        jlblGrapes.setHorizontalTextPosition(SwingConstants.CENTER);


			}
			}//end 
			
                {
			bottom = new JPanel();
			GridLayout BottomPanelLayout = new GridLayout(1, 2);
			BottomPanelLayout.setHgap(5);
			BottomPanelLayout.setVgap(5);
			BottomPanelLayout.setColumns(2);
			bottom.setLayout(BottomPanelLayout);
			getContentPane().add(bottom, BorderLayout.CENTER);
			bottom.setPreferredSize(new java.awt.Dimension(392, 130));
				
                        {
			AlignPanel = new JPanel();
			BorderLayout AlignPanelLayout = new BorderLayout();
			bottom.add(AlignPanel);
			AlignPanel.setLayout(AlignPanelLayout);
			AlignPanel.setBorder(BorderFactory.createTitledBorder(null, "Horizontal Alignment", TitledBorder.LEADING, TitledBorder.TOP));
					{
			lblpnl = new JPanel();
			GridLayout jPanel1Layout = new GridLayout(2, 1);
			jPanel1Layout.setHgap(5);
			jPanel1Layout.setVgap(5);
			jPanel1Layout.setColumns(1);
			jPanel1Layout.setRows(2);
			AlignPanel.add(lblpnl, BorderLayout.CENTER);
			lblpnl.setLayout(jPanel1Layout);
						
                        {
			jlblfive = new JLabel();
			lblpnl.add(jlblfive);
			jlblfive.setText("Horizontal");
						}
			
                        {
			jlblfour = new JLabel();
			lblpnl.add(jlblfour);
			jlblfour.setText("Vertical");
						}
					}
					
                                        {
			align = new JPanel();
			GridLayout AligncomboLayout = new GridLayout(2, 1);
			AligncomboLayout.setHgap(5);
                        AligncomboLayout.setVgap(5);
			AligncomboLayout.setColumns(1);
			AligncomboLayout.setRows(2);
			AlignPanel.add(align, BorderLayout.EAST);
			align.setLayout(AligncomboLayout);
						{
			ComboBoxModel jcboHAModel = 
			new DefaultComboBoxModel(
			new String[] { "LEFT", "CENTER", "RIGHT" });
			jcbofour = new JComboBox();
			align.add(jcbofour);
			jcbofour.setModel(jcboHAModel);
						}
				
                                                {
			ComboBoxModel jcboVAModel = 
			new DefaultComboBoxModel(
			new String[] { "TOP", "CENTER", "BOTTOM" });
			jcbothree = new JComboBox();
			align.add(jcbothree);
			jcbothree.setModel(jcboVAModel);
						}
					}
				}
			
                        {
			text = new JPanel();
			BorderLayout TextPanelLayout = new BorderLayout();
			bottom.add(text);
			text.setLayout(TextPanelLayout);
			text.setBorder(BorderFactory.createTitledBorder("Text Position"));
					
                        {
			lblpane = new JPanel();
			GridLayout Label2panelLayout = new GridLayout(2, 1);
			Label2panelLayout.setHgap(5);
			Label2panelLayout.setVgap(5);
			Label2panelLayout.setColumns(1);
			Label2panelLayout.setRows(2);
			text.add(lblpane, BorderLayout.CENTER);
			lblpane.setLayout(Label2panelLayout);
						
                        {
			jlblthree = new JLabel();
			lblpane.add(jlblthree);
			jlblthree.setText("Horizontal");
			}
						
                        {
			jlbltwo = new JLabel();
			lblpane.add(jlbltwo);
			jlbltwo.setText("Vertical");
			}
			}
			
                        {
			txtcom = new JPanel();
		        GridLayout TextComboLayout = new GridLayout(2, 1);
			TextComboLayout.setHgap(5);
			TextComboLayout.setVgap(5);
			TextComboLayout.setColumns(1);
			TextComboLayout.setRows(2);
			txtcom.setLayout(TextComboLayout);
			text.add(txtcom, BorderLayout.EAST);
			
                        {
			ComboBoxModel jcboTHAModel = 
			new DefaultComboBoxModel(
			new String[] { "LEFT", "CENTER", "RIGHT" });
			jcbotwo = new JComboBox();
			txtcom.add(jcbotwo);
			jcbotwo.setModel(jcboTHAModel);
			jcbotwo.setSelectedItem("CENTER");
		
			}

                        {
			ComboBoxModel jcboTVAModel = 
			new DefaultComboBoxModel(
			new String[] { "TOP", "CENTER", "BOTTOM" });
			jcboone = new JComboBox();
			txtcom.add(jcboone);
			jcboone.setModel(jcboTVAModel);
			jcboone.setSelectedItem("CENTER");
			}
			}
			}
                        
                        jcbofour.addItemListener(new ItemListener() {
			
                            
         public void itemStateChanged(ItemEvent e) {
            
	    String A = (String)jcbofour.getSelectedItem();
	    if(A.equals("LEFT"))	{
            jlblGrapes.setHorizontalAlignment(SwingConstants.LEFT);
						}
	    else if(A.equals("CENTER"))	{
            jlblGrapes.setHorizontalAlignment(SwingConstants.CENTER);
						}
	    else if(A.equals("RIGHT"))	{
            jlblGrapes.setHorizontalAlignment(SwingConstants.RIGHT);
						}
					}
				});
				
		jcbothree.addItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				String A = (String)jcbothree.getSelectedItem();
				if(A.equals("TOP"))	{
				jlblGrapes.setVerticalAlignment(SwingConstants.TOP);
						}
			        else if(A.equals("CENTER"))	{
				jlblGrapes.setVerticalAlignment(SwingConstants.CENTER);
						}
			        else if(A.equals("BOTTOM"))	{
				jlblGrapes.setVerticalAlignment(SwingConstants.BOTTOM);
						}
					}
				});
				
				
	   jcbotwo.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			      String A = (String)jcbotwo.getSelectedItem();
			      if(A.equals("LEFT"))	{
			      jlblGrapes.setHorizontalTextPosition(SwingConstants.LEFT);
						}
			      else if(A.equals("CENTER"))	{
			      jlblGrapes.setHorizontalTextPosition(SwingConstants.CENTER);
						}
			      else if(A.equals("RIGHT"))	{
			      jlblGrapes.setHorizontalTextPosition(SwingConstants.RIGHT);
						}
					}
				});
				
           jcboone.addItemListener(new ItemListener() {
		public void itemStateChanged(ItemEvent e) {
			String A = (String)jcboone.getSelectedItem();
			if(A.equals("TOP"))	{
			jlblGrapes.setVerticalTextPosition(SwingConstants.TOP);
						}
			else if(A.equals("CENTER"))	{
			jlblGrapes.setVerticalTextPosition(SwingConstants.CENTER);
						}
			else if(A.equals("BOTTOM"))	{
			jlblGrapes.setVerticalTextPosition(SwingConstants.BOTTOM);
						}
		}
		});
				
		}
	pack();
	setSize(400, 300);
    } catch (Exception e) {
	e.printStackTrace();
        
        

}

}

}