JavaFX UI控件教程(二十三)之Menu

翻译自  Menu

本章介绍如何创建菜单和菜单栏,添加菜单项,将菜单分组,创建子菜单以及设置上下文菜单。

您可以使用以下JavaFX API类在JavaFX应用程序中构建菜单。

  • 菜单栏

  • 菜单项

    • 菜单

    • CheckMenuItem

    • RadioMenuItem

    • 菜单

    • CustomMenuItem

      • SeparatorMenuItem

  • 上下文菜单

图22-1显示了具有典型菜单栏的应用程序的屏幕截图。

图22-1使用菜单栏和三个菜单类别的应用程序

 

在JavaFX应用程序中构建菜单

菜单是可以根据用户的请求显示的可操作项目列表。当菜单可见时,用户可以选择一个菜单项。用户单击某个项目后,菜单将返回隐藏模式。通过使用菜单,您可以通过在菜单中放置并不总是需要显示的功能来节省应用程序用户界面(UI)中的空间。

菜单栏中的菜单通常按类别分组。编码模式是声明菜单栏,定义类别菜单,并使用菜单项填充类别菜单。在JavaFX应用程序中构建菜单时,请使用以下菜单项类:

  • MenuItem - 创建一个可操作的选项

  • Menu - 创建子菜单

  • RadioButtonItem - 创建互斥选择

  • CheckMenuItem - 创建可在选定和未选定状态之间切换的选项

要分隔一个类别中的菜单项,请使用SeparatorMenuItem该类。

按菜单栏中的类别组织的菜单通常位于窗口的顶部,剩下的场景用于关键的UI元素。如果出于某些原因,您无法为菜单栏分配UI的任何可视部分,则可以使用用户打开的上下文菜单,只需单击鼠标即可。

创建菜单栏

虽然菜单栏可以放在用户界面的其他位置,但通常它位于UI的顶部,并且它包含一个或多个菜单。菜单栏会自动调整大小以适合应用程序窗口的宽度。默认情况下,添加到菜单栏的每个菜单都由带有文本值的按钮表示。

考虑一个呈现有关植物的参考信息的应用程序,例如它们的名称,二项式名称,图片和简要描述。您可以创建三个菜单类别:文件,编辑和视图,并使用菜单项填充它们。例22-1显示了添加了菜单栏的此类应用程序的源代码。

示例22-1菜单示例应用程序

