Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.39 KB | None | 0 0
  1. import java.awt.*;
  2. import java.applet.*;
  3. import java.awt.event.*;
  4. import java.awt.Dimension;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.ActionEvent;
  9. import javax.swing.JApplet;
  10. import javax.swing.JButton;
  11. import java.awt.image.BufferedImage;
  12. import java.io.*;
  13. import javax.imageio.ImageIO;
  14. import javax.swing.ImageIcon;
  15.  
  16. public class LylaMain extends JApplet
  17. {
  18.    int RETURN_SUCC = 0;
  19.    int RETURN_FAIL = -1;
  20.    Image backGround = null;
  21.    Image startBtn = null;
  22.    Image Logo = null;
  23.    Image credits = null;
  24.    int screen;
  25.    
  26.     public void init()
  27.     {
  28.         setSize(1280,720);
  29.         playMusic();
  30.     }
  31.  
  32.     public void start()
  33.     {
  34.         // provide any code requred to run each time applet is visited
  35.     }
  36.  
  37.     public void stop()
  38.     {
  39.         // provide any code that needs to be run when page is replaced by another applet or before JApplet is destroyed.
  40.        
  41.     }
  42.  
  43.     public void paint(Graphics g)
  44.     {
  45.         //This is the Main method for the program flow.
  46.         init();
  47.         startScreen(g);
  48.     }
  49.      
  50.     public void playMusic()  
  51.     {
  52.         AudioClip player = getAudioClip(getCodeBase(), "assets/main.wav");
  53.         player.play();
  54.         player.loop();
  55.     }
  56.    
  57.     public void startScreen(Graphics g)
  58.     {
  59.         screen = 1; // start screen phase
  60.         Toolkit toolkit = Toolkit.getDefaultToolkit();
  61.         // BackGround
  62.         backGround = toolkit.getImage("assets/bg.jpg");
  63.         g.drawImage(backGround, 0, 0, this);  
  64.        
  65.        
  66.         //Start button
  67.         startBtn = toolkit.getImage("assets/startBTN.png");
  68.         g.drawImage(startBtn, 850, 300, this);
  69.        
  70.        //BufferedImage buttonIcon = ImageIO.read(new File("assets/startBTN.png"));
  71.        //JButton buton = new JButton(new ImageIcon(buttonIcon));                             BROKEN CODE WILL FIX KEK
  72.        
  73.         //startBtn.addActionListener(this);
  74.        
  75.         //Credits button
  76.         credits = toolkit.getImage("assets/creditsBtn.png");
  77.         g.drawImage(credits, 850, 400, this);
  78.        
  79.         // Primary Banner
  80.         Logo = toolkit.getImage("assets/ao.png");
  81.         g.drawImage(Logo, 650, 0, this);
  82.         // left/right, height
  83.        
  84.         //clickng detection implemented later
  85.         //creditsScreen(g);
  86.             }
  87.     public int creditsScreen(Graphics g)
  88.     {
  89.         if(screen == 1)
  90.           screen = 3; // credits screen
  91.         else
  92.           return RETURN_FAIL;
  93.         int x,x1,x2,x3,x4,x5,x6,x7;
  94.         int y,y1,y2,y3,y4,y5,y6;
  95.         String s = "Development Team";
  96.         String line1 = "Nadia - Organizer & Leader";
  97.         String line2 = "Tanzia - Story writer & planner of choices";
  98.         String line3 = "Edward - Mouse interaction & Swing";
  99.         String line4 = "Andrew - Cover page & sound";
  100.         String line5 = "Semrah - Graphics & Textboxes";
  101.         String line6 = "Tyler - Animation & Helper";
  102.         String kek = "Special Guest - gEoRgE";
  103.         Dimension d = getSize();
  104.         Font f = new Font("Old English Text MT",Font.BOLD,28);
  105.         g.setFont(f);
  106.        
  107.         FontMetrics fm = g.getFontMetrics();
  108.         x = d.width/2 - fm.stringWidth(s)/2 ;
  109.         y = d.height/2 - fm.getHeight();
  110.        
  111.         x1 = d.width/2 - fm.stringWidth(line1)/2 ;
  112.         x2 = d.width/2 - fm.stringWidth(line2)/2 ;
  113.         x3 = d.width/2 - fm.stringWidth(line3)/2 ;
  114.         x4 = d.width/2 - fm.stringWidth(line4)/2 ;
  115.         x5 = d.width/2 - fm.stringWidth(line5)/2 ;
  116.         x6 = d.width/2 - fm.stringWidth(line6)/2 ;
  117.  
  118.        
  119.         setBackground(Color.white);
  120.         g.drawImage(backGround, 0, 0, this);
  121.        
  122.         g.drawString(s,x,y - 30);
  123.         g.drawString(line1, x1, y+35 - 30);
  124.         g.drawString(line2, x2, y + 70 - 30);
  125.         g.drawString(line3, x3, y + 105 - 30);
  126.         g.drawString(line4, x4, y + 140 - 30);
  127.         g.drawString(line5, x5, y + 175 - 30);
  128.         g.drawString(line6, x6, y + 210 - 30);
  129.         x7 = d.width/2 - fm.stringWidth(kek)/2 ;
  130.         Font a = new Font("Arial",Font.PLAIN,10);
  131.         g.setFont(a);
  132.         g.drawString(kek,x7,y + 350);
  133.        
  134.        return RETURN_SUCC;
  135.     }
  136.        /*public void actionPerformed(ActionEvent e) {
  137.         if (e.getSource() == start) {
  138.             Toolkit.getDefaultToolkit().beep();
  139.         }
  140.     }*/
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement