java 中模式与非模式的问题

Python019

java 中模式与非模式的问题,第1张

只能控制当前窗体不能控制当前窗体以外的窗体..环境话来说就是只有操作完当前窗体才能去操作别的窗体..这种类型的叫模态窗体.

嗯语句??应该是用

你创建一个面板后丢到JDialog中去就可以了好像

java没有专门的模态窗体都是用JDialog去实现的..要不你就自己模拟一个好了..

....不明白??这里有个例子你看看就知道了

...晕明显告诉你...jframe不能实现模态窗体..java中要实现模态窗体必须通过JDialog或者自己去模拟一个..在有不是模式..是模态..要是你还是不知道..你就自己去百渡搜搜就知道如何实现了

下面是一个实现dialog box

import javafx.stage.*import javafx.scene.*import javafx.scene.paint.Colorimport javafx.scene.control.*import javafx.event.ActionEventimport javafx.event.EventHandlerpublic class ModalDialog {

Button btnpublic ModalDialog(final Stage stg) {

btn = new Button()final Stage stage = new Stage()//Initialize the Stage with type of modalstage.initModality(Modality.APPLICATION_MODAL)//Set the owner of the Stage stage.initOwner(stg)

stage.setTitle("Top Stage With Modality")

Group root = new Group()

Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN)

btn.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent event) {

stage.hide()

}

})

btn.setLayoutX(100)

btn.setLayoutY(80)

btn.setText("OK")

root.getChildren().add(btn)

stage.setScene(scene)

stage.show()

}

}import javafx.application.Applicationimport javafx.event.ActionEventimport javafx.event.EventHandlerimport javafx.scene.Groupimport javafx.scene.Sceneimport javafx.scene.control.Buttonimport javafx.scene.paint.Colorimport javafx.stage.Stagepublic class ModalTest extends Application {/**

* @param args the command line arguments

*/public static void main(String[] args) {

Application.launch(ModalTest.class, args)

}

@Overridepublic void start(final Stage primaryStage) {

primaryStage.setTitle("Hello World")

Group root = new Group()

Scene scene = new Scene(root, 500, 450, Color.LIGHTBLUE)

Button btn = new Button()

btn.setLayoutX(250)

btn.setLayoutY(240)

btn.setText("Show modal dialog")

btn.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent event) {

ModalDialog md = new ModalDialog(primaryStage)

}

})

root.getChildren().add(btn)

primaryStage.setScene(scene)

primaryStage.show()

}

}