Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: GUI Java Help Please!

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default GUI Java Help Please!

    Hello All ---

    I am working on the following assignment and need a little bit of help with my code.

    Write a program that has three buttons, each displaying a different text that when pressed will display the text on the button in a text box. (For an extra challenge, have the user choose the color of the displayed text as well).

    This is my code so far.

    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.*;
    class button extends Frame
    {
    button()
    {
    TextField objTextf;
    setTitle("press the button");
    setSize(300,300);
    show();
    }
    public static void main(String[] args)
    {

    Frame objFrame;
    Button objbutton1;
    Button objbutton2;
    Button objbutton3;
    objFrame = new button();
    objbutton1 = new Button("hello");
    objbutton2 = new Button("Hola");
    objbutton3 = new Button("Guten Tag");
    objTextf = new TextField("trial");
    objbutton1.setBounds(180,150,80,50);
    objbutton2.setBounds(100,150,80,50);
    objbutton3.setBounds(20,150,80,50);
    objFrame.add(objbutton1);
    objFrame.add(objbutton2);
    objFrame.add(objbutton3);
    objFrame.add(objTextf);
    objbutton1.addActionListener(new button1Listener());
    objbutton2.addActionListener(new button2Listener());
    objbutton3.addActionListener(new button3Listener());
    }
    public class button1Listener
    {
    public void buttonpushed(ButtonEvent me)
    {
    String S = objTextf.getText();
    objTextf.setText(S);
    }
    }
    }



    I am getting the error message --- cannot find symbol - class ButtonEvent ---

    The following line is highlighted -- public void buttonpushed(ButtonEvent me)

    Any help and advice is greatly appreciated! Thank you!


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: GUI Java Help Please!

    The error message states it cannot find the class ButtonEvent. It is not part of the Java API, is it a class you have written yourself? If so where is it?

    Also, your button1Listener (etc) classes are not ActionListeners therefore cannot be added to your buttons.
    Improving the world one idiot at a time!

  3. #3
    Member coderxx0's Avatar
    Join Date
    Feb 2013
    Location
    England, UK
    Posts
    61
    My Mood
    Cool
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Re: GUI Java Help Please!

    Quote Originally Posted by Techstudent View Post
    Hello All ---

    I am working on the following assignment and need a little bit of help with my code.

    Write a program that has three buttons, each displaying a different text that when pressed will display the text on the button in a text box. (For an extra challenge, have the user choose the color of the displayed text as well).

    This is my code so far.

    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.*;
    class button extends Frame
    {
    button()
    {
    TextField objTextf;
    setTitle("press the button");
    setSize(300,300);
    show();
    }
    public static void main(String[] args)
    {

    Frame objFrame;
    Button objbutton1;
    Button objbutton2;
    Button objbutton3;
    objFrame = new button();
    objbutton1 = new Button("hello");
    objbutton2 = new Button("Hola");
    objbutton3 = new Button("Guten Tag");
    objTextf = new TextField("trial");
    objbutton1.setBounds(180,150,80,50);
    objbutton2.setBounds(100,150,80,50);
    objbutton3.setBounds(20,150,80,50);
    objFrame.add(objbutton1);
    objFrame.add(objbutton2);
    objFrame.add(objbutton3);
    objFrame.add(objTextf);
    objbutton1.addActionListener(new button1Listener());
    objbutton2.addActionListener(new button2Listener());
    objbutton3.addActionListener(new button3Listener());
    }
    public class button1Listener
    {
    public void buttonpushed(ButtonEvent me)
    {
    String S = objTextf.getText();
    objTextf.setText(S);
    }
    }
    }



    I am getting the error message --- cannot find symbol - class ButtonEvent ---

    The following line is highlighted -- public void buttonpushed(ButtonEvent me)

    Any help and advice is greatly appreciated! Thank you!
    please text wrap you code
    [CODE]
    CODE HERE
    [*CODE]

  4. #4
    Member
    Join Date
    Feb 2013
    Posts
    30
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: GUI Java Help Please!

    Thank you for the information!

Similar Threads

  1. Replies: 2
    Last Post: January 18th, 2013, 11:12 AM
  2. New to java trying a GUI
    By dj56 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 2nd, 2011, 09:26 AM
  3. JAVA GUI
    By PrgmMGF in forum Java Theory & Questions
    Replies: 6
    Last Post: December 24th, 2010, 03:50 AM