From 65c2dc33666ac35d5229018b604a8fd0e1f708a3 Mon Sep 17 00:00:00 2001 From: cirakg Date: Sun, 15 Jan 2023 19:31:41 +0100 Subject: Ispravljeno brisanje chat box-a izmedju igara. Dodat deo tooltip-a na game panel-u. --- src/main/java/ui/GamePanel.java | 34 ++++++++++++++++------------------ src/main/java/ui/MainFrame.java | 7 +++---- 2 files changed, 19 insertions(+), 22 deletions(-) (limited to 'src') 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("Igra
Korisnici se bore po potezima. Koristeci izabrane napade
Prikazane su sve potrebne informacije za vodjenje igre.
Korisnici mogu koristiti chat za komunikaciju.
Po zavrsetku igre korisnici dobijaju obavestenje o rezultatu igre i
opciju da se vrate na stranicu za biranje protivnika"); + lblToolTip.setToolTipText("Igra
Korisnici se bore po potezima. Koristeci izabrane napade
Prikazane su sve potrebne informacije za vodjenje igre.
Korisnici mogu koristiti chat za komunikaciju.
Po zavrsetku igre korisnici dobijaju obavestenje o rezultatu igre i
opciju da se vrate na stranicu za biranje protivnika
U chatu su validni svi karakeri osim :"); 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 @@ -419,6 +408,15 @@ public class GamePanel extends JPanel { bis.close(); 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() { 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) { -- cgit v1.2.3