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 6 of 6

Thread: Help With JComboBox

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Help With JComboBox

    package Components;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JVideos extends JPanel implements ActionListener
    {
    	JLabel explainSelector = new JLabel("Please use the drop down menu\nto select a movie to rent.");
     
     
     
    	public JVideos()
    	{
    		String[] movieStrings = {"Reservoir Dogs", "Memento", "Oldboy", "Inglorious Bastards", "Snatch",
    					 "Slumdog Millionaire", "District 9", "Ip Man", "Gran Torino", "The Matrix"};
    		JComboBox movieChoice = new JComboBox(movieStrings);
    		JPanel 	panel = new JPanel();
    		JLabel greenBox = new JLabel("Welcome to Greenbox");
    		movieChoice.setSelectedIndex(0);
    		movieChoice.addActionListener(this);
    		panel.add(greenBox);
    		panel.add(explainSelector);
    		panel.add(movieChoice);
    		this.add(panel);
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setLayout(new FlowLayout());
     
    	}
     
     
     
     
    	public void main(String[] args)
    	{
    		JVideos aFrame = new JVideos();
    		final int WIDTH = 400;
    		final int HEIGHT = 600;
    		aFrame.setSize(WIDTH, HEIGHT);
    		aFrame.setVisible(true);
    	}
    }
    the errors im getting...
    Components.JVideos is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    cannot find symbol method setDefaultCloseOperation(int)


    This is the first Im working with comboboxes so my questions are
    1.How do i get past these two error so that I can build error free?
    2.What else would I need so that my I can have a GUI output with that information in it?

    The panel parts Im not sure if I need, I just pulled it from another example hoping that it would work, before I had simply added those label using
    add(explainSelector); . . . etc
    if those lines work any better or would help to clean up the code to make it easier to work with I would like to switch back to that.

    I have the listener in there so that I can later give the user further information once they select a film they would like to rent. I'll try to figure out how to create an event after they have selected a movie, any help there would also be much appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,033
    Thanks
    52
    Thanked 2,278 Times in 2,249 Posts

    Default Re: Help With JComboBox

    Components.JVideos is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener
    When you code this implements clause:
    ... implements ActionListener
    you are promising the compiler that you will define an actionPerformed() method.
    The compile can't find the definition and gives the above error message.
    Either define the method or remove the implements clause.

    cannot find symbol method setDefaultCloseOperation(int)
    The compiler can not find the definition for this method in the class it is used in, so it gives the error message.
    What class is the method in? Is there an instance of that class that you should use to call that method?


    The code looks like it was cut and pasted from some other places and has a lot of missing parts or parts that do not go together.
    You should take a look at the tutorial on how to build a Swing program before messing any more with this.
    http://docs.oracle.com/javase/tutori...ing/index.html
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help With JComboBox

    kinda was cut and pasted >.<
    I had originally had the code outside the method and after seeing examples of others code I moved much of my code inside of the JVideos method. It would build before but after seeing others work I thought maybe it needed to be inside the method to call it in to play elsewhere a much easier way. Ill look through your suggestion, thanks!
    I'll clean up the code more and repost if I get it working or get new errors I'll update the post in case anyone else finds it useful once I have working code.

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help With JComboBox

    package Components;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class JVideos extends JFrame implements ActionListener
    {
    	JLabel explainSelector = new JLabel("Please use the drop down menu\nto select a movie to rent.");
     
     
    	public void actionPerformed(java.awt.event.ActionEvent e)
    	{
    	}
     
    	public JVideos()
    	{	
    		super("Greenbox Rentals");
    		String[] movieStrings = {"Reservoir Dogs", "Memento", "Oldboy", "Inglorious Bastards", "Snatch",
    					 "Slumdog Millionaire", "District 9", "Ip Man", "Gran Torino", "The Matrix"};
    		JComboBox movieChoice = new JComboBox(movieStrings);
    		JLabel greenBox = new JLabel("Welcome to Greenbox");
     
    		add(greenBox);
    		add(explainSelector);
    		add(movieChoice);
    		movieChoice.setSelectedIndex(0);
    		movieChoice.addActionListener(this);
    		setLayout(new FlowLayout());
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    	}
     
     
     
     
    	public void main(String[] args)
    	{
    		JVideos aFrame = new JVideos();
    		final int WIDTH = 400;
    		final int HEIGHT = 600;
    		aFrame.setSize(WIDTH, HEIGHT);
    		aFrame.setTitle("Greenbox Videos");
    		aFrame.setVisible(true);
    	}
    }

    okay, I've cleaned up my code and as far as I can tell it should run. It build but the when I run it so that my GUI shows up I am getting

    java.lang.NoSuchMethodError: main
    Exception in thread "main"
    Process completed.


    and nothing is actually happening

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,033
    Thanks
    52
    Thanked 2,278 Times in 2,249 Posts

    Default Re: Help With JComboBox

    The java command require a main() method with these attributes on the class that it starts:
    public static void
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    Olympaphibian89 (December 6th, 2012)

  7. #6
    Junior Member
    Join Date
    Sep 2012
    Posts
    14
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Help With JComboBox

    wow... thank you so much, haha. its always something simple

    --- Update ---

    wohoo, i can finally begin on the rest of the project where clicking these things actually does something!

Similar Threads

  1. JComboBox
    By ikocijan in forum What's Wrong With My Code?
    Replies: 9
    Last Post: July 16th, 2012, 06:35 AM
  2. Getting the Selected Value in JComboBox
    By aStudentofJava in forum AWT / Java Swing
    Replies: 2
    Last Post: March 9th, 2012, 09:35 AM
  3. JComboBox
    By SV25 in forum Java Theory & Questions
    Replies: 2
    Last Post: April 20th, 2011, 08:47 AM
  4. [SOLVED] JCombobox help
    By sman36 in forum AWT / Java Swing
    Replies: 10
    Last Post: August 11th, 2010, 04:11 AM
  5. JComboBox
    By nasi in forum AWT / Java Swing
    Replies: 1
    Last Post: April 29th, 2010, 08:40 AM

Tags for this Thread