📄 mainframe.java
字号:
public mainFrame(String title) {
this();
setTitle(title);
}
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension d = getSize();
super.addNotify();
if (fComponentsAdjusted)
return;
}
// Used for addNotify check.
boolean fComponentsAdjusted = false;
//{{DECLARE_CONTROLS
JCalendar calendar1;
JTextArea textArea1;
JTextField textFieldErrMsg;
JLabel labelInsertDF;
JTextField textFieldDFaddress;
JList listNames;
DefaultListModel lModel;
JPanel p1;
JPanel p2;
JPanel p3;
JPanel p4;
JPanel p5;
JPanel calendarPanel;
JPanel descriptionPanel;
JPanel infoPanel;
JPanel persPanel;
JPanel listPanel;
JTextArea textArea2;
JLabel facilitatorMessage;
JTextField Info;
JLabel appointment;
JLabel description;
JLabel LInfo;
JFrame facFrame;
JFrame knowFrame;
JButton doneButton;
JScrollPane sPane;
//{{DECLARE_MENUS
JMenuBar mainMenuBar;
JMenu menu1;
JMenuItem miRegWithDF;
JMenuItem miViewDF;
JMenuItem menuItem3;
JMenuItem menuItem4;
JMenu appMenu;
JMenuItem menuItem5;
JMenuItem menuItem2;
JMenuItem menuItem1;
class SymWindow extends java.awt.event.WindowAdapter {
public void windowClosing(java.awt.event.WindowEvent event) {
Object object = event.getSource();
if (object == mainFrame.this)
Frame1_WindowClosing(event);
}
}
void Frame1_WindowClosing(java.awt.event.WindowEvent event)
{
setVisible(false); // hide the Frame
dispose(); // free the system resources
myAgent.doDelete();
}
class SymAction implements java.awt.event.ActionListener
{
public void actionPerformed(java.awt.event.ActionEvent event) {
Object object = event.getSource();
if (object == miViewDF)
miViewDF_Action(event);
else if (object == miRegWithDF)
miRegWithDF_Action(event);
else if (object == menuItem1)
menuItem1_ActionPerformed(event);
else if (object == menuItem2)
menuItem2_ActionPerformed(event);
else if (object == menuItem4)
menuItem4_ActionPerformed(event);
else if (object == textFieldDFaddress)
textFieldDFaddress_EnterHit(event);
else if (object == menuItem3)
menuItem3_ActionPerformed(event);
else if (object == menuItem5)
menuItem5_ActionPerformed(event);
else if (object == doneButton)
close_know_Frame();
}
}
/** View Known DF */
void miViewDF_Action(java.awt.event.ActionEvent event)
{
clearFrame();
knowFrame.setVisible(true);
description.setText("Known Facilitators");
//listNames.clearSelection();
//lModel.removeAllElements();
lModel.clear();
for (Enumeration e = myAgent.getKnownDF(); e.hasMoreElements(); ) {
//listNames.addItem(((AID)e.nextElement()).getName());
lModel.addElement(((AID)e.nextElement()).getName());
}
currentAction = VIEWKNOWNDF;
//listNames.select(0);
listNames.setSelectedIndex(0);
listNames_ItemStateChanged();
}
//Chiude il Frame Known Persons e Known Facilitators
void close_know_Frame() {
knowFrame.setVisible(false);
}
void miExit_Action(java.awt.event.ActionEvent event)
{
// Action from Exit Create and show as modal
//System.err.println("miExit_ACtion");
}
void miRegWithDF_Action(java.awt.event.ActionEvent event)
{ // Register with a DF
clearFrame();
facFrame.setVisible(true);
/*
labelInsertDF.setVisible(true);
textFieldDFaddress.setVisible(true);
*/
textFieldDFaddress.requestFocus();
}
/** View Known Persons **/
void menuItem3_ActionPerformed(java.awt.event.ActionEvent event)
{
clearFrame();
knowFrame.setVisible(true);
description.setText("Known persons");
//listNames.clearSelection();
//lModel.removeAllElements();
//lModel.removeAllElements();
lModel.clear();
for (Enumeration e = myAgent.getKnownPersons(); e.hasMoreElements(); ) {
//listNames.addItem(((Person)e.nextElement()).getName());
lModel.addElement(((Person)e.nextElement()).getName());
}
currentAction=VIEWKNOWNPERSONS;
//listNames.select(0);
listNames.setSelectedIndex(0);
listNames_ItemStateChanged();
}
void calendar1_Action()
{
Appointment a = null;
clearFrame();
p2.setVisible(true);
p4.setVisible(true);
textArea1.setText("");
java.util.Calendar c = calendar1.getCalendar();
a = myAgent.getMyAppointment(c.getTime());
if (a != null) {
//System.out.println("C'e' un appuntamento");
textArea1.setText(a.getDescription());
}
}
/**
* This method sets to not visible all the components of this frame
* except the Menu Bar.
*/
void clearFrame () {
knowFrame.setVisible(false);
facFrame.setVisible(false);
}
void menuItem1_ActionPerformed(java.awt.event.ActionEvent event)
{ // Remove an appointment
calendar1_Action();
GuiEvent ev = new GuiEvent(this,myAgent.CANCELAPPOINTMENT);
ev.addParameter(calendar1.getCalendar().getTime());
myAgent.postGuiEvent(ev);
calendar1_Action();
}
/** Fix an appointment */
void menuItem2_ActionPerformed(java.awt.event.ActionEvent event)
{
calendar1_Action();
// Create and show the Frame
//System.out.println("Trasmetto : " + calendar1.getCalendar());
(new FixApp(myAgent, calendar1.getCalendar() )).setVisible(true);
}
/** This method is called to update the list of known persons */
void menuItem4_ActionPerformed(java.awt.event.ActionEvent event)
{
AID dfName;
Enumeration e = myAgent.getKnownDF();
clearFrame();
//getContentPane().setSize(255,100);
while (e.hasMoreElements()) {
dfName=(AID)e.nextElement();
GuiEvent ev = new GuiEvent(this,myAgent.SEARCHWITHDF);
ev.addParameter(dfName);
myAgent.postGuiEvent(ev);
}
}
//stampa i msg di update
void showErrorMessage(String text) {
//clearFrame();
p4.setVisible(true);
//textFieldErrMsg.setVisible(true);
Info.setText(text);
//System.err.println(text);
}
//da sistemare..chiama anche lui showErrorMessage
void textFieldDFaddress_EnterHit(java.awt.event.ActionEvent event)
{
clearFrame();
GuiEvent ev = new GuiEvent(this,myAgent.REGISTERWITHDF);
ev.addParameter(textFieldDFaddress.getText());
myAgent.postGuiEvent(ev);
}
class SymItem implements java.awt.event.ItemListener
{
public void itemStateChanged(java.awt.event.ItemEvent event)
{
//Object object = event.getSource();
//if (object == listNames)
//listNames_ItemStateChanged(event);
}
}
void listNames_ItemStateChanged()
{
//String cur = listNames.getSelectedItem();
String cur = (String)lModel.getElementAt(listNames.getSelectedIndex());
if (currentAction == VIEWKNOWNPERSONS)
textArea2.setText(myAgent.getPerson(cur).toString());
else if (currentAction == VIEWKNOWNDF)
textArea2.setText(cur);
}
void menuItem5_ActionPerformed(java.awt.event.ActionEvent event)
{
calendar1_Action();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -