Home > Back-end >  Why use Java CustomDialog complains?
Why use Java CustomDialog complains?

Time:09-26

completely according to the teacher's example dozen, this should be how to fix it, please?

error results shown



 import Java awt. *; 
Import the Java. The awt. Event. *;

Import the Java. IO. *;

Public class CustomDialogDemo extends Java. The awt. Frame implements ActionListener {

String menulabel []={" File "};

String menuitemlabel [] []={
{" New ", "Open", "-", "Save" and "Save As... ", "-", "Exit"}
};

The Menu Menu []=new Menu [1];
MenuItem MenuItem [] []=new MenuItem [1] [7].

//the Demo only
The Label Label;

Public static void main (String args []) {
New CustomDialogDemo ();
}

//construct function
Public CustomDialogDemo () {
Super (" File Dialog Demo ");

//define Layout Manager for BorderLayout
SetLayout (new BorderLayout ());

//the Demo only
Label=new label ();
Add (label, BorderLayout. SOUTH);

//to select single
MenuBar MenuBar=createMenuBar ();

//define the Windows user interface of choice for single
SetMenuBar (menuBar);

//set the size of the window
Enclosing setSize (250, 250);

//Center the frame
Dimension screenSize=Toolkit. GetDefaultToolkit (.) getScreenSize ();
Dimension frameSize=this. GetSize ();

If (frameSize. Height & gt; ScreenSize. Height)
FrameSize. Height=screenSize. Height;

If (frameSize. Width & gt; ScreenSize. Width)
FrameSize. Width=screenSize. Width;

Enclosing setLocation (screenSize. Width - frameSize. Width)/2, (screenSize. Height - frameSize. Height)/2);

//display Windows
Enclosing setVisible (true);

Enclosing addWindowListener (new WindowAdapter () {
Public void windowClosing (WindowEvent e) {
System.exit(0);
}
});
}

Private MenuBar createMenuBar () {
//to select single
MenuBar MenuBar=new MenuBar ();

//set up menu
for (int i=0; i//set up menu
The menu [I]=new menu (menulabel [I]);
Menu [I] the setFont (new Font (" dialog ", the Font. PLAIN, 11));

//new co-opted single to choose a single
MenuBar. Add (menu [I]);
}

for(int i=0; ifor(int j=0; jIf (menuitemlabel [I] [j] equals (" - ")) {
//new dividing line
The menu [I] addSeparator ();
}
The else {
//set up menu item
Menuitem [I] [j]=new menuitem (menuitemlabel [I] [j]);
Menuitem [I] [j]. Journal of setFont (new Font (" dialog ", the Font. PLAIN, 11));

//registered ActionListener
Menuitem [I] [j]. Journal of addActionListener (this);

//the new co-opted single project
Menu [I]. Add (menuitem [I] [j]);
}
}
}

Return the menuBar;
}

//implementation of ActionListener interface method
Public void actionPerformed (an ActionEvent e) {
//action event menu items
MenuItem MenuItem=(MenuItem) um participant etSource ();

If (menuitem. GetLabel () equals (" New ")) {//New
String title=menuitem. GetLabel ();

CustomDialog dialog=new CustomDialog (this title, the title + "dialog Demo.", true);

A Boolean flag=dialog. GetState ();

If (flag)
Label. SetText (" Select the OK Button. ");
The else
Label the setText (" Select the Cancel Button. ");
}
Else if (menuitem. GetLabel () equals (" Open ")) {//Open
FileDialog FileDialog=new FileDialog (this, "Open File", FileDialog. The LOAD).


The Filter Filter=new Filter (" Java ");



Filedialog. SetFilenameFilter (filter);

Filedialog. SetVisible (true);

Label the setText (" the File Selected: "+ filedialog. GetDirectory () + filedialog. GetFile ());
}
Else if (menuitem. GetLabel () equals (" Save ")) {//Save
FileDialog FileDialog=new FileDialog (this, "Save File", FileDialog. Save);


The Filter Filter=new Filter (" Java ");



Filedialog. SetFilenameFilter (filter);

Filedialog. SetVisible (true);

Label the setText (" the File Selected: "+ filedialog. GetDirectory () + filedialog. GetFile ());
}
Else if (menuitem. GetLabel () equals (" Save As... ")) {//Save As...
String title=menuitem. GetLabel ();

CustomDialog dialog=new CustomDialog (this title, the title + "dialog Demo.", true);

A Boolean flag=dialog. GetState ();
If (flag)
Label. SetText (" Select the OK Button. ");
The else
Label the setText (" Select the Cancel Button. ");
}
Else if (menuitem. GetLabel () equals (" Exit "))//Exit
System.exit(0);
}
}

CodePudding user response:

Where is your CustomDialog class?

CodePudding user response:

The
refer to the original poster?? Verge?? Response:
completely according to the teacher's example dozen, this should be how to fix it, please?


Recommend you use eclispe programming tools, free CostomDialog class may not need to import under the same package,
  • Related