Swing calls file selection dialog

xiaoxiao2021-03-06  65

Import javax.swing. *;

.

.

.

Public Class Jcutter Extends Jframe {

Private JTextField Textfield;

Private jbutton button;

Private jfilechooser fdialog;

Private Jframe Frame;

.

.

.

Button = new jbutton ();

Button.addActionListener (New ActionListener () {

Public Void ActionPerformed (ActionEvent E) {

String msg;

fdialog = new jfilechooser (); // file selector

Int results = fdialog.showopendialog (frame);

IF (result == jfilechooser.Approve_option) {

String fname = fdialog.getname (fdialog.getSelectedFile ());

Frame.SetTitle (FNAME);

Msg = "file open approved";

Else

Msg = "File Open Cancelled";

JOPTIONPANE.SHOWMESSAGEDIALOG (Frame, MSG); // Tips box

}

});

转载请注明原文地址:https://www.9cbs.com/read-120194.html

New Post(0)