这是 MVC 范例的类视图,该类由 2 组成,单击-和JDialogs
时将打开。JMenuItem
addEvent
editEvent
public class EventView extends javax.swing.JFrame {
private javax.swing.JDialog addDialog;
private javax.swing.JDialog editDialog;
private EventModel model;
/** Constructor */
public EventView(EventModel model) {
initComponents();
this.model = model;
updateEventTable();
}
public void addEventListener(ActionListener al) {
addEventButton.addActionListener(al);
}
/* public void clearListener(ActionListener cl) {
clearEventButton.addActionListener(cl);
}*/
public void addDialog(ActionListener ae) {
addEvent.addActionListener(ae);
}
public void editDialog(ActionListener ee) {
editEvent.addActionListener(ee);
}
}
控制器类处理用户与监听器的交互。
public class EventController implements ActionListener {
//... The Controller needs to interact with both the Model and View.
private EventModel model;
private EventView view;
/** Constructor */
public EventController(EventModel model, EventView v){
model = new EventModel();
view = v;
//... Add listeners to the view.
view.addEventListener(new addEventListener());
//view.clearListener(new clearEventListener());
view.addDialog(new addDialogListener());
view.editDialog(new editDialogListener());
}
class addEventListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String name = "";
String date;
String start="";
String end="";
String venue="";
String details="";
String opportunities="";
String moreOppor="";
try {
name = view.getEventName();
date = view.eventDate().toString();
start = view.startTime();
end = view.endTime();
venue = view.locationWhere();
details = view.getDetails();
opportunities = view.getOpportunities();
moreOppor = view.getMore();
model.addEvent(name,date,start,venue,details,opportunities,moreOppor,end);
view.showSuccess("Event Added!");
} catch (Exception ex) {
view.showError(ex);
}
}
}
class addDialogListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("");
}
}
class editDialogListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("");
}
}
我有两个关于这个模块的问题:
EventController
显示一个错误,它不是抽象的,并且当我相信我这样做时不会覆盖抽象方法 actionPerformed。如我错了请纠正我。我确实有一个额外的 JMenuItem 被调用deleteEvent
,但我还没有触及它。在 NetbeansIDE 上工作仅供参考我想
System.out.println("");
用可以让我显示addDialog
视图类的对话框但我无法访问该组件的东西替换这些行。这个怎么做?我已经尝试过view.
,但它没有显示允许setVisible(true)
.