当我运行这个程序
public class Fabric extends Thread {
public static void main(String[] args) {
Thread t1 = new Thread(new Fabric());
Thread t2 = new Thread(new Fabric());
Thread t3 = new Thread(new Fabric());
t1.start();
t2.start();
t3.start();
}
public void run() {
for(int i = 0; i < 2; i++)
System.out.print(Thread.currentThread().getName() + " ");
}
}
Run Code Online (Sandbox Code Playgroud)
我得到输出
Thread-1 Thread-5 Thread-5 Thread-3 Thread-1 Thread-3
Run Code Online (Sandbox Code Playgroud)
是否有任何具体原因为什么线程被赋予奇数的名称 - 1,3,5 ...或者它是不可预测的?
我正在使用GridPane在JavaFX中创建一个棋盘游戏.
有7种不同的动画可以放置在网格的每个网格(单元格)中.
最初网格看起来像这样
我在编程动画插入之前测试了添加一个简单的圆圈.它看起来像这样
添加的节点是SubScenes,包括TimeLine动画.每个单元大小为40x40,SubScene大小也为40x40.
添加后的子场景,位于网格窗格边框线的顶部,看起来不太好.
我该怎么办才能将节点添加到网格线下面?即网格线位于节点之上.
如果使用GridPane是不可能的,还有什么我可以使用的吗?
我为游戏执行的课程
class Game {
static GridPane grid;
public void start(final Stage stage) throws Exception {
int rows = 5;
int columns = 5;
stage.setTitle("Enjoy your game");
grid = new GridPane();
for(int i = 0; i < columns; i++) {
ColumnConstraints column = new ColumnConstraints(40);
grid.getColumnConstraints().add(column);
}
for(int i = 0; i < rows; i++) {
RowConstraints row = new RowConstraints(40);
grid.getRowConstraints().add(row);
}
grid.setOnMouseReleased(new EventHandler<MouseEvent> () {
public void handle(MouseEvent me) {
grid.add(Anims.getAnim(1), …Run Code Online (Sandbox Code Playgroud) 这是我一直在尝试的代码
import java.util.Scanner;
import java.io.*;
abstract class Account implements Serializable {
protected String accountHolderName;
protected long balance;
protected ObjectOutputStream accData;
Scanner input = new Scanner(System.in);
}
class Savings extends Account implements Serializable {
Savings() throws IOException {
System.out.print("enter your name: ");
accountHolderName = input.nextLine();
System.out.print("\n");
System.out.print("enter your balance: ");
balance = input.nextLong();
accData = new ObjectOutputStream(new FileOutputStream(accountHolderName + ".bin"));
accData.writeObject(this);
accData.close();
}
}
class Banking implements Serializable {
public static void main(String args[]) throws IOException {
Scanner input = new …Run Code Online (Sandbox Code Playgroud) 我一直在学习WPF.我尝试在我的WPF应用程序中使用Threading,但我想我错过了一些东西.
我在窗口放了一个按钮和一个标签.如果我按下按钮,我希望标签改变它的背景颜色...... 2秒后,设置原始背景颜色.
这是XAML和我一直在尝试的代码.
MainWindow.XAML
<Window x:Class="UITest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:UITest"
mc:Ignorable="d"
Title="MainWindow" Height="519" Width="656">
<StackPanel>
<Button x:Name="button1" Width="60" Height="30" Content="Button" Margin="10 10 0 0" BorderThickness="0" BorderBrush="{x:Null}" Padding="0" HorizontalAlignment="Left" VerticalAlignment="Top">
</Button>
<Label x:Name="label1" Width="100" Height="30" Margin="10 10 0 0" BorderThickness="0" BorderBrush="{x:Null}" Padding="0" HorizontalAlignment="Left" VerticalAlignment="Top" Background="Bisque">
</Label>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
MainWindow.XAML.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; …Run Code Online (Sandbox Code Playgroud) 我刚从文档开始学习python 2.7.11.我是做这是在那里给出的例子,但在弄糊涂了print,并r进行了介绍.我对如何将反斜杠显示为输出感到困惑.这与字符转义相关,但到目前为止我只是用于\b退格,\n新行,\\反斜杠
这就是我所说的:
有四种不同的情况:
既不使用print也不使用r
使用print但不是r
使用r但不是print
使用print和r
并且他们都提供不同的输出.我无法理解四种情况下实际发生的事情.