Demo entry 6347371

java

   

Submitted by java on Feb 14, 2017 at 12:01
Language: Java. Code size: 4.0 kB.

public class BasicStage {
	final String[] lbMapKey = {"firePos", "highestT", "highestTPos", "highestSmog", 
			"highestSmogPos", "assumeFire", "T", "smog", "light", "set"};
	final String[] tfMapKey = {"firePos", "highestT", "highestTPos", "highestSmog", 
			"highestSmogPos", "assumeFire1", "assumeFire2", "T", "smog", "light"};
	final String[] lbMapKeyChinese = {"火点位置:", "最高温度:", "最高温度位置:", "最高烟雾:", 
			"最高烟雾位置:", "模拟火灾点:", "温度", "烟雾", "光感", "设置"};
	
	public HashMap<String, Label> lbMap = new HashMap<String, Label>();
	public HashMap<String, TextField> tfMap = new HashMap<String, TextField>();
	public Button btResetAssume = new Button("重置");
	public Button btResetSet = new Button("重置");
	public Button btOkAssume = new Button("确定");
	public Button btOkSet = new Button("确定");
	public Button btHistory = new Button("历史记录");
	
	ImageView img = new ImageView("image//pic.png");
	Image imgCrossing = new Image("image//crossing.png");
	Image imgSafe = new Image("image//safe.png");
	Image imgLeft = new Image("image//left.png");
	Image imgRight = new Image("image//Right.png");
	
	Pane paneImg = new Pane();
	HBox hboxBtAssume = new HBox(80);	
	HBox hboxBtSet = new HBox(80);
	HBox hboxTfAssumeFire = new HBox(5);
	HBox hboxT = new HBox(5);
	HBox hboxSmog = new HBox(5);
	HBox hboxLight = new HBox(5);
	
	GridPane gridPane = new GridPane();
	
	HBox hbox = new HBox(10);
	Scene scene = new Scene(hbox);
	Stage stage = new Stage();
	
	public BasicStage() {
		creatNode();
		
		/* 设置hboxBtAssume, hboxBtSet */
		hboxBtAssume.getChildren().addAll(btResetAssume, btOkAssume);
		hboxBtSet.getChildren().addAll(btResetSet, btOkSet);
		/* 设置hboxTfAssumeFire */
		hboxTfAssumeFire.getChildren().addAll(tfMap.get("assumeFire1"), tfMap.get("assumeFire2"));
		
		hboxT.getChildren().addAll(lbMap.get("T"), tfMap.get("T"));
		hboxSmog.getChildren().addAll(lbMap.get("smog"), tfMap.get("smog"));
		hboxLight.getChildren().addAll(lbMap.get("light"), tfMap.get("light"));
		
		paneImg.getChildren().addAll(img, new ImageView(imgLeft));
		
		/* 设置gridPane,并向其中添加节点 */
		gridPane.setAlignment(Pos.TOP_CENTER);
		gridPane.setHgap(10);
		gridPane.setVgap(10);
		addNodeIntoGP();
		
		/* 将gridPane, hboxImg添加到hbox中 */
		hbox.getChildren().addAll(paneImg, gridPane);
		hbox.setPadding(new Insets(10, 10, 10, 10));
		stage.setTitle("火灾路线生成系统");
		stage.setScene(scene);
	}
	
	private void creatNode() {
		/* 创建label,并设置字体为 Microsoft YaHei 20,将其加入到lbMap中 */
		for(int i = 0; i < lbMapKey.length; i++) {
			Label lbTemp = new Label(lbMapKeyChinese[i]);
			lbTemp.setFont(Font.font("Microsoft YaHei", 20));
			lbMap.put(lbMapKey[i], lbTemp);
		}
		
		/* 创建TextField对象,并设置长度(150,100,90), editable属性 */
		for(int i = 0; i < tfMapKey.length; i++) {
			TextField tfTemp = new TextField();
			if( tfMapKey[i].equals("T") || tfMapKey[i].equals("smog") || tfMapKey[i].equals("light") ){
				tfTemp.setMaxWidth(90);
			}else if( tfMapKey[i].startsWith("assume") ){
				tfTemp.setMaxWidth(90);
			}else {
				tfTemp.setMaxWidth(150);
				tfTemp.setEditable(false);
			}	
			tfMap.put(tfMapKey[i], tfTemp);
		}
		
	}
	
	private void addNodeIntoGP() {
		gridPane.addRow(0, lbMap.get("firePos"), tfMap.get("firePos"));
		gridPane.addRow(1, lbMap.get("highestT"), tfMap.get("highestT"));	
		gridPane.addRow(2, lbMap.get("highestTPos"), tfMap.get("highestTPos"));
		gridPane.addRow(3, lbMap.get("highestSmog"), tfMap.get("highestSmog"));
		gridPane.addRow(4, lbMap.get("highestSmogPos"), tfMap.get("highestSmogPos"));
		
		gridPane.addRow(5, new Label(""));
		gridPane.addRow(6, lbMap.get("assumeFire"), hboxTfAssumeFire);
		
		gridPane.add(hboxBtAssume, 1, 7);
		gridPane.addRow(8, new Label(""));
		gridPane.addRow(9, lbMap.get("set"));
		gridPane.addRow(10, hboxT, hboxSmog);
		gridPane.addRow(11, hboxLight);
		gridPane.add(hboxBtSet, 1, 12);
		gridPane.addRow(13, new Label(""));
		gridPane.addRow(14, btHistory);
	}
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).