成绩查询系统网站开发,狮岭做网站,农业建设管理信息网站,后期网站在本教程中#xff0c;我将使用JavaFX 2和CSS设计漂亮的Login Form 。 它是经典的登录表单#xff0c;带有用户名和密码以及登录按钮。 为了遵循本教程#xff0c;我强烈建议您查看以下这些教程#xff1a; Eclipse IDE中的JavaFX 2入门 JavaFX 2#xff1a;HBox JavaFX… 在本教程中我将使用JavaFX 2和CSS设计漂亮的Login Form 。 它是经典的登录表单带有用户名和密码以及登录按钮。 为了遵循本教程我强烈建议您查看以下这些教程 Eclipse IDE中的JavaFX 2入门 JavaFX 2HBox JavaFX 2GridPane JavaFX 2样式按钮 JavaFX 2使用文本和文本效果 用户名 JavaFX2 密码密码 您可以在上方输入此信息然后单击“登录”按钮。 它会提示您登录成功但是如果输入错误信息则会提示您登录不成功。 本教程的最终输出屏幕截图如下图所示。 JavaFX 2登录表单 这是我们示例的Java代码 import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Reflection;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;/**** web http://zoranpavlovic.blogspot.com/*/
public class Login extends Application {String user JavaFX2;String pw password;String checkUser, checkPw;public static void main(String[] args) {launch(args);}Overridepublic void start(Stage primaryStage) {primaryStage.setTitle(JavaFX 2 Login);BorderPane bp new BorderPane();bp.setPadding(new Insets(10,50,50,50));//Adding HBoxHBox hb new HBox();hb.setPadding(new Insets(20,20,20,30));//Adding GridPaneGridPane gridPane new GridPane();gridPane.setPadding(new Insets(20,20,20,20));gridPane.setHgap(5);gridPane.setVgap(5);//Implementing Nodes for GridPaneLabel lblUserName new Label(Username);final TextField txtUserName new TextField();Label lblPassword new Label(Password);final PasswordField pf new PasswordField();Button btnLogin new Button(Login);final Label lblMessage new Label();//Adding Nodes to GridPane layoutgridPane.add(lblUserName, 0, 0);gridPane.add(txtUserName, 1, 0);gridPane.add(lblPassword, 0, 1);gridPane.add(pf, 1, 1);gridPane.add(btnLogin, 2, 1);gridPane.add(lblMessage, 1, 2);//Reflection for gridPaneReflection r new Reflection();r.setFraction(0.7f);gridPane.setEffect(r);//DropShadow effect DropShadow dropShadow new DropShadow();dropShadow.setOffsetX(5);dropShadow.setOffsetY(5);//Adding text and DropShadow effect to itText text new Text(JavaFX 2 Login);text.setFont(Font.font(Courier New, FontWeight.BOLD, 28));text.setEffect(dropShadow);//Adding text to HBoxhb.getChildren().add(text);//Add IDs to Nodesbp.setId(bp);gridPane.setId(root);btnLogin.setId(btnLogin);text.setId(text);//Action for btnLoginbtnLogin.setOnAction(new EventHandler() {public void handle(ActionEvent event) {checkUser txtUserName.getText().toString();checkPw pf.getText().toString();if(checkUser.equals(user) checkPw.equals(pw)){lblMessage.setText(Congratulations!);lblMessage.setTextFill(Color.GREEN);}else{lblMessage.setText(Incorrect user or pw.);lblMessage.setTextFill(Color.RED);}txtUserName.setText();pf.setText();}});//Add HBox and GridPane layout to BorderPane Layoutbp.setTop(hb);bp.setCenter(gridPane); //Adding BorderPane to the scene and loading CSSScene scene new Scene(bp);scene.getStylesheets().add(getClass().getClassLoader().getResource(login.css).toExternalForm());primaryStage.setScene(scene);primaryStage.titleProperty().bind(scene.widthProperty().asString().concat( : ).concat(scene.heightProperty().asString()));//primaryStage.setResizable(false);primaryStage.show();}
} 为了正确设置此应用程序的样式您需要在项目的/ src文件夹中创建login.css文件。 如果您不知道该怎么做请查看JavaFX 2样式按钮教程 。 这是我们示例CSS代码 #root {-fx-background-color: linear-gradient(lightgray, gray);-fx-border-color: white;-fx-border-radius: 20;-fx-padding: 10 10 10 10;-fx-background-radius: 20;}#bp {-fx-background-color: linear-gradient(gray,DimGrey );}#btnLogin {-fx-background-radius: 30, 30, 29, 28;-fx-padding: 3px 10px 3px 10px;-fx-background-color: linear-gradient(orange, orangered );
}#text {-fx-fill: linear-gradient(orange , orangered);
} 多数民众赞成在本教程中如果您有任何意见或问题请随时发表评论。 如果您喜欢本教程则可以在此博客上查看更多JavFX 2教程。 您可能想看一下下面的这些教程 JavaFX 2使用CSS设置按钮样式 JavaFX 2使用CSS设置文本样式 参考 JavaFX 2在Zoran Pavlovic博客博客上从我们的JCG合作伙伴 Zoran Pavlovic 创建尼斯登录表单 。 翻译自: https://www.javacodegeeks.com/2012/06/in-this-tutorial-i-will-design-nice.html