Help with GUI layout

class, interface, or enum expected error

Page 1 of 1

3 Replies - 3929 Views - Last Post: 03 February 2008 - 06:46 PM Rate Topic: -----

#1 Reason4  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 20-December 07

Help with GUI layout

Posted 02 February 2008 - 11:41 PM

I suspect that I have some components in the wrong place in the program I am working on, but am not sure. The only compile code error I get right now is "class, interface, or enum expected" at line 80.

Could someone take a look and see why I get the above error -- and comments are welcome about other errors you may spot.

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/* FrameDemo.java requires no other files. */


public class FrameDemo3 extends JFrame
{
		 public static void main(String[] args)
	{

	DataOutputStream output;//Per text, p. 8.13, declare output stream
}
	/**
	 * Create the GUI.
	 */

	private static void createAndShowGUI()
	{ //Create and set up the window.

		JFrame frame = new JFrame("Week 3 Program (PRG/421) - CM");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	   //JLabel emptyLabel = new JLabel("Carole McMillen");
	   //emptyLabel.setPreferredSize(new Dimension(100, 150));
	   //frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

	   JPanel firstRow = new JPanel();


		//Display the window.
		frame.setSize(400, 400); //This sets the frame size.
		frame.setLocationRelativeTo(null); //This sets the frame location to the center of the screen.
		frame.setVisible(true); //This means you can see the frame.
	}
//}//*************************

private void initializeComponent()
	{
		JPanel first = new JPanel();
				jLabel2 amt = new JLabel();
				jLabel3 amtfield = new JLabel();
				jLabel4 tlabel = new JLabel();
				jLabel5 ttext = new JLabel();
				jCheckBox1 ask = new JCheckBox();
				jTextField1 t1 = new JTextField();
				jTextField2 t2 = new JTextField();
				jTextArea1 t3 = new JTextArea();
				jComboBox1 box1 = new JComboBox();
				jComboBox2 box2 = new JComboBox();
		contentPane getinfo = (JPanel)this.getContentPane();

		jLabel2.setText("  Loan Term (Yrs):");
		jLabel3.setText("  Enter a loan amount (no commas or $ please):");
		jLabel4.setText("  Interest Rate (%):");
		jLabel5.setText("  Monthly Payment on this loan is: ");
		jCheckBox1.setText("  Click here to see an amortization of your chosen loan.");
		jCheckBox1.setSelected(true);


			jCheckBox1.addItemListener(new ItemListener()
			{
				public void itemStateChanged(ItemEvent e)
				{
					jCheckBox1_itemStateChanged(e);
				}
			});

}
//*******************

	public static void main(String[] args)
	{
	   createAndShowGUI();
	}
   }
}
}



Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Help with GUI layout

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Help with GUI layout

Posted 03 February 2008 - 03:31 AM

There were more errors, note that Java is a case sensitive language, and you should declare the object by writing the class name and then instantiate it.

Here,it compiles now, but it is not finished:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/* FrameDemo.java requires no other files. */


public class FrameDemo3 extends JFrame
{
	  

	DataOutputStream output;//Per text, p. 8.13, declare output stream

	/**
	 * Create the GUI.
	 */

	private static void createAndShowGUI()
	{ //Create and set up the window.

		JFrame frame = new JFrame("Week 3 Program (PRG/421) - CM");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	   //JLabel emptyLabel = new JLabel("Carole McMillen");
	   //emptyLabel.setPreferredSize(new Dimension(100, 150));
	   //frame.getContentPane().add(emptyLabel, BorderLayout.CENTER);

	   JPanel firstRow = new JPanel();


		//Display the window.
		frame.setSize(400, 400); //This sets the frame size.
		frame.setLocationRelativeTo(null); //This sets the frame location to the center of the screen.
		frame.setVisible(true); //This means you can see the frame.
	}
//}//*************************

private void initializeComponent()
	{
		JPanel first = new JPanel();
				JLabel amt = new JLabel();
				JLabel amtfield = new JLabel();
				JLabel tlabel = new JLabel();
				JLabel ttext = new JLabel();
				JCheckBox ask = new JCheckBox();
				JTextField t1 = new JTextField();
				JTextField t2 = new JTextField();
				JTextArea t3 = new JTextArea();
				JComboBox box1 = new JComboBox();
				JComboBox box2 = new JComboBox();
		JPanel getinfo = (JPanel)this.getContentPane();

		amt.setText("  Loan Term (Yrs):");
		amtfield.setText("  Enter a loan amount (no commas or $ please):");
		tlabel.setText("  Interest Rate (%):");
		ttext.setText("  Monthly Payment on this loan is: ");
		ask.setText("  Click here to see an amortization of your chosen loan.");
		ask.setSelected(true);


			ask.addItemListener(new ItemListener()
			{
				public void itemStateChanged(ItemEvent e)
				{
					//ask_itemStateChanged(e);
				}
			});

}
//*******************

	public static void main(String[] args)
	{
	   createAndShowGUI();
	}
   }

Was This Post Helpful? 0
  • +
  • -

#3 Reason4  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 20-December 07

Re: Help with GUI layout

Posted 03 February 2008 - 11:02 AM

Thank you for the tip, and it does help. I did change font case on the "j's", changing all of them to caps and, when that didn't work, all to lower case. It didn't seem to matter. Obviously I do have other issues.

Can you direct me to a moron level explanation of instantiating a class? I thought I had that taken care of in the code I submitted. However, since none of the components will display, obviously I have not. It really is frustrating to be so dense!

[quote name='PennyBoki' date='3 Feb, 2008 - 03:31 AM' post='304201']
There were more errors, note that Java is a case sensitive language, and you should declare the object by writing the class name and then instantiate it.
Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Help with GUI layout

Posted 03 February 2008 - 06:46 PM

I recommend you take a look at the Java tutorials where you'll find some GUI tutorials.

when I said case sensitive I meant that: jPanel is different tham JPANEL nd different than JPanel and so on.... the actual name of the class is JPanel. So be careful with that.

this is a declaring an object:

JPanel x;

this is instantiating the object:

x= new JPanel();


the name of the class is JPanel, the name of the object is x.

This post has been edited by PennyBoki: 03 February 2008 - 06:50 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1