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

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




Enhancing a Frame

 
Reply to this topicStart new topic

Enhancing a Frame

moses316
14 Sep, 2007 - 06:28 PM
Post #1

New D.I.C Head
*

Joined: 13 Sep, 2007
Posts: 26


My Contributions
Can someone tell me where I am going wrong in my code? I keep getting 10 compile errors. Any help would be appreciated.

CODE

/*
    Chapter 6:    Buttons
    Programmer:  Justin Mosley
    Date:       September 14, 2007
    Filename:    Buttons.java
    Purpose:
*/

import java.awt.*;
import java.awt.event.*;

public class Buttons extends Frame
{
    public Buttons()
    {
        //set the layout
        setLayout(new BorderLayout(20,5));

          //Add buttons
        Button Red = new Button("Red");
        Button Yellow = new Button("Yellow");
        Button Cyan = new Button("Cyan");
        Button Magenta = new Button("Magenta");
        Choice colors = new Choice();
        //Button White = new Button("White");

        add(Red, BorderLayout.NORTH);
        add(Yellow, BorderLayout.SOUTH);
        add(Cyan, BorderLayout.EAST);
        add(Magenta, BorderLayout.WEST);
        add(colors, BorderLayout.CENTER);

        //choice component colors
        colors.add("Red");
        colors.add("Yellow");
        colors.add("Cyan");
        colors.add("Magenta");

        //ItemLister for choice component
        Red.addItemListener(this);
        Yellow.addItemListener(this);
        Cyan.addItemListener(this);
        Magenta.addItemListener(this);
        colors.addItemListener(this);

        //add the ActionListener to each menu item
        Red.addActionListener(this);
        Yellow.addActionListener(this);
        Cyan.addActionListener(this);
        Magenta.addActionListener(this);
        //White.addActionListener(this);

        //override the windowClosing event
        addWindowListener(
        new WindowAdapter()
        {
        public void windowClosing(WindowEvent e)
        {
        System.exit(0);
        }
        }
        );

        }

        //This method is triggered by the user clicking in the choice component area in the center and choicing a color
        public void itemStateChanged(ItemEvent ie)
        {
        String arg = e.getActionCommand();
        if (arg == "Red")
        setBackground(Color.red);

        if (arg == "Yellow")
        setBackground(Color.yellow);

        if (arg == "Cyan")
        setBackground(Color.cyan);

        if (arg == "Magenta")
        setBackground(Color.magenta);

        if (arg == "White")
        setBackground(Color.white);
        }

        public static void main(String[] args)
        {
        // set frame properties
        Buttons f = new Buttons();
        f.setTitle("Border Application");
        f.setBounds(200,200,300,300);
        f.setVisible(true);

        }

        public void actionPerformed(ActionEvent e)
        {
        //test for button clicks
        String arg = e.getActionCommand();
        if (arg == "Red")
        setBackground(Color.red);

        if (arg == "Yellow")
        setBackground(Color.yellow);

        if (arg == "Cyan")
        setBackground(Color.cyan);

        if (arg == "Magenta")
        setBackground(Color.magenta);

        if (arg == "White")
        setBackground(Color.white);
        }

        }

User is offlineProfile CardPM
+Quote Post

girasquid
RE: Enhancing A Frame
14 Sep, 2007 - 06:54 PM
Post #2

Barbarbar
Group Icon

Joined: 3 Oct, 2006
Posts: 1,294



Thanked: 18 times
Dream Kudos: 725
My Contributions
Can you tell us which compile errors you're getting?
User is offlineProfile CardPM
+Quote Post

moses316
RE: Enhancing A Frame
14 Sep, 2007 - 07:07 PM
Post #3

New D.I.C Head
*

Joined: 13 Sep, 2007
Posts: 26


My Contributions
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:41: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Red.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:42: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Yellow.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:43: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Cyan.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:44: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Magenta.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:70: cannot resolve symbol
symbol : variable e
location: class Buttons
String arg = e.getActionCommand();
^
5 errors