import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.effect.Glow;
import javafx.scene.effect.SepiaTone;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;public class MenuSample extends Application {final PageData[] pages = new PageData[] {new PageData("Apple","The apple is the pomaceous fruit of the apple tree, species Malus "+ "domestica in the rose family (Rosaceae). It is one of the most "+ "widely cultivated tree fruits, and the most widely known of "+ "the many members of genus Malus that are used by humans. "+ "The tree originated in Western Asia, where its wild ancestor, "+ "the Alma, is still found today.","Malus domestica"),new PageData("Hawthorn","The hawthorn is a large genus of shrubs and trees in the rose "+ "family, Rosaceae, native to temperate regions of the Northern "+ "Hemisphere in Europe, Asia and North America. "+ The name hawthorn was "+ "originally applied to the species native to northern Europe, "+ "especially the Common Hawthorn C. monogyna, and the unmodified "+ "name is often so used in Britain and Ireland.","Crataegus monogyna"),new PageData("Ivy","The ivy is a flowering plant in the grape family (Vitaceae) native to+ " eastern Asia in Japan, Korea, and northern and eastern China. "+ "It is a deciduous woody vine growing to 30 m tall or more given "+ "suitable support,  attaching itself by means of numerous small "+ "branched tendrils tipped with sticky disks.","Parthenocissus tricuspidata"),new PageData("Quince","The quince is the sole member of the genus Cydonia and is native to "+ "warm-temperate southwest Asia in the Caucasus region. The "+ "immature fruit is green with dense grey-white pubescence, most "+ "of which rubs off before maturity in late autumn when the fruit "+ "changes color to yellow with hard, strongly perfumed flesh.","Cydonia oblonga")};final String[] viewOptions = new String[] {"Title", "Binomial name", "Picture", "Description"};final Entry<String, Effect>[] effects = new Entry[] {new SimpleEntry<String, Effect>("Sepia Tone", new SepiaTone()),new SimpleEntry<String, Effect>("Glow", new Glow()),new SimpleEntry<String, Effect>("Shadow", new DropShadow())};final ImageView pic = new ImageView();final Label name = new Label();final Label binName = new Label();final Label description = new Label();public static void main(String[] args) {launch(args);}@Overridepublic void start(Stage stage) {stage.setTitle("Menu Sample");Scene scene = new Scene(new VBox(), 400, 350);scene.setFill(Color.OLDLACE);MenuBar menuBar = new MenuBar();// --- Menu FileMenu menuFile = new Menu("File");// --- Menu EditMenu menuEdit = new Menu("Edit");// --- Menu ViewMenu menuView = new Menu("View");menuBar.getMenus().addAll(menuFile, menuEdit, menuView);((VBox) scene.getRoot()).getChildren().addAll(menuBar);stage.setScene(scene);stage.show();}private class PageData {public String name;public String description;public String binNames;public Image image;public PageData(String name, String description, String binNames) {this.name = name;this.description = description;this.binNames = binNames;image = new Image(getClass().getResourceAsStream(name + ".jpg"));}}
}

与其他UI控件不同,Menu类的类和其他扩展MenuItem不会扩展Node类。它们无法直接添加到应用程序场景中,并且在通过该getMenus方法添加到菜单栏之前保持不可见。

图22-2菜单栏已添加到应用程序中

您可以使用键盘的箭头键浏览菜单。但是,当您选择菜单时,不执行任何操作,因为尚未定义菜单的行为。

 

添加菜单项

通过添加以下项来设置“文件”菜单的功能:

  • 随机播放 - 加载有关植物的参考信息

  • 清除 - 删除参考信息并清除场景

  • 分隔符 - 分离菜单项

  • 退出 - 退出应用程序

例22-2中的粗线通过使用MenuItem类创建了一个Shuffle菜单,并将图形组件添加到应用程序场景中。该MenuItem级能够创建带有文本和图形的动作项。用户单击执行的操作由setOnAction方法定义,类似于Button类。

示例22-2使用Graphics添加Shuffle菜单项

import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.effect.Glow;
import javafx.scene.effect.SepiaTone;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
import javafx.stage.Stage;public class MenuSample extends Application {final PageData[] pages = new PageData[] {new PageData("Apple","The apple is the pomaceous fruit of the apple tree, species Malus "+"domestica in the rose family (Rosaceae). It is one of the most "+"widely cultivated tree fruits, and the most widely known of "+"the many members of genus Malus that are used by humans. "+"The tree originated in Western Asia, where its wild ancestor, "+"the Alma, is still found today.","Malus domestica"),new PageData("Hawthorn","The hawthorn is a large genus of shrubs and trees in the rose "+ "family, Rosaceae, native to temperate regions of the Northern "+ "Hemisphere in Europe, Asia and North America. "+ "The name hawthorn was "+ "originally applied to the species native to northern Europe, "+ "especially the Common Hawthorn C. monogyna, and the unmodified "+ "name is often so used in Britain and Ireland.","Crataegus monogyna"),new PageData("Ivy","The ivy is a flowering plant in the grape family (Vitaceae) native"+" to eastern Asia in Japan, Korea, and northern and eastern China."+" It is a deciduous woody vine growing to 30 m tall or more given "+"suitable support,  attaching itself by means of numerous small "+"branched tendrils tipped with sticky disks.","Parthenocissus tricuspidata"),new PageData("Quince","The quince is the sole member of the genus Cydonia and is native"+" to warm-temperate southwest Asia in the Caucasus region. The "+"immature fruit is green with dense grey-white pubescence, most "+"of which rubs off before maturity in late autumn when the fruit "+"changes color to yellow with hard, strongly perfumed flesh.","Cydonia oblonga")};final String[] viewOptions = new String[] {"Title", "Binomial name", "Picture", "Description"};final Entry<String, Effect>[] effects = new Entry[] {new SimpleEntry<String, Effect>("Sepia Tone", new SepiaTone()),new SimpleEntry<String, Effect>("Glow", new Glow()),new SimpleEntry<String, Effect>("Shadow", new DropShadow())};final ImageView pic = new ImageView();final Label name = new Label();final Label binName = new Label();final Label description = new Label();private int currentIndex = -1;public static void main(String[] args) {launch(args);}@Overridepublic void start(Stage stage) {stage.setTitle("Menu Sample");Scene scene = new Scene(new VBox(), 400, 350);scene.setFill(Color.OLDLACE);name.setFont(new Font("Verdana Bold", 22));binName.setFont(new Font("Arial Italic", 10));pic.setFitHeight(150);pic.setPreserveRatio(true);description.setWrapText(true);description.setTextAlignment(TextAlignment.JUSTIFY);shuffle();MenuBar menuBar = new MenuBar();final VBox vbox = new VBox();vbox.setAlignment(Pos.CENTER);vbox.setSpacing(10);vbox.setPadding(new Insets(0, 10, 0, 10));vbox.getChildren().addAll(name, binName, pic, description);// --- Menu FileMenu menuFile = new Menu("File");MenuItem add = new MenuItem("Shuffle",new ImageView(new Image("menusample/new.png")));add.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent t) {shuffle();vbox.setVisible(true);}});        menuFile.getItems().addAll(add);// --- Menu EditMenu menuEdit = new Menu("Edit");// --- Menu ViewMenu menuView = new Menu("View");menuBar.getMenus().addAll(menuFile, menuEdit, menuView);((VBox) scene.getRoot()).getChildren().addAll(menuBar, vbox);stage.setScene(scene);stage.show();}private void shuffle() {int i = currentIndex;while (i == currentIndex) {i = (int) (Math.random() * pages.length);}pic.setImage(pages[i].image);name.setText(pages[i].name);binName.setText("(" + pages[i].binNames + ")");description.setText(pages[i].description);currentIndex = i;}private class PageData {public String name;public String description;public String binNames;public Image image;public PageData(String name, String description, String binNames) {this.name = name;this.description = description;this.binNames = binNames;image = new Image(getClass().getResourceAsStream(name + ".jpg"));}}
} 

当用户选择Shuffle菜单项时,shuffle调用的方法setOnAction通过计算相应数组中元素的索引来指定标题,二项式名称,工厂图片及其描述。

“清除”菜单项用于擦除应用程序场景。您可以通过使VBox具有GUI元素的容器不可见来实现此操作,如例22-3所示。

示例22-3使用加速器创建清除菜单项

MenuItem clear = new MenuItem("Clear");
clear.setAccelerator(KeyCombination.keyCombination("Ctrl+X"));
clear.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent t) {vbox.setVisible(false);}
});

