diff options
author | cirakg <ciraboxkg@gmail.com> | 2023-01-15 19:31:41 +0100 |
---|---|---|
committer | cirakg <ciraboxkg@gmail.com> | 2023-01-15 19:31:41 +0100 |
commit | 65c2dc33666ac35d5229018b604a8fd0e1f708a3 (patch) | |
tree | d20cd1bea61f5c52794c4a78ca6b56b589b68df3 | |
parent | da977ffa778d5bda4bba4d0f36db602ae1384b3c (diff) |
Ispravljeno brisanje chat box-a izmedju igara. Dodat deo tooltip-a na game panel-u.
-rw-r--r-- | src/main/java/ui/GamePanel.java | 34 | ||||
-rw-r--r-- | src/main/java/ui/MainFrame.java | 7 |
2 files changed, 19 insertions, 22 deletions
diff --git a/src/main/java/ui/GamePanel.java b/src/main/java/ui/GamePanel.java index e16482d..edd18ce 100644 --- a/src/main/java/ui/GamePanel.java +++ b/src/main/java/ui/GamePanel.java @@ -168,17 +168,14 @@ public class GamePanel extends JPanel { txtAreaChat = new JTextArea(); txtAreaChat.setEditable(false); txtAreaChat.setLineWrap(true); - txtAreaChat.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Est ultricies integer quis auctor elit sed. Urna nunc id cursus metus aliquam eleifend mi. Amet consectetur adipiscing elit pellentesque habitant morbi tristique senectus. Consequat interdum varius sit amet mattis vulputate enim nulla aliquet. Tristique magna sit amet purus gravida quis blandit. Eget gravida cum sociis natoque penatibus. Nec tincidunt praesent semper feugiat nibh. Maecenas sed enim ut sem. Pulvinar neque laoreet suspendisse interdum consectetur. Diam maecenas ultricies mi eget mauris pharetra. Sollicitudin aliquam ultrices sagittis orci. Nulla facilisi etiam dignissim diam quis."); + txtAreaChat.setText(""); scrollPane.setViewportView(txtAreaChat); btnBack = new JButton("Return to choose opponent"); btnBack.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnBack.setVisible(false); - MainFrame topFrame=(MainFrame) SwingUtilities.getAncestorOfClass(MainFrame.class, GamePanel.this); - topFrame.getContentPane().removeAll(); - topFrame.getContentPane().add(topFrame.chooseOpponentPanel,BorderLayout.CENTER); - SwingUtilities.updateComponentTreeUI(topFrame); + returnBack(); } }); @@ -188,7 +185,7 @@ public class GamePanel extends JPanel { lblToolTip = new JLabel("(?)"); lblToolTip.setBounds(180, 105, 23, 14); - lblToolTip.setToolTipText("<html>Igra<br> Korisnici se bore po potezima. Koristeci izabrane napade <br>Prikazane su sve potrebne informacije za vodjenje igre.<br> Korisnici mogu koristiti chat za komunikaciju.<br> Po zavrsetku igre korisnici dobijaju obavestenje o rezultatu igre i<br> opciju da se vrate na stranicu za biranje protivnika</html>"); + lblToolTip.setToolTipText("<html>Igra<br> Korisnici se bore po potezima. Koristeci izabrane napade <br>Prikazane su sve potrebne informacije za vodjenje igre.<br> Korisnici mogu koristiti chat za komunikaciju.<br> Po zavrsetku igre korisnici dobijaju obavestenje o rezultatu igre i<br> opciju da se vrate na stranicu za biranje protivnika<br>U chatu su validni svi karakeri osim :</html>"); add(lblToolTip); add(lblToolTip); @@ -265,9 +262,7 @@ public class GamePanel extends JPanel { btnShield.setEnabled(false); int optionres=JOptionPane.showConfirmDialog(null, "YOU WIN!!! Do you want to return to choose opponent page", "Result:"+you, JOptionPane.YES_NO_OPTION); if(optionres==JOptionPane.OK_OPTION) { - topFrame.getContentPane().removeAll(); - topFrame.getContentPane().add(topFrame.chooseOpponentPanel,BorderLayout.CENTER); - SwingUtilities.updateComponentTreeUI(topFrame); + returnBack(); } else @@ -280,9 +275,7 @@ public class GamePanel extends JPanel { btnShield.setEnabled(false); int optionres=JOptionPane.showConfirmDialog(null, "YOU LOSE!!! Do you want to return to choose opponent page", "Result"+you, JOptionPane.YES_NO_OPTION); if(optionres==JOptionPane.OK_OPTION) { - topFrame.getContentPane().removeAll(); - topFrame.getContentPane().add(topFrame.chooseOpponentPanel,BorderLayout.CENTER); - SwingUtilities.updateComponentTreeUI(topFrame); + returnBack(); } else @@ -331,9 +324,7 @@ public class GamePanel extends JPanel { btnShield.setEnabled(false); int optionres=JOptionPane.showConfirmDialog(null, "YOU LOSE!!! Do you want to return to choose opponent page", "Result"+you, JOptionPane.YES_NO_OPTION); if(optionres==JOptionPane.OK_OPTION) { - topFrame.getContentPane().removeAll(); - topFrame.getContentPane().add(topFrame.chooseOpponentPanel,BorderLayout.CENTER); - SwingUtilities.updateComponentTreeUI(topFrame); + returnBack(); } else @@ -346,9 +337,7 @@ public class GamePanel extends JPanel { btnShield.setEnabled(false); int optionres=JOptionPane.showConfirmDialog(null, "YOU WIN!!! Do you want to return to choose opponent page", "Result:"+you, JOptionPane.YES_NO_OPTION); if(optionres==JOptionPane.OK_OPTION) { - topFrame.getContentPane().removeAll(); - topFrame.getContentPane().add(topFrame.chooseOpponentPanel,BorderLayout.CENTER); - SwingUtilities.updateComponentTreeUI(topFrame); + returnBack(); } else @@ -420,6 +409,15 @@ public class GamePanel extends JPanel { return image; } + public void returnBack() { + MainFrame topFrame=(MainFrame) SwingUtilities.getAncestorOfClass(MainFrame.class, GamePanel.this); + topFrame.getContentPane().removeAll(); + topFrame.getContentPane().add(topFrame.chooseOpponentPanel,BorderLayout.CENTER); + topFrame.gamePanel.txtAreaChat.setText(null);//clear chat between games + topFrame.gamePanel.chat=""; + SwingUtilities.updateComponentTreeUI(topFrame); + + } public JTextArea getTxtAreaChat() { return txtAreaChat; diff --git a/src/main/java/ui/MainFrame.java b/src/main/java/ui/MainFrame.java index dc4b7f5..282ddde 100644 --- a/src/main/java/ui/MainFrame.java +++ b/src/main/java/ui/MainFrame.java @@ -139,6 +139,8 @@ public class MainFrame extends JFrame implements Runnable { System.out.println("OPPONENTLEFT"); this.getContentPane().removeAll(); this.getContentPane().add(this.chooseOpponentPanel,BorderLayout.CENTER); + this.gamePanel.txtAreaChat.setText(null);//clear chat between games + this.gamePanel.chat=""; SwingUtilities.updateComponentTreeUI(this); }else { //XML OBJECTS @@ -163,10 +165,7 @@ public class MainFrame extends JFrame implements Runnable { this.getContentPane().add(this.gamePanel,BorderLayout.CENTER); SwingUtilities.updateComponentTreeUI(this); this.game=game; - this.gamePanel.loadElements(); - this.gamePanel.txtAreaChat.setText(null);//clear chat between games - this.gamePanel.chat=""; - + this.gamePanel.loadElements(); } } catch (Exception e) { |