GUI学习week1

主程序

-package com.soft1841.oop.week1;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.net.URL;

public class ButtonApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
URL location = getClass().getResource("/fxml/button.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
Parent root = fxmlLoader.load();
Scene scene = new Scene(root,543,824);
scene.getStylesheets().add(ButtonApp.class.getResource("/css/style.css").toExternalForm());
primaryStage.setTitle("知乎");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

按钮

-package com.soft1841.oop.week1;

import javafx.scene.control.Button;

public class MyButton extends Button {
public MyButton(){
this.setPrefSize(436,44);
this.setStyle("-fx-background-color: rgb(0, 132, 255);-fx-border-radius: 10;-fx-text-fill: #FFFFFF");
}
}

标签

-package com.soft1841.oop.week1;

import javafx.scene.control.Label;

public class ZhihuLa1 extends Label {
public ZhihuLa1(){
this.setStyle("-fx-text-fill: #0084ff;-fx-font-size: 28");
}
}

-package com.soft1841.oop.week1;

import javafx.scene.control.Label;

public class ZhihuLa2 extends Label {
public ZhihuLa2(){
this.setStyle("-fx-text-fill: #8590a6;-fx-font-size: 14");
}
}

hxml

-<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.*?>

<?import com.soft1841.oop.week1.MyButton?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.control.Label?>
<?import com.soft1841.oop.week1.ZhihuLa1?>
<?import com.soft1841.oop.week1.ZhihuLa2?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="com.soft1841.oop.week1.ButtonController">

<ImageView AnchorPane.topAnchor="55"
           AnchorPane.leftAnchor="180">
    <Image url="/img/知乎.png"/>
</ImageView>
<ZhihuLa1 text="登录知乎,发现更大的世界"
          AnchorPane.leftAnchor="104"
          AnchorPane.topAnchor="170"/>

<MyButton text="登录"
          AnchorPane.leftAnchor="50"
          AnchorPane.topAnchor="435"/>
<ZhihuLa2 text="手机号或邮箱"
          AnchorPane.topAnchor="243"
          AnchorPane.leftAnchor="56"/>
<ZhihuLa2 text="密码"
          AnchorPane.topAnchor="330"
          AnchorPane.leftAnchor="56"/>
<ZhihuLa2 text="忘记密码"
          AnchorPane.rightAnchor="56"
          AnchorPane.topAnchor="370"/>
<ZhihuLa2 text="二维码登录 · 海外手机登录 · 社交账号登录 "
          AnchorPane.topAnchor="510"
          AnchorPane.leftAnchor="56"/>

</AnchorPane>

css

-.root{

-fx-background-color: rgb(255, 255, 255);

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • GeekBand C++ Week1 Notes A.OOP-面向对象编程 1基础:C语言 -变量variable...
    古来征战几人回阅读 3,517评论 0 0
  • Week1-2 的代码 from bs4 import BeautifulSoup with open('C://...
    Rayment915阅读 2,299评论 0 0
  • 1.C++概述 面向对象: 学习classes间关系 继承inheritance、 复合composition、 ...
    龙曜阅读 1,820评论 0 0
  • Week1-3 一 内敛函数 #1 函数若在class body类内定义完成,便自动成为inline。inline...
    D_东阅读 1,540评论 0 0
  • 原本想把每周的课程内容放在一篇文档中,无奈Martin的信息密度太大,所以把每周内容按照自然发生的状况拆解为两篇-...
    Sisyphus235阅读 9,055评论 4 27