在实施MenuItem类别可让开发设置菜单加速器,执行相同的动作的菜单项的组合键。使用“清除”菜单,用户可以从“文件”菜单类别中选择操作,也可以同时按下“控制键”和“X”键。

Exit菜单关闭应用程序窗口。设置System.exit(0)为此菜单项的操作,如例22-4所示。

示例22-4创建退出菜单项

MenuItem exit = new MenuItem("Exit");
exit.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent t) {System.exit(0);}
});

使用示例22-5中getItems显示的方法将新创建的菜单项添加到“文件”菜单。您可以创建一个分隔符菜单项并将其添加到方法中,以便可视地分离“退出”菜单项。getItems

示例22-5添加菜单项

menuFile.getItems().addAll(add, clear, new SeparatorMenuItem(), exit);

将示例22-2,示例22-3,示例22-4和示例22-5添加到Menu Sample应用程序,然后编译并运行它。选择Shuffle菜单项以加载有关不同植物的参考信息。然后清除场景(清除),并关闭应用程序(退出)。图22-3显示了Clear菜单项的选择。

图22-3包含三个菜单项的文件菜单

使用“视图”菜单,您可以隐藏和显示参考信息的元素。实现createMenuItem方法并在方法中调用它start以创建四个CheckMenuItem对象。然后将新创建的检查菜单项添加到“视图”菜单,以切换标题,二项式名称,工厂图片及其描述的可见性。例22-6显示了实现这些任务的两个代码片段。

示例22-6应用CheckMenuItem类创建切换选项

// --- Creating four check menu items within the start method
CheckMenuItem titleView = createMenuItem ("Title", name);                                                       
CheckMenuItem binNameView = createMenuItem ("Binomial name", binName);        
CheckMenuItem picView = createMenuItem ("Picture", pic);        
CheckMenuItem descriptionView = createMenuItem ("Description", description);     
menuView.getItems().addAll(titleView, binNameView, picView, descriptionView);...// The createMenuItem method
private static CheckMenuItem createMenuItem (String title, final Node node){CheckMenuItem cmi = new CheckMenuItem(title);cmi.setSelected(true);cmi.selectedProperty().addListener(new ChangeListener<Boolean>() {public void changed(ObservableValue ov,Boolean old_val, Boolean new_val) {node.setVisible(new_val);}});return cmi;
}

CheckMenuItem班是的扩展MenuItem类。它可以在选定和取消选择的状态之间切换。选中后,检查菜单项会显示复选标记。

例22-6创建了四个CheckMenuItem对象并处理其selectedProperty属性的更改。例如,当用户取消选择该项时picView,该setVisible方法接收该false值,该工厂的图片变得不可见。将此代码片段添加到应用程序,编译并运行应用程序时,您可以尝试选择和取消选择菜单项。图22-4显示了显示工厂标题和图片时的应用程序,但隐藏了其二项式名称和描述。

图22-4使用检查菜单项

 

创建子菜单

对于“编辑”菜单,定义两个菜单项:“图片效果”和“无效果”。“图片效果”菜单项被设计为具有三个项目的子菜单,用于设置三种可用视觉效果中的一种。“无效果”菜单项将删除所选效果并恢复图像的初始状态。

使用RadioMenuItem该类创建子菜单的项目。将单选菜单按钮添加到切换组以使选择互斥。例22-7实现了这些任务。

示例22-7使用单选菜单项创建子菜单

//Picture Effect menu
Menu menuEffect = new Menu("Picture Effect");
final ToggleGroup groupEffect = new ToggleGroup();
for (Entry<String, Effect> effect : effects) {RadioMenuItem itemEffect = new RadioMenuItem(effect.getKey());itemEffect.setUserData(effect.getValue());itemEffect.setToggleGroup(groupEffect);menuEffect.getItems().add(itemEffect);
}
//No Effects menu
final MenuItem noEffects = new MenuItem("No Effects");noEffects.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent t) {pic.setEffect(null);groupEffect.getSelectedToggle().setSelected(false);}
});//Processing menu item selection
groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {public void changed(ObservableValue<? extends Toggle> ov,Toggle old_toggle, Toggle new_toggle) {if (groupEffect.getSelectedToggle() != null) {Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData();pic.setEffect(effect);}}});
//Adding items to the Edit menu
menuEdit.getItems().addAll(menuEffect, noEffects);

setUserData方法定义特定无线电菜单项的视觉效果。当选择切换组中的一个项目时,相应的效果将应用于图片。选择“无效果”菜单项时,该setEffect方法指定该null值,并且不对图片应用任何效果。

