Results 1 to 2 of 2
  1. #1
    Naxix is offline Member
    Join Date
    Jul 2011
    Posts
    13
    Rep Power
    0

    Default Cannot be resolved to a type

    Hello, i'm trying to code a window with some Comboboxes and buttons,
    and i was trying to make a action listener for my button, and for that i made an
    innerclass in my outerclass to handle the actionlistener.

    What i did was:
    Java Code:
    AppStart ap = new AppStart();
    ap.HandlerClass handler = new ap.HandlerClass();
    AppStart being my class name, and HandlerClass my innerclass,
    the error is as followed:

    Java Code:
    ap cannot be resolved to a type
    ap cannot be resolved to a type
    Here is all the code if needed:
    Java Code:
    package ComputerConfig;
     
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
     
    public class AppStart{
        final static boolean shouldFill = true;
        final static boolean shouldWeightX = true;
        final static boolean RIGHT_TO_LEFT = false;
        
        private static JButton button;
        
        final public static String[] CPU = {
    			"Intel Core i5 2500K Sandy brigde", "Intel Core i7 3820", 
    			"Intel Core i7 2600K Sandy Bridge", "Intel Core i7 2700K Sandy Brigde", 
    			"Intel Core i7 3930K", "AMD FX-8150", "AMD FX-4100", "AMD Phenom II X6 1045T"
    		};
        
        final public static String[] Bundkort = {
    			"ASUS P8Z68-V LX", "ASUS P8Z68-V PRO/GEN3", "ASUS SABERTOOTH X79"
    		};
     
        public static void addComponentsToPane(Container pane) {
            if (RIGHT_TO_LEFT) {
                pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
            }
     
        JComboBox comboBox = new JComboBox();
        JLabel label = new JLabel();
        AppStart ap = new AppStart();
        ap.HandlerClass handler = new ap.HandlerClass();
        pane.setLayout(new GridBagLayout());
        GridBagConstraints c = new GridBagConstraints();
        if (shouldFill) {
    
        c.fill = GridBagConstraints.NONE;
        }
        
        label.setBorder(BorderFactory.createTitledBorder("Panel border"));
        //Label for Title
        label = new JLabel("Hvilke dele skal din pc have");
        c.fill = GridBagConstraints.NONE;
        c.insets = new Insets(10,10,0,0);
        c.gridx = 2;
        c.gridy = 0;
        pane.add(label, c);
        
      //Label for Motherboard
        label = new JLabel("Bundkort:");
        c.fill = GridBagConstraints.LINE_START;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.gridx = 0;
        c.gridy = 1;
        c.gridwidth = 1;
        pane.add(label, c);
        
        //ComboBox for Motherboard
        comboBox = new JComboBox(Bundkort);
        comboBox.setSelectedIndex(-1);
        c.fill = GridBagConstraints.NONE;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.ipadx = 70;
        c.gridx = 2;
        c.gridy = 1;
        pane.add(comboBox, c);
        
        //Label for CPU
        label = new JLabel("Processor:");
        c.fill = GridBagConstraints.LINE_START;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.gridx = 0;
        c.gridy = 2;
        c.gridwidth = 1;
        pane.add(label, c);
        
        //ComboBox for CPU
        comboBox = new JComboBox(CPU);
        comboBox.setSelectedIndex(-1);
        c.fill = GridBagConstraints.NONE;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.ipadx = 30;
        c.gridx = 2;
        c.gridy = 2;
        pane.add(comboBox, c);
        
        button = new JButton("Update");
        c.fill = GridBagConstraints.LINE_START;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.gridx = 2;
        c.gridy = 3;
        pane.add(button, c);
        button.addActionListener(handler);
        
        label = new JLabel("Pris: 0 kr.");
        c.fill = GridBagConstraints.LINE_START;
        c.anchor = GridBagConstraints.FIRST_LINE_START;
        c.gridx = 0;
        c.gridy = 3;
        c.gridwidth = 1;
        pane.add(label, c);
        
        }
        
        public class HandlerClass implements ActionListener{
        	public void actionPerformed(ActionEvent e){
        		
        	}
        }
     
        private static void createAndShowGUI() {
    
            JFrame frame = new JFrame("GridBagLayoutDemo");
            JPanel panel = new JPanel();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            panel.setBorder(BorderFactory.createTitledBorder("Computer Config"));
            frame.setContentPane(panel);
     
            addComponentsToPane(frame.getContentPane());
     
            frame.pack();
            frame.setVisible(true);
        }
     
        public static void main(String[] args) {
    
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
                }
            });
            
    
        }
    
    }
    I'm not sure if i'm doing it all wrong, or if there is an easier way.

    -Naxix

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Cannot be resolved to a type

    Moved from New to Java

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

Similar Threads

  1. HttpServlet Cannot be resolved to a type
    By chizbox in forum Eclipse
    Replies: 3
    Last Post: 07-01-2012, 05:09 PM
  2. Error: ConsoleProgram cannot be resolved to the type
    By petrohamadi in forum New To Java
    Replies: 5
    Last Post: 06-13-2011, 10:49 PM
  3. Replies: 4
    Last Post: 12-13-2010, 10:00 PM
  4. Filter cannot be resolved to a type??
    By Harrie_KalaChakra in forum Eclipse
    Replies: 1
    Last Post: 01-15-2010, 09:19 AM
  5. Replies: 1
    Last Post: 12-18-2007, 10:41 AM

Posting Permissions

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