2016-12-22 2 views
0

Я хотел проверить, работает ли ActionListener в моем внутреннем фрейме, если он работает. Но внутренний класс, который реализует ActionListener, не будет читать зарегистрированную кнопку. Любые причины?JButton внутри JInternalFrame не запускает ActionListener

EmployeeFrameView

public class EmployeeFrameView extends JInternalFrame 
{ 
    JButton button; 

    public EmployeeFrameView() 
    { 
    super("AddEmployee",true,true,true,true); 
    addComponentsToPane(getContentPane()); 
    pack(); 
    setVisible(true); 
    setLocation(xOffset,yOffset); 
    } 

    private void addComponentsToPane(final Container pane) 
    { 
    final JPanel content = new JPanel(); 
    panelEmployee = new JPanel(); 

    //Add to content and set layout 
    content.setLayout(new BorderLayout()); 
    content.add(addComponentsToEmployeePanel(panelEmployee),BorderLayout.NORTH); 

    //Adding ScrollPane to Container. 
    final JScrollPane scrollPane = new JScrollPane(content, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
    pane.add(scrollPane); 
    } 

    private JPanel addComponentsToEmployeePanel(JPanel panelEmployee) 
    { 
    panelEmployee.setLayout(grid); 
    gbc.gridx = 0; 
    gbc.gridy = 1; 
    button = new JButton("Button"); 
    panelEmployee.add(button, gbc); 
    } 

    public void addAction(ActionListener l) 
    { 
    button.addActionListener(l); 
    } 
} 

EmployeeFrameController

public class EmployeeFrameController 
{ 
EmployeeFrameView theView; 

public EmployeeFrameController(EmployeeFrameView theView) 
{ 
    this.theView = theView; 

    this.theView.addAction(new addAction()); 
} 

class addAction implements ActionListener 
{ 
    @Override 
    public void actionPerformed(ActionEvent e) 
    { 
     System.out.println("Working"); 
    } 

} 

} 

Главная

public class Main 
{ 
public static void main(String[] args) 
{ 
    EmployeeFrameView employeeFrameView = new EmployeeFrameView(); 

    EmployeeFrameController employeeFrameController = new EmployeeFrameController(employeeFrameView); 
} 
} 
+0

Пожалуйста, отредактируйте свой вопрос, чтобы включить [mcve], который показывает проблему, которую вы описываете, для [пример] (http://stackoverflow.com/a/14874924/230513). – trashgod

+0

@trashgod Смотрите мой обновленный пост :) – Francisunoxx

+0

К сожалению, ваш пример неполный. Была ли для вас сеть [example] (http://stackoverflow.com/a/14874924/230513)? – trashgod

ответ

0

я не могу см. любую проблему с кодом, который вы опубликовали. Вероятно, ваша проблема находится где-то в коде, который вы здесь не включили (я бы поставил на что-то беспорядочное обращение, так как вы не включили кодификацию, в которую кнопка добавляется в экран.).

+0

См. Мой обновленный пост :) – Francisunoxx

Смежные вопросы