图22-5捕获用户选择Shadow菜单项的时刻。

图22-5带有三个单选菜单项的子菜单

DropShadow效果被施加到图像,它看起来如图图22-6。

图22-6应用了DropShadow效果的Quince图片

在“图片效果”子菜单中未选择任何效果时,可以使用类的setDisable方法MenuItem禁用“无效果”菜单。修改例22-7,如例22-8所示。

示例22-8禁用菜单项

Menu menuEffect = new Menu("Picture Effect");
final ToggleGroup groupEffect = new ToggleGroup();
for (Entry<String, Effect> effect : effects) {RadioMenuItem itemEffect = new RadioMenuItem(effect.getKey());itemEffect.setUserData(effect.getValue());itemEffect.setToggleGroup(groupEffect);menuEffect.getItems().add(itemEffect);
}
final MenuItem noEffects = new MenuItem("No Effects");
noEffects.setDisable(true);      
noEffects.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent t) {pic.setEffect(null);groupEffect.getSelectedToggle().setSelected(false);noEffects.setDisable(true);}
});groupEffect.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {public void changed(ObservableValue<? extends Toggle> ov,Toggle old_toggle, Toggle new_toggle) {if (groupEffect.getSelectedToggle() != null) {Effect effect = (Effect) groupEffect.getSelectedToggle().getUserData();pic.setEffect(effect);noEffects.setDisable(false);} else {noEffects.setDisable(true);}}
});
menuEdit.getItems().addAll(menuEffect, noEffects);

如果未RadioMenuItem选择任何选项,则禁用“无效果”菜单项,如图22-7所示。当用户选择其中一个视觉效果时,将启用“无效果”菜单项。

图22-7效果菜单项被禁用

 

添加上下文菜单

如果无法为所需功能分配用户界面的任何空间,则可以使用上下文菜单。上下文菜单是一个弹出窗口,响应鼠标单击而显示。上下文菜单可以包含一个或多个菜单项。

在“菜单示例”应用程序中,为工厂的图片设置上下文菜单,以便用户可以复制图像。

使用ContextMenu该类定义上下文菜单,如例22-9所示。

示例22-9定义上下文菜单

final ContextMenu cm = new ContextMenu();
MenuItem cmItem1 = new MenuItem("Copy Image");
cmItem1.setOnAction(new EventHandler<ActionEvent>() {public void handle(ActionEvent e) {Clipboard clipboard = Clipboard.getSystemClipboard();ClipboardContent content = new ClipboardContent();content.putImage(pic.getImage());clipboard.setContent(content);}
});cm.getItems().add(cmItem1);
pic.addEventHandler(MouseEvent.MOUSE_CLICKED,new EventHandler<MouseEvent>() {@Override public void handle(MouseEvent e) {if (e.getButton() == MouseButton.SECONDARY)  cm.show(pic, e.getScreenX(), e.getScreenY());}
});

当用户右键单击该ImageView对象时,将show调用该方法以使其显示上下文菜单。

setOnAction为上下文菜单的“复制图像”项定义的方法会创建一个Clipboard对象,并将图像添加为其内容。图22-8捕获用户选择“复制图像”上下文菜单项的时刻。

图22-8使用上下文菜单

您可以尝试复制图像并将其粘贴到图形编辑器中。

要进一步增强,可以向上下文菜单添加更多菜单项并指定不同的操作。您还可以使用CustomMenuItem该类创建自定义菜单。使用此类,您可以在菜单中嵌入任意节点,并指定例如按钮或滑块作为菜单项。

 

相关的API文档 

  • Menu

  • MenuItem

  • RadioMenuItem

  • CheckMenuItem

  • ContextMenu

  • SeparatorMenuItem

  • CustomMenuItem

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/325027.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

利用bootstraptable展示数据,对数据进行排序分页等操作

