Address Book(地址薄)
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.Scene?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.collections.FXCollections?>
<?import addressbook.*?> <Scene xmlns:fx="http://javafx.com/fxml" fx:controller="addressbook.Controller"
stylesheets="addressbook/addressbook.css">
<GridPane styleClass="grid-pane">
<Label id="address-book" text="%addressBook"
GridPane.columnIndex="0" GridPane.rowIndex="0"/>
<TableView fx:id="tableView" tableMenuButtonVisible="true"
GridPane.columnIndex="0" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="firstNameColumn"
text="%firstName" prefWidth="100">
<cellValueFactory>
<PropertyValueFactory property="firstName"/>
</cellValueFactory>
<cellFactory>
<FormattedTableCellFactory alignment="CENTER"
addRowContextMenu="true"/>
</cellFactory>
</TableColumn>
<TableColumn
text="%lastName" prefWidth="100">
<cellValueFactory>
<PropertyValueFactory property="lastName"/>
</cellValueFactory>
</TableColumn>
<TableColumn
text="%email" prefWidth="210" sortable="false">
<cellValueFactory>
<PropertyValueFactory property="email"/>
</cellValueFactory>
</TableColumn>
</columns>
<Person firstName="Jacob" lastName="Smith"
email="jacob.smith@example.com"/>
<Person firstName="Isabella" lastName="Johnson"
email="isabella.johnson@example.com"/>
<Person firstName="Ethan" lastName="Williams"
email="ethan.williams@example.com"/>
<Person firstName="Emma" lastName="Jones"
email="emma.jones@example.com"/>
<Person firstName="Michael" lastName="Brown"
email="michael.brown@example.com"/>
<sortOrder>
<fx:reference source="firstNameColumn"/>
</sortOrder>
</TableView>
<HBox styleClass="h-box" GridPane.columnIndex="0" GridPane.rowIndex="2">
<TextField fx:id="firstNameField" promptText="%firstName"
prefWidth="90"/>
<TextField fx:id="lastNameField" promptText="%lastName"
prefWidth="90"/>
<TextField fx:id="emailField" promptText="%email"
prefWidth="150"/>
<Button text="%add" onAction="#addPerson"/>
</HBox>
</GridPane>
</Scene>
/**
* An address book application.
*
* @author HAN
*/
package addressbook;
# Title of window
title=FXML Address Book # Name of label above the table view
addressBook=Address Book # Name of the first table column
# & Prompt text of text field for the first table column
firstName=First Name # Name of the second table column
# & Prompt text of text field for the second table column
lastName=Last Name # Name of the third table column
# & Prompt text of text field for the third table column
email=Email Address # Name of button for adding rows to table
add=Add
# Title of window
title=FXML\u5730\u5740\u7C3F # Name of label above the table view
addressBook=\u5730\u5740\u7C3F # Name of the first table column
# & Prompt text of text field for the first table column
firstName=\u540D\u5B57 # Name of the second table column
# & Prompt text of text field for the second table column
lastName=\u59D3 # Name of the third table column
# & Prompt text of text field for the third table column
email=\u7535\u5B50\u90AE\u4EF6 # Name of button for adding rows to table
add=\u6DFB\u52A0
.grid-pane {
-fx-alignment: center;
-fx-hgap: 10;
-fx-vgap: 10;
-fx-padding: 10;
} #address-book {
-fx-font: NORMAL 20 Tahoma;
} .h-box {
-fx-spacing:10;
-fx-alignment: bottom-right;
}
package addressbook; import java.text.Format; import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.text.TextAlignment;
import javafx.util.Callback; public class FormattedTableCellFactory<S, T> implements
Callback<TableColumn<S, T>, TableCell<S, T>> {
/**
* The alignment for both the multiline text and label position within cell.
*/
private TextAlignment alignment; /**
* Specify a Format if required to format the cell item.
*/
private Format format; /**
* This variable is set because normally only one time of adding context
* menu to table row is needed. So be aware of cooccurrence when setting
* cell factory for multiple columns.
*/
private boolean addRowContextMenu; public TextAlignment getAlignment() {
return alignment;
} public Format getFormat() {
return format;
} public boolean getAddRowContextMenu() {
return addRowContextMenu;
} public void setAlignment(TextAlignment alignment) {
this.alignment = alignment;
} public void setFormat(Format format) {
this.format = format;
} public void setAddRowContextMenu(boolean addRowContextMenu) {
this.addRowContextMenu = addRowContextMenu;
} @Override
public TableCell<S, T> call(TableColumn<S, T> arg0) {
final TableCell<S, T> cell = new TableCell<S, T>() {
@Override
protected void updateItem(T item, boolean empty) {
if (item == getItem()) {
return;
}
super.updateItem(item, empty);
if (item == null) {
setText(null);
setGraphic(null);
} else if (item instanceof Node) {
setText(null);
setGraphic((Node) item);
} else if (format != null) {
setText(format.format(item));
setGraphic(null);
} else {
setText(item.toString());
setGraphic(null);
} if (addRowContextMenu)
addCM(this);
}
};
if (alignment == null)
alignment = TextAlignment.LEFT;
cell.setTextAlignment(alignment);
switch (alignment) {
case CENTER:
cell.setAlignment(Pos.CENTER);
break;
case RIGHT:
cell.setAlignment(Pos.CENTER_RIGHT);
break;
default:
cell.setAlignment(Pos.CENTER_LEFT);
}
return cell;
} private MenuItem delete = new MenuItem("Delete");
private ContextMenu contextMenu = new ContextMenu(delete); private void addCM(final TableCell<S, T> cell) {
@SuppressWarnings("rawtypes")
final TableRow row = cell.getTableRow();
delete.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
cell.getTableView().getItems().remove(row.getItem());
}
});
if (row != null) {
if (row.getItem() != null) {
row.setContextMenu(contextMenu);
}
}
}
}
package addressbook; import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty; /**
* A Bean convention based data model.
*
* @author HAN
*/
public class Person {
private StringProperty firstName = new SimpleStringProperty();
private StringProperty lastName = new SimpleStringProperty();
private StringProperty email = new SimpleStringProperty(); public Person() {
this("", "", "");
} public Person(String firstName, String lastName, String email) {
setFirstName(firstName);
setLastName(lastName);
setEmail(email);
} public final String getFirstName() {
return firstName.get();
} public final String getLastName() {
return lastName.get();
} public final String getEmail() {
return email.get();
} public final void setFirstName(String firstName) {
this.firstName.set(firstName);
} public final void setLastName(String lastName) {
this.lastName.set(lastName);
} public final void setEmail(String email) {
this.email.set(email);
} public StringProperty firstNameProperty() {
return firstName;
} public StringProperty lastNameProperty() {
return lastName;
} public StringProperty emailProperty() {
return email;
}
}
package addressbook; import javafx.fxml.FXML;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField; public class Controller {
@FXML
private TableView<Person> tableView;
@FXML
private TextField firstNameField;
@FXML
private TextField lastNameField;
@FXML
private TextField emailField; @FXML
private void addPerson() {
tableView.getItems().add(
new Person(firstNameField.getText(), lastNameField.getText(),
emailField.getText()));
firstNameField.clear();
lastNameField.clear();
emailField.clear();
}
}
package addressbook; import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle; import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage; public class Model extends Application {
public static void main(String[] args) {
launch(args);
} @Override
public void start(Stage stage) throws Exception {
Locale locale = getCurrentLocale();
ResourceBundle resources = ResourceBundle
.getBundle("addressbook/addressbook", locale,
Model.class.getClassLoader());
stage.setTitle(resources.getString("title"));
stage.setScene((Scene) FXMLLoader.load(
Model.class.getResource("View.fxml"), resources));
stage.show();
} private Locale getCurrentLocale() {
Map<String, String> namedParams = getParameters().getNamed();
String languageParam = namedParams.get("language");
String countryParam = namedParams.get("country"); Locale locale = Locale.getDefault();
if (languageParam != null && languageParam.trim().length() > 0) {
if (countryParam != null && countryParam.trim().length() > 0) {
locale = new Locale(languageParam.trim(), countryParam.trim());
} else {
locale = new Locale(languageParam.trim());
}
}
return locale;
}
}




