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="登錄知乎,發(fā)現(xiàn)更大的世界"
          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);

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • GeekBand C++ Week1 Notes A.OOP-面向?qū)ο缶幊?1基礎(chǔ):C語言 -變量variable...
    古來征戰(zhàn)幾人回閱讀 601評論 0 0
  • Week1-2 的代碼 from bs4 import BeautifulSoup with open('C://...
    Rayment915閱讀 318評論 0 0
  • 1.C++概述 面向?qū)ο螅?學習classes間關(guān)系 繼承inheritance、 復合composition、 ...
    龍曜閱讀 313評論 0 0
  • Week1-3 一 內(nèi)斂函數(shù) #1 函數(shù)若在class body類內(nèi)定義完成,便自動成為inline。inline...
    D_東閱讀 259評論 0 0
  • 原本想把每周的課程內(nèi)容放在一篇文檔中,無奈Martin的信息密度太大,所以把每周內(nèi)容按照自然發(fā)生的狀況拆解為兩篇-...
    Sisyphus235閱讀 3,787評論 4 27

友情鏈接更多精彩內(nèi)容