Tool completed with exit code 1

User is offlineProfile CardPM
+Quote Post

moses316
RE: Enhancing A Frame
14 Sep, 2007 - 07:16 PM
Post #4

New D.I.C Head
*

Joined: 13 Sep, 2007
Posts: 26


My Contributions
The first 4 arrows should be on the period. The 5 arrow should be on the e.




QUOTE(moses316 @ 14 Sep, 2007 - 10:07 PM) *

C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:41: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Red.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:42: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Yellow.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:43: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Cyan.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:44: cannot resolve symbol
symbol : method addItemListener (Buttons)
location: class java.awt.Button
Magenta.addItemListener(this);
^
C:\CourseTechnology\sc_JavaProg_68330-01428\data\Chapter06\Buttons.java:70: cannot resolve symbol
symbol : variable e
location: class Buttons
String arg = e.getActionCommand();
^
5 errors

Tool completed with exit code 1


User is offlineProfile CardPM
+Quote Post

moses316
RE: Enhancing A Frame
16 Sep, 2007 - 06:44 AM
Post #5

New D.I.C Head
*

Joined: 13 Sep, 2007
Posts: 26


My Contributions
Still need some help on this one. Can't figure out how to correct the errors I'm getting.
User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: Enhancing A Frame
16 Sep, 2007 - 07:38 AM
Post #6

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,010



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

My Contributions
I just commented out some things, and when you are trying to use listeners you need to implement them first.
Why is ItemListener in there?
anyways, here you'll see what I commented out, compile it and run it.

CODE

/*
    Chapter 6:    Buttons
    Programmer:  Justin Mosley
    Date:       September 14, 2007
    Filename:    Buttons.java
    Purpose:
*/

import java.awt.*;
import java.awt.event.*;

public class Buttons extends Frame implements  ActionListener// ItemEventListener
{
    public Buttons()
    {
        //set the layout
        setLayout(new BorderLayout(20,5));

          //Add buttons
        Button Red = new Button("Red");
        Button Yellow = new Button("Yellow");
        Button Cyan = new Button("Cyan");
        Button Magenta = new Button("Magenta");
        Choice colors = new Choice();
        //Button White = new Button("White");

        add(Red, BorderLayout.NORTH);
        add(Yellow, BorderLayout.SOUTH);
        add(Cyan, BorderLayout.EAST);
        add(Magenta, BorderLayout.WEST);
        add(colors, BorderLayout.CENTER);

        //choice component colors
        colors.add("Red");
        colors.add("Yellow");
        colors.add("Cyan");
        colors.add("Magenta");

        //ItemLister for choice component
        Red.addActionListener(this);
        Yellow.addActionListener(this);
        Cyan.addActionListener(this);
        Magenta.addActionListener(this);
//        colors.addActionListener(this);

        //add the ActionListener to each menu item
        Red.addActionListener(this);
        Yellow.addActionListener(this);
        Cyan.addActionListener(this);
        Magenta.addActionListener(this);
        //White.addActionListener(this);

        //override the windowClosing event
        addWindowListener(
        new WindowAdapter()
        {
        public void windowClosing(WindowEvent e)
        {
        System.exit(0);
        }
        });
        

        }

        //This method is triggered by the user clicking in the choice component area in the center and choicing a color
       /* public void itemStateChanged(ItemEvent ie)
        {
        //String arg = ie.getActionCommand();
        if (ie.getSource().equals(Red))
        setBackground(Color.red);

        if (arg == "Yellow")
        setBackground(Color.yellow);

        if (arg == "Cyan")
        setBackground(Color.cyan);

        if (arg == "Magenta")
        setBackground(Color.magenta);

        if (arg == "White")
        setBackground(Color.white);
        }*/

        public static void main(String[] args)
        {
        // set frame properties
        Buttons f = new Buttons();
        f.setTitle("Border Application");
        f.setBounds(200,200,300,300);
        f.setVisible(true);

        }