Address Book(地址薄)的更多相关文章
- iOS:访问地址薄
地址簿的访问 介绍: 地址簿(Address Book)是一个共享的联系人信息数据库.任何iOS应用程序都可以使用.通过提供常用联系人信息,而不是让每一个应用程序管理独立的联系人列表,可改善用户体验. ...
- Qt 地址薄 (一) 界面设计
实现一个简单的地址薄,功能包括:地址的添加.浏览.编辑.查找.输出文件等. 1 界面和元素 整个地址薄界面,可视为一个 AddressBook 类.其中的 Name.Address 以及两个编辑栏, ...
- Qt 地址薄 (二) 添加地址
在上一篇 Qt 地址薄 (一) 界面设计 中,主要是实现了地址簿的界面,使用布局管理器进行元素的布局,并解释了"子类化" 和"所有权"的概念. 本篇将在上面的基 ...
- wex5 实战 省市县三级联动与地址薄同步
无论是商城,还是快递,都要用到省市县三级联动,和地址薄,今天就以实战来制作,难点有3个: 1:三级联动,有wex5组件实现,相对简单,实战里对行数据进行了拼接 2: 地址薄选项,利用inputSel ...
- ios开发——实用技术篇Swift篇&地址薄、短信、邮件
//返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...
- python 教程 第十四章、 地址薄作业
第十四章. 地址薄作业 #A Byte of Python #!/usr/bin/env python import cPickle import os #define the contacts fi ...
- 如何从OA系统批量整理出邮箱地址,并导入到Foxmail 地址薄中?
一.打开某位leader的OA,点击查看“下属” a. 将所有的下属信息 --- 全选 --- 复制 --- 粘贴到 excel 表格中 b. 分别提取“姓名” 和 “邮箱”地址信息,结合notepa ...
- LeetCode 1108. Defanging an IP Address (IP 地址无效化)
题目标签:String 题目给了我们一组 ip address,让我们把 . 变成 [.],这题可以用replace,但是这样做的话,好像没意义了.所以还是走一下array,具体看code. Java ...
- <address>标签,为网页加入地址信息
一般网页中会有一些网站的联系地址信息需要在网页中展示出来,这些联系地址信息如公司的地址就可以<address>标签.也可以定义一个地址(比如电子邮件地址).签名或者文档的作者身份. 语法: ...
随机推荐
- 用PlistBuddy修改Plist文件
Plist文件是以.plist为结尾的文件的总称. 众所周知, Plist在Mac OSX系统中起着举足轻重的作用,就如同Windows里面的Registry一样,系统和程序使用Plist文件来存储自 ...
- 《Java虚拟机原理图解》1.4 class文件里的字段表集合--field字段在class文件里是如何组织的
0.前言 了解JVM虚拟机原理是每个Java程序猿修炼的必经之路.可是因为JVM虚拟机中有非常多的东西讲述的比較宽泛.在当前接触到的关于JVM虚拟机原理的教程或者博客中,绝大部分都是充斥的文字性的描写 ...
- Android SDK Manager 无法更新SDK
Android SDK Manager 被墙后无法更新SDK 下载sdk时抛出错误:Failed to fetch URL http://dl-ssl.google.com/ 參考例如以下博客: ht ...
- JQuery动态增加删除元素
<form action="" method="post" enctype="multipart/form-data"> < ...
- JS客户端读取Excel文件插件js-xls使用方法
js-xls是一款客户端读取Excel的插件,亲测IE11.FireFox.Chrome可用,读取速度也客观. 插件Demo地址:http://oss.sheetjs.com/js-xlsx/ ...
- Android-版本与api对应关系图
Code name Version API level Lollipop 5.1 API level 22 Lollipop 5.0 API level 21 KitKat 4.4 - 4.4.4 A ...
- COM 浅谈
ArcObject 是基于 COM(Microsoft Component Object Model),即组件对象模型.虽然ArcGIS的终端用户不用理解什么是COM,但是作为基于ArcObject的 ...
- HibernateTemplate常用方法总结
HibernateTemplate常用方法 (本文章内容相当于转载自:http://www.tuicool.com/articles/fU7FV3,只是整理了一下内容结构和修改了部分内容,方便阅读) ...
- 《Hadoop权威》学习笔记四:Hadoop的I/O
一.数据完整性 二.压缩 三.序列化 基本概念 序列化指的是将结构化对象转化为字节流以便于通过网络进行传输或写入持久化存储的过程 反序列化指的是将字节流转为一系列结构化对象的过程. 进程间通信 ...
- hdu 1711 Number Sequence(KMP模板题)
我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...