From 94f63a321f89b83d8c70b0795854301fb33b4f5a Mon Sep 17 00:00:00 2001 From: siqq Date: Sun, 7 Sep 2014 03:17:24 +0300 Subject: [PATCH] OrefPanel class Improvements --- Java-Missle/src/view/OrefPanel.java | 44 ++++++++++++++--------------- Java-Missle/src/view/WarGui.java | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Java-Missle/src/view/OrefPanel.java b/Java-Missle/src/view/OrefPanel.java index 6453098..ee60d25 100644 --- a/Java-Missle/src/view/OrefPanel.java +++ b/Java-Missle/src/view/OrefPanel.java @@ -36,43 +36,43 @@ public OrefPanel() { .getResource(OREF_IMAGE_PATH))); add(orefImageLable); - topAlert = new JTextField(" "); - topAlert.setBackground(new Color(255, 127, 80)); - add(topAlert); - topAlert.setColumns(10); + topAlert = createNewAlert(); + middleAlert = createNewAlert(); + buttomAlert = createNewAlert(); - middleAlert = new JTextField(" "); - middleAlert.setBackground(new Color(255, 127, 80)); + add(topAlert); add(middleAlert); - middleAlert.setColumns(10); - - buttomAlert = new JTextField(" "); - buttomAlert.setBackground(new Color(255, 127, 80)); add(buttomAlert); - buttomAlert.setColumns(10); - topAlert.setFont(font); - middleAlert.setFont(font); - buttomAlert.setFont(font); - - topAlert.setForeground(Color.WHITE); - ; + } - topAlert.setEditable(false); - middleAlert.setEditable(false); - buttomAlert.setEditable(false); + public JTextField createNewAlert() { + JTextField textBox = new JTextField(""); + textBox.setBackground(new Color(255, 127, 80)); + textBox.setColumns(10); + textBox.setFont(font); + textBox.setForeground(Color.WHITE); + textBox.setHorizontalAlignment(JTextField.CENTER); + textBox.setEditable(false); + return textBox; } - public void addMissileToOrefPanel(String destination, int time) { + public void addMissileToOrefPanel(String destination, int time, int flyTime) { if (time < ALERT_DISPLAY_TIME && time % 2 == 0) { - topAlert.setText(" Alert in " + destination); + topAlert.setText("Alert in " + destination); validate(); } else if (time < ALERT_DISPLAY_TIME) { topAlert.setText(""); } else { + topAlert.setText(""); // the alert is finished, free the topAlert Label } + if (time == flyTime) { + // if missile flyTime is less then ALERT_DISPLAY_TIME + topAlert.setText(""); + + } } } diff --git a/Java-Missle/src/view/WarGui.java b/Java-Missle/src/view/WarGui.java index 276c8a8..fc62c0b 100644 --- a/Java-Missle/src/view/WarGui.java +++ b/Java-Missle/src/view/WarGui.java @@ -215,7 +215,7 @@ public void updateMissileProgress(int time, String missileId, String type, String destination, int damage, int flyTime) { progressPanel.updateMissileTime(time, missileId, type,destination,damage,flyTime); - orefPanel.addMissileToOrefPanel(destination, time); + orefPanel.addMissileToOrefPanel(destination, time, flyTime); } public void selectIronDomeToFireFrom(String missileId) {