        public void actionPerformed(ActionEvent e)
        {
        //test for button clicks
        String arg = e.getActionCommand();
        if (arg=="Red")
        setBackground(Color.red);

        if (arg == "Yellow")
        setBackground(Color.yellow);

        if (arg == "Cyan")
        setBackground(Color.cyan);

        if (arg == "Magenta")
        setBackground(Color.magenta);

        if (arg == "White")
        setBackground(Color.white);
        }

}

User is offlineProfile CardPM
+Quote Post

moses316
RE: Enhancing A Frame
17 Sep, 2007 - 05:41 PM
Post #7

New D.I.C Head
*

Joined: 13 Sep, 2007
Posts: 26


My Contributions
Thanks for the help. That worked great.





QUOTE(PennyBoki @ 16 Sep, 2007 - 10:38 AM) *

I just commented out some things, and when you are trying to use listeners you need to implement them first.
Why is ItemListener in there?
anyways, here you'll see what I commented out, compile it and run it.

CODE

/*
    Chapter 6:    Buttons
    Programmer:  Justin Mosley
    Date:       September 14, 2007
    Filename:    Buttons.java
    Purpose:
*/

import java.awt.*;
import java.awt.event.*;

public class Buttons extends Frame implements  ActionListener// ItemEventListener
{
    public Buttons()
    {
        //set the layout
        setLayout(new BorderLayout(20,5));

          //Add buttons
        Button Red = new Button("Red");
        Button Yellow = new Button("Yellow");
        Button Cyan = new Button("Cyan");
        Button Magenta = new Button("Magenta");
        Choice colors = new Choice();
        //Button White = new Button("White");

        add(Red, BorderLayout.NORTH);
        add(Yellow, BorderLayout.SOUTH);
        add(Cyan, BorderLayout.EAST);
        add(Magenta, BorderLayout.WEST);
        add(colors, BorderLayout.CENTER);

        //choice component colors
        colors.add("Red");
        colors.add("Yellow");
        colors.add("Cyan");
        colors.add("Magenta");

        //ItemLister for choice component
        Red.addActionListener(this);
        Yellow.addActionListener(this);
        Cyan.addActionListener(this);
        Magenta.addActionListener(this);
//        colors.addActionListener(this);

        //add the ActionListener to each menu item
        Red.addActionListener(this);
        Yellow.addActionListener(this);
        Cyan.addActionListener(this);
        Magenta.addActionListener(this);
        //White.addActionListener(this);

        //override the windowClosing event
        addWindowListener(
        new WindowAdapter()
        {
        public void windowClosing(WindowEvent e)
        {
        System.exit(0);
        }
        });
        

        }

        //This method is triggered by the user clicking in the choice component area in the center and choicing a color
       /* public void itemStateChanged(ItemEvent ie)
        {
        //String arg = ie.getActionCommand();
        if (ie.getSource().equals(Red))
        setBackground(Color.red);

        if (arg == "Yellow")
        setBackground(Color.yellow);

        if (arg == "Cyan")
        setBackground(Color.cyan);

        if (arg == "Magenta")
        setBackground(Color.magenta);

        if (arg == "White")
        setBackground(Color.white);
        }*/

        public static void main(String[] args)
        {
        // set frame properties
        Buttons f = new Buttons();
        f.setTitle("Border Application");
        f.setBounds(200,200,300,300);
        f.setVisible(true);

        }

        public void actionPerformed(ActionEvent e)
        {
        //test for button clicks
        String arg = e.getActionCommand();
        if (arg=="Red")
        setBackground(Color.red);

        if (arg == "Yellow")
        setBackground(Color.yellow);

        if (arg == "Cyan")
        setBackground(Color.cyan);

        if (arg == "Magenta")
        setBackground(Color.magenta);

        if (arg == "White")
        setBackground(Color.white);
        }

}



User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:35AM

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