Advertisement
TrodelHD

Untitled

Apr 3rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. package Spiel;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JPanel;
  10. import javax.swing.JTextArea;
  11.  
  12. public class ErrorMessage {
  13. public ErrorMessage (String Display){
  14. CloseAllWindows();
  15. JFrame f = new JFrame("An error occurred!");
  16. f.setLayout(new BorderLayout());
  17. f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18. f.setLocationRelativeTo(null);
  19. f.setSize(400, 150);
  20. f.setBounds(f.getBounds().x-(f.getBounds().width/2), f.getBounds().y-(f.getBounds().height/2), f.getBounds().width, f.getBounds().height);
  21.  
  22.  
  23. JPanel Center = new JPanel();
  24. f.add(Center,BorderLayout.CENTER);
  25.  
  26. JPanel Bottom = new JPanel();
  27. f.add(Bottom, BorderLayout.PAGE_END);
  28.  
  29. JTextArea t = new JTextArea("An error occurred");
  30. t.setEditable(false);
  31. t.setBorder(null);
  32. try {t.setText(Display);} catch (Exception e) {}
  33. Center.add(t);
  34.  
  35. JButton b = new JButton("OK");
  36. Bottom.add(b);
  37. b.addActionListener(new ActionListener() {
  38. @Override
  39. public void actionPerformed(ActionEvent e) {
  40. f.dispose();
  41. new RestartProgramm();
  42. }
  43. });
  44. Bottom.add(b);
  45.  
  46. Bottom.doLayout();
  47. Center.doLayout();
  48. f.doLayout();
  49. f.setVisible(true);
  50.  
  51. }
  52. private void CloseAllWindows(){
  53. try {Main.frame.dispose();} catch (Exception e) {}
  54. try {MyPanel.frame.dispose();} catch (Exception e) {}
  55. try {MyPanelRater.frame.dispose();} catch (Exception e) {}
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement