Results 1 to 4 of 4

Thread: ComboBox issue

  1. #1
    mbschultz97 is offline Member
    Join Date
    May 2014
    Location
    Texas
    Posts
    73
    Rep Power
    0

    Default ComboBox issue

    Error: Main method not found in class guitest.guiTest, please define the main method as:
    public static void main(String[] args)
    or a JavaFX application class must extend javafx.application.Application
    XML Code:
    package guitest;
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    import java.util.*;
    
    public class guiTest extends JFrame{
    	
    	Hashtable<String, String[]> subItems = new Hashtable<String, String[]>();
    	String[] items = {"Color", "Shape", "Fruit"};
    	String[] subItems1 = {"Red", "Blue", "Green"};
    	String[] subItems2 = {"Circle", "Square", "Triangle"};
    	String[] subItems3 = {"Apple", "Orange", "Banana"};
    	subItems.put(items[0], subItems1);
    	subItems.put(items[1], subItems2);
    	subItems.put(items[2], subItems3);
    	
    	public guiTest() {
    		setTitle("test");
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		getContentPane().setLayout(null);
    		setSize(275,200);
    		setLocation(300,300);
    		
    		JComboBox comboBox_1 = new JComboBox();
    		comboBox_1.setBounds(10, 42, 95, 20);
    		getContentPane().add(comboBox_1);
    		
    		JComboBox comboBox = new JComboBox();
    		comboBox.setBounds(10, 11, 95, 20);
    		getContentPane().add(comboBox);
    		comboBox.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e) {
    				String item = (String)comboBox.getSelectedItem();
    				Object o = subItems.get(item);
    				if (o == null){
    					comboBox_1.setModel(new DefaultComboBoxModel());
    				}
    				else{
    					comboBox_1.setModel(new DefaultComboBoxModel((String[])o));
    				}
    			}
    		});
    		
    		
    	}
    	public static void main(String[] args){
    		guiTest test = new guiTest();
    		test.setVisible(true);
    	}
    }

  2. #2
    mbschultz97 is offline Member
    Join Date
    May 2014
    Location
    Texas
    Posts
    73
    Rep Power
    0

    Default Re: ComboBox issue

    lines 16-18 the . , and ; are underlined in red in eclipse

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: ComboBox issue

    In the class body, you can have only declarations and declaration-cum assignment statements. All other statements must be within a constructor, method or initializer.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    mbschultz97 is offline Member
    Join Date
    May 2014
    Location
    Texas
    Posts
    73
    Rep Power
    0

    Default Re: ComboBox issue

    Quote Originally Posted by DarrylBurke View Post
    In the class body, you can have only declarations and declaration-cum assignment statements. All other statements must be within a constructor, method or initializer.

    db
    thanks for the help it works now :)

Similar Threads

  1. Replies: 2
    Last Post: 06-22-2015, 09:21 AM
  2. dynamically related combobox in jsp issue
    By ppreeti in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 03-18-2014, 04:24 PM
  3. Problem: Fill a comboBox from another combobox
    By Ridha in forum AWT / Swing
    Replies: 2
    Last Post: 03-08-2013, 02:34 PM
  4. Regular Expression issue and setName() method issue
    By geforce in forum New To Java
    Replies: 2
    Last Post: 01-30-2012, 03:33 AM
  5. combobox
    By dina in forum AWT / Swing
    Replies: 7
    Last Post: 05-11-2011, 05:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •