Java实验第五次
目录
1. 设计一个窗口,在窗口内放置一个按钮,当不断地单击该按钮时,在按钮上显示被点击的次数。
public class Text1 extends Application{
public static void main(String[] args) {
// TODO Auto-generated method stub
Application.launch(args);
}
@Override
public void start(Stage stage) throws Exception {
// TODO Auto-generated method stub
Button button = new Button("0");
button.setOnMouseClicked(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
// TODO Auto-generated method stub
// double n1 = Double.parseDouble(num1.getText());
String u = button.getText(); //获取按钮上的文本信息
int y = Integer.parseInt(u); //吧文本信息转化为int类型
int p = y+1; //次数加一
button.setText(String.valueOf(p)); //吧转换后的数据重新传回按钮上
}
});
FlowPane flowPane = new FlowPane(); //添加面板
flowPane.getChildren().add(button); //吧空控件添加到面板上
Scene scene = new Scene(flowPane); //创建场景
stage.setScene(scene); //吧场景添加到舞台
stage.setWidth(600);
stage.show();
}
}
2. 编写一个应用程序,有一个标题为“登录”的窗口,能实现用户名和密码的输入,用户名和密码保存在Map集合中。
(1)如果用户名和密码输入正确,则单击“登录”按钮弹出“用户登录成功”的消息框;
(2)如果用户名或密码输入错误,则单击“登录”按钮弹出“用户登录失败”的消息框。
public class Text2 extends Application {
Label label1 = new Label("用户名:");
Label label2 = new Label("密码:");
TextField tf = new TextField();
TextField tf1 = new TextField();
Button b = new Button("登陆");
public static void main(String[] args) {
// TODO Auto-generated method stub
Application.