Welcome to Dream.In.Code
Become a Java Expert!

Join 150,369 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,755 people online right now. Registration is fast and FREE... Join Now!




Help with GUI layout

 
Reply to this topicStart new topic

Help with GUI layout, class, interface, or enum expected error

Reason4
2 Feb, 2008 - 10:41 PM
Post #1

New D.I.C Head
*

Joined: 20 Dec, 2007
Posts: 29

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.

CODE

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!
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Help With GUI Layout
3 Feb, 2008 - 02:31 AM
Post #2

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
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:

CODE

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();
    }
   }



User is offlineProfile CardPM
+Quote Post

Reason4
RE: Help With GUI Layout
3 Feb, 2008 - 10:02 AM
Post #3

New D.I.C Head
*

Joined: 20 Dec, 2007
Posts: 29

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.


User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Help With GUI Layout
3 Feb, 2008 - 05:46 PM
Post #4

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
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: 3 Feb, 2008 - 05:50 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 02:12PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month