Advertisement
Mercedes

reglas sin manosear

Nov 21st, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package missil.command;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Color;
  5. import java.awt.Dimension;
  6. import java.awt.Graphics;
  7. import java.awt.GridBagConstraints;
  8. import java.awt.Image;
  9. import java.awt.Insets;
  10. import java.awt.event.MouseAdapter;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import java.net.URL;
  16.  
  17. import javax.imageio.ImageIO;
  18. import javax.swing.JButton;
  19. import javax.swing.JFrame;
  20. import javax.swing.JPanel;
  21. import javax.swing.JTextField;
  22.  
  23. import missil.command.PantallaDeJuego.PanelDibujo;
  24.  
  25.  
  26. public class Reglas extends JFrame{
  27.  
  28.  
  29. private JButton home;
  30. private JButton siguiente;
  31.  
  32. private String imagenRegla1= "recursos/reglas1.png";
  33. private String imagenRegla2= "recursos/reglas2.png";
  34.  
  35. private boolean ok=false;
  36.  
  37. private Image img1;
  38. private Image img2;
  39.  
  40.  
  41. public Reglas() {
  42.  
  43.  
  44. this.setLayout(new BorderLayout());
  45. this.setTitle("Reglas Del Juego");
  46. this.setSize(1024, 700);
  47. this.setLocationRelativeTo(null);
  48.  
  49. home= new JButton("Atras");
  50. this.home.setVisible(true);
  51. this.add(this.home, BorderLayout.SOUTH);
  52.  
  53. this.home.addMouseListener(new goBack());
  54.  
  55.  
  56. siguiente= new JButton("Siguiente");
  57. this.siguiente.addMouseListener(new Next());
  58. this.add(this.siguiente, BorderLayout.EAST);
  59. siguiente.setVisible(true);
  60.  
  61. this.setVisible(true);
  62. this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  63. }
  64.  
  65. public class Next extends MouseAdapter{
  66. public void mouseClicked (MouseEvent arg0) {
  67. ok=true; // ok es para cuando se oprima el boton siguiente se ejecute la segunda parte del paint y se grafique la segunda imagen
  68. //siguiente.setEnabled(false);
  69. //siguiente.setVisible(false);
  70. siguiente.setVisible(false);
  71. repaint();
  72. }
  73.  
  74.  
  75.  
  76. }
  77. public class goBack extends MouseAdapter {
  78.  
  79. public void mouseClicked (MouseEvent arg0) {
  80. PantallaInicial pantalla = new PantallaInicial();
  81. dispose();
  82. }
  83.  
  84. }
  85.  
  86.  
  87. URL regla1URL = getClass().getClassLoader().getResource(imagenRegla1);
  88. URL regla2URL = getClass().getClassLoader().getResource(imagenRegla2);
  89.  
  90. public void paint (Graphics gr){
  91.  
  92. if (imagenRegla1 == null)
  93. System.err.println("Couldn't find file: " + imagenRegla1);
  94. else{
  95. try {
  96. img1 = ImageIO.read(regla1URL);
  97. } catch (IOException ex) {
  98. ex.printStackTrace();
  99. }
  100. }
  101.  
  102. gr.drawImage(img1, 50, 50, null);
  103.  
  104. if (ok){
  105.  
  106. if (imagenRegla2 == null)
  107. System.err.println("Couldn't find file: " + imagenRegla2);
  108. else{
  109. try {
  110. img2 = ImageIO.read(regla2URL);
  111. } catch (IOException ex) {
  112. ex.printStackTrace();
  113. }
  114. }
  115. gr.drawImage(img2, 50, 50, null);
  116. }
  117.  
  118.  
  119. }
  120.  
  121.  
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement