0
이 코드는 miALote를 누르면 메인 윈도우에서 새 창을 생성하기로되어 있습니다 ...하지만 잘못하지는 않습니다. . 내가 컨트롤러, 작동에서 경우 삭제하지만이 때문에 일이 안이라면 ...이 메인 컨트롤러 코드 :actionPerformed와 메소드가 컨트롤러와 작동하지 않습니다.
package Controller.GUI;
import GUI.AltaLote;
import GUI.MenuPrincipal;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Controller implements ActionListener{
MenuPrincipal ventanaControlada;
public Controller(MenuPrincipal win){
this.ventanaControlada=win;
}
public void actionPerformed(ActionEvent e){
if (e.getSource().equals(ventanaControlada.miALote)) {
AltaLote ventana=new AltaLote();
ControllerLote controlador=new ControllerLote(ventana);
ventana.addController(controlador);
ventana.setVisible(true);
}
}
}
메인 윈도우 코드 :이
package GUI;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import Controller.GUI.Controller;
public class MenuPrincipal extends JMenu{
private JFrame frame;
public JMenuItem miALote;
Controller controlador;
private JTable table;
public void addController (Controller mc){
controlador=mc;
}
/**
* Create the application.
*/
public MenuPrincipal() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
public void initialize() {
JMenuItem miALote = new JMenuItem("Dar de alta nuevo lote...");
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenu mnLote = new JMenu("Lote");
menuBar.add(mnLote);
mnLote.add(miALote);
miALote.addActionListener(controlador);
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setBounds(0, 0, 390, 139);
frame.getContentPane().add(scrollPane);
frame.setSize(416, 274);
frame.setVisible(true);
frame.getContentPane().add(table, BorderLayout.WEST);
this.setVisible(true);
}
public JMenuItem getAgregarLote() {
return miALote;
}
public void setAgregarLote(JMenuItem miALote) {
this.miALote = miALote;
}
}
'초기화 '를 호출 할 때'controlador'는'null'입니다 ... – MadProgrammer
'MenuPrincipal'이'JMenu'를 확장해야하는 이유는 무엇입니까? ? 그리고 왜 그것은'initialize' 메소드 내에서 새로운'JFrame'을 생성합니까? 네가 행동 청취자보다 큰 문제가 있다고 생각해. – MadProgrammer