document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  *  Final Project PBO
  3.  *  Class MenuFrame
  4.  *  
  5.  *  @author Aimar Wibowo
  6.  *  @author Timotius Wirawan
  7.  *  @version 11 Januari 2021
  8.  */
  9.  
  10. import java.awt.Color;
  11. import java.awt.Graphics;
  12. import java.awt.Image;
  13. import java.awt.event.ActionEvent;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.MouseEvent;
  16. import java.awt.event.MouseListener;
  17. import java.io.DataInputStream;
  18. import java.io.DataOutputStream;
  19. import java.io.FileInputStream;
  20. import java.io.FileOutputStream;
  21. import java.io.IOException;
  22.  
  23. import javax.sound.sampled.AudioInputStream;
  24. import javax.sound.sampled.AudioSystem;
  25. import javax.sound.sampled.Clip;
  26. import javax.sound.sampled.LineUnavailableException;
  27. import javax.swing.ImageIcon;
  28. import javax.swing.JButton;
  29. import javax.swing.JFrame;
  30. import javax.swing.JPanel;
  31. import javax.swing.border.Border;
  32.  
  33. public class MenuFrame extends JFrame{
  34.     ImagePanel panel = new ImagePanel();
  35.     JButton newGame = new JButton(panel.imageNewGame);
  36.     JButton loadGame = new JButton(panel.imageLoadGame);
  37.     JButton howToPlay = new JButton(panel.imageOption);
  38.     JButton back= new JButton(panel.imageBack);
  39.  
  40.     public MenuFrame() {
  41.         init();
  42.         addMenuFrameActionListener();
  43.     }
  44.    
  45.     public void init(){
  46.          newGame.setBounds(520,250, 200, 45);
  47.          newGame.setBorder(null);
  48.          loadGame.setBounds( 520, 300, 200, 45);
  49.          loadGame.setBorder(null);
  50.          howToPlay.setBounds(520, 350, 200, 45);
  51.          howToPlay.setBorder(null);
  52.          back.setBounds(520, 400, 200, 45);
  53.          back.setBorder(null);
  54.      
  55.          this.add(newGame);
  56.          this.add(loadGame);
  57.          this.add(howToPlay);
  58.          this.add(back);
  59.          this.add(panel);
  60.     }
  61.    
  62.     public void addMenuFrameActionListener(){
  63.         loadGame.addActionListener(new newGameAction1());
  64.         loadGame.addActionListener(new ActionListener() {
  65.            
  66.             @Override
  67.             public void actionPerformed(ActionEvent e) {
  68.                 GameMain.clip.close();
  69.                 GameMain.buttonmusic();
  70.                 setVisible(false);
  71.                
  72.             }
  73.         });
  74.      
  75.        newGame.addActionListener(new newGameAction());
  76.        newGame.addActionListener(new ActionListener() {
  77.             @Override
  78.             public void actionPerformed(ActionEvent e) {
  79.                 GameMain.clip.close();
  80.                 GameMain.buttonmusic();
  81.                 setVisible(false);
  82.                
  83.             }
  84.         });
  85.        
  86.        back.addActionListener(new backPage());
  87.        howToPlay.addActionListener(new ActionListener() {
  88.             @Override
  89.             public void actionPerformed(ActionEvent e) {
  90.                 GameMain.buttonmusic();
  91.                 HowToPlay newFrame = new HowToPlay();
  92.                 newFrame.setTitle("How To Play");
  93.                 newFrame.setSize(800,600);
  94.                 newFrame.setLocationRelativeTo(null);
  95.                 newFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  96.                 newFrame.setVisible(true); 
  97.                 newFrame.setResizable(false);
  98.             }
  99.         });
  100.        
  101.        back.addActionListener(new ActionListener() {
  102.             @Override
  103.             public void actionPerformed(ActionEvent e) {
  104.                 setVisible(false);
  105.             }
  106.         });
  107.     }
  108.    
  109.     public class ImagePanel extends JPanel{
  110.         private ImageIcon imageIcon = new ImageIcon("images/untitle.jpg");
  111.         private ImageIcon imageNewGame = new ImageIcon("images/newgame.jpg");
  112.         private ImageIcon imageLoadGame = new ImageIcon("images/loadgame.jpg");
  113.         private ImageIcon imageOption = new ImageIcon("images/option.jpg");
  114.         private ImageIcon imageBack = new ImageIcon("images/back.jpg");
  115.         private Image image = imageIcon.getImage();
  116.            
  117.         protected void paintComponent(Graphics g) {
  118.             super.paintComponent(g);
  119.             g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
  120.                
  121.             }
  122.          }
  123.     }
  124.  
  125.     class newGameAction implements ActionListener {
  126.         public void actionPerformed(ActionEvent e){
  127.             GameHold mDraw =new GameHold("Tower Of Hanoi",1);
  128.             try {
  129.                 Clip clip = AudioSystem.getClip();
  130.                 System.out.println(clip.getFormat());
  131.                 clip.stop();
  132.             }
  133.             catch (LineUnavailableException e1) {
  134.                 e1.printStackTrace();
  135.             }
  136.         }
  137.     }
  138.        
  139.     class newGameAction1 implements ActionListener {
  140.         public void actionPerformed(ActionEvent e){
  141.             try{
  142.                 DataInputStream input =new DataInputStream(new FileInputStream("images/input.txt"));
  143.                 int x=input.readInt();
  144.                 input.close();
  145.                 System.out.println("here is XX: " + x);
  146.                 GameHold hold =new GameHold("Tower Of Hanoi",x);   
  147.             }
  148.             catch(IOException ex){
  149.                 System.out.println("Problem with Input Output FIle");      
  150.             }
  151.         }
  152.     }
');