今天分享一下bootstraptable的相关技能点&#xff0c;由于第一次接触&#xff0c;所以刚开始碰了好多壁&#xff0c;于是趁现在过去不久&#xff0c;先总结总结。 Bootstraptable简单的来说就是一个表格控件&#xff0c;但是这个表格可不是一般的表格&#xff0c;分页、排序、…

JavaScript BOM

标题什么是BOM 1.BOM是Browser Object Model的简写&#xff0c;即浏览器对象模型。 2.BOM由一系列对象组成&#xff0c;是访问、控制、修改浏览器的属性的方法 3.BOM没有统一的标准(每种客户端都可以自定标准)。 4.BOM的顶层是window对象 BOM对象学习 window <!DOCTYPE h…

OJ8462-大盗阿福【各种dp之5】

题目 我们的黑虎阿福改行当小偷啦!然后他去偷东西&#xff0c;然后那个zz报警系统只有在他洗劫两家相邻的店才会报警&#xff0c;然后求他在不触发警报的情况下能拿到最多的钱。 &#xff08;注&#xff1a;没有偷了会扣钱的店铺&#xff09; 输入 2 3 1 8 2 4 10 7 6 1…

交换两个对象

//问题二&#xff1a;使用冒泡排序按学生成绩排序&#xff0c;并遍历所有学生信息for(int i 0;i < stus.length - 1;i){for(int j 0;j < stus.length - 1 - i;j){if(stus[j].score > stus[j 1].score){//如果需要换序&#xff0c;交换的是数组的元素&#xff1a;St…

JavaFX UI控件教程(二十四)之Password Field

翻译自 Password Field 在本章中&#xff0c;您将了解另一种类型的文本控件&#xff0c;即密码字段。 本PasswordField类实现一个专门的文本字段。通过显示回显字符串来隐藏用户键入的字符。图23-1显示了一个密码字段&#xff0c;其中包含提示消息。 图23-1带有提示消息的密…

3分钟内看完这,bootstraptable表格控件,受益匪浅!

今天分享一下bootstraptable的相关技能点&#xff0c;由于第一次接触&#xff0c;所以刚开始碰了好多壁&#xff0c;于是趁现在过去不久&#xff0c;先总结总结。Bootstraptable简单的来说就是一个表格控件&#xff0c;但是这个表格可不是一般的表格&#xff0c;分页、排序、查…

微软Azure开源开发者(深圳)峰会等你来

微软开发技术与云平台自从迈向开放、开源、跨平台的转型以来&#xff0c;已经受到全球开源社区们的关注。 从 Github 上高居世界首位的开源项目贡献数量&#xff0c;可以看到微软贯彻开源战略的实际行动。另一方面&#xff0c;微软也主动与开源社区做密切的技术交流。 本次 Azu…

OJ4121 and OJ2968-股票买卖 and Maximun sum【各种dp之6 and 9】

股票买卖 题目 阿福该炒股了&#xff0c;然后假设他已经预测到了后几天的股票&#xff0c;要求他最多买卖两次的赚到的最大值。 &#xff08;注&#xff1a;他只有第一次卖了才能再买&#xff09; 输入 3 7 5 14 -2 4 9 3 17 6 6 8 7 4 1 -2 4 18 9 5 2 输出 28 2…

面向对象VS面向过程

1.面向过程&#xff1a;强调的是功能行为&#xff0c;以函数为最小单位&#xff0c;考虑怎样做。 2.面向对象&#xff1a;强调具备了功能的对象&#xff0c;以类/对象为最小单位&#xff0c;考虑谁来做。

这个点名系统太好用了,快来看看……

声明&#xff1a;软件为本人原创&#xff0c;后台回复&#xff1a;随机点名系统&#xff0c;免费下载。大家好&#xff0c;我是雄雄&#xff0c;昨天公众号给大家分享了windows系统和office办公软件激活的方法&#xff0c;正中好多粉丝的下怀。【原文在这里】今天在给大家分享一…

JavaFX UI控件教程(二十二)之Titled Pane和Accordion

翻译自 Titled Pane and Accordion 本章介绍如何在JavaFX应用程序中使用accordion和title窗格的组合。 标题窗格是带标题的面板。它可以打开和关闭&#xff0c;它可以封装任何Node诸如UI控件或图像以及添加到布局容器的元素组。 标题窗格可以使用手风琴控件进行分组&#x…

在ASP.NET Core 2.0中使用MemoryCache

说到内存缓存大家可能立马想到了HttpRuntime.Cache,它位于System.Web命名空间下&#xff0c;但是在ASP.NET Core中System.Web已经不复存在。今儿个就简单的聊聊如何在ASP.NET Core中使用内存缓存。我们一般将经常访问但是又不是经常改变的数据放进缓存是再好不过了&#xff0c;…

ssl1016 OJ8467-数的划分 鸣人的影分身【各种dp之8 7】

数的划分 Description 将整数n分成k份&#xff0c;且每份不能为空&#xff0c;任意两份不能相同(不考虑顺序)。   例如&#xff1a;n7&#xff0c;k3 (6&#xff1c;n&#xff1c;&#xff1d;200,2&#xff1c;&#xff1d;k&#xff1c;&#xff1d;6&#xff09;&#…

数据库的嵌套查询和统计查询

①求选修了数据结构的学生学号和成绩。 select s_no,score from choice where s_no in (select s_no from course where course_name数据结构) ②求01001课程的成绩高于张彬的学生学号和成绩。 select s_no,score from choice where course_no01001 and score>(select scor…

匿名对象的使用

package com.wdl.day09;/** 匿名对象的使用* 1.理解&#xff1a;我们创建的对象&#xff0c;没有显式的赋给一个变量名。即为匿名对象* 2.特征&#xff1a;匿名对象只能调用一次。* 3.使用&#xff1a;如下**/ public class InstanceTest {public static void main(String[] ar…

sql server中创建数据库和表的语法

下面是sql server中创建数据库&#xff0c;创建数据表以及添加约束的sql语句&#xff1a; use master --创建数据库 if exists (select * from sysdatabases where name jobtest)drop database jobtest create database jobtest on (namejobtest_data,filename D:\DB\jobtes…

在ASP.NET Core 2.0中使用CookieAuthentication

在ASP.NET Core中关于Security有两个容易混淆的概念一个是Authentication&#xff08;认证&#xff09;&#xff0c;一个是Authorization&#xff08;授权&#xff09;。而前者是确定用户是谁的过程&#xff0c;后者是围绕着他们允许做什么&#xff0c;今天的主题就是关于在ASP…

JavaFX UI控件教程(二十五)之Color Picker

翻译自 Color Picker 本章介绍ColorPicker控件&#xff0c;提供其设计概述&#xff0c;并说明如何在JavaFX应用程序中使用它。 JavaFX SDK中的颜色选择器控件是一个典型的用户界面组件&#xff0c;使用户可以从可用范围中选择特定颜色&#xff0c;或通过指定RGB或HSB组合来设…

ssl1217-删边【图论,dfs】

题目 给出一个连通无向图&#xff0c;求最多能删掉多少条边后还是连通图。 输入 4(顶点数) 6(边数) 1 2 (表示一条点1到点2的线) 1 3 1 4 2 3 2 4 3 4 输出 3 dfs解题思路 这道题其实不用dfs更简单&#xff0c;但是毕竟例题还是用一下吧。 首先我们如果到达一个点便…

英语不会读怎么办?它来教你……

大家好&#xff0c;我是雄雄&#xff0c;今天我又给大家分享好看又实用的软件啦~今天给大家分享的是一个比昨天的随机点名系统还要实用的软件&#xff0c;如果说昨天的随机点名系统只适合老师或者某些需要点名的朋友使用的话&#xff0c;那么今天分享的软件则是一个人人都可使用…