Ward_Programm3r

GDSE Question for Czonzhu

Sep 8th, 2014
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.81 KB | None | 0 0
  1.         import javax.swing.*;
  2.     import java.awt.*;
  3.     import java.awt.event.*;
  4.  
  5.  
  6.  
  7.     public class TetrisGUI implements ActionListener{
  8.         public static JButton quit = new JButton();
  9.         public static JLabel label1 = new JLabel();
  10.         public static JLabel label2 = new JLabel();
  11.         public static JLabel label3 = new JLabel();
  12.         public static JFrame frame = new JFrame();
  13.         public static MyDrawPanel drawPanel = new MyDrawPanel();
  14.         public static MainAreaPanel mainArea = new MainAreaPanel();
  15.         public static boolean entered = false;
  16.        
  17.  
  18.         public static void main(String[] args) {
  19.             TetrisGUI gui = new TetrisGUI();
  20.             gui.go();
  21.         }
  22.  
  23.         public void go() {
  24.            
  25.             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  26.             quit = new JButton("QUIT");
  27.             label1 = new JLabel("Level:    1");
  28.             label2 = new JLabel("Lines:    0");
  29.             label3 = new JLabel("Score:    0");
  30.             quit.setFont(new Font("Arial", Font.BOLD, 20));
  31.             label1.setFont(new Font("Arial", Font.BOLD, 20));
  32.             label2.setFont(new Font("Arial", Font.BOLD, 20));
  33.             label3.setFont(new Font("Arial", Font.BOLD, 20));
  34.  
  35.             MyDrawPanel drawPanel = new MyDrawPanel();
  36.  
  37.             quit.addActionListener(this);
  38.             mainArea.addMouseListener(new CustomListener(){});
  39.            
  40.            
  41.            
  42.             frame.getContentPane().add(quit);
  43.             frame.getContentPane().add(label1);
  44.             frame.getContentPane().add(label2);
  45.             frame.getContentPane().add(label3);
  46.             frame.getContentPane().add(mainArea);
  47.             frame.getContentPane().add(drawPanel);
  48.            
  49.            
  50.            
  51.  
  52.             drawPanel.setOpaque(false);//Set the drawPanel opaque
  53.             label1.setSize(100,200);
  54.             label1.setLocation(310,130);
  55.             label2.setSize(100,200);
  56.             label2.setLocation(310,180);
  57.             label3.setSize(100,200);
  58.             label3.setLocation(310,230);
  59.             mainArea.setSize(250,500);
  60.             mainArea.setLocation(20,50);
  61.             quit.setSize(100,40);
  62.             quit.setLocation(300,510); 
  63.             frame.setSize(450,600);
  64.             frame.setVisible(true);
  65.            
  66.            
  67.         }
  68.  
  69.        
  70.  
  71.         public void actionPerformed(ActionEvent event) {
  72.             System.exit(0);
  73.         }
  74.  
  75.        
  76.     }
  77.  
  78.  
  79.     class MyDrawPanel extends JPanel {
  80.         public void paintComponent(Graphics g) {
  81.             repaint();
  82.             g.setColor(Color.black);
  83.             g.drawRect(20,50,250,500);//Main Area
  84.             g.drawRect(300,50,100,70);//NextShape
  85.             g.drawRect(145,80,25,25);//Tian Block
  86.             g.drawRect(145,105,25,25);
  87.             g.drawRect(120,80,25,25);
  88.             g.drawRect(120,105,25,25);
  89.  
  90.            
  91.  
  92.             Color deepGreen = new Color(35,165,63);
  93.             g.setColor(deepGreen);
  94.             g.fillRect(121,81,24,24);//Tian Block
  95.             g.fillRect(121,106,24,24);
  96.             g.fillRect(146,81,24,24);
  97.             g.fillRect(146,106,24,24);
  98.  
  99.             g.setColor(Color.black);
  100.             g.drawRect(245,525,25,25);//Right bottom
  101.             g.drawRect(220,525,25,25);
  102.             g.drawRect(195,525,25,25);
  103.             g.drawRect(170,525,25,25);
  104.             g.drawRect(245,500,25,25);
  105.             g.drawRect(245,475,25,25);
  106.             g.drawRect(220,500,25,25);
  107.             g.drawRect(195,500,25,25);
  108.             Color deepBlue = new Color(11,90,178);
  109.             g.setColor(deepBlue);
  110.             g.fillRect(246,526,24,24);
  111.             g.fillRect(221,526,24,24);
  112.             g.fillRect(246,501,24,24);
  113.             g.fillRect(246,476,24,24);
  114.             Color brightYellow = new Color(255,255,12);
  115.             g.setColor(brightYellow);
  116.             g.fillRect(196,526,24,24);
  117.             g.fillRect(171,526,24,24);
  118.             g.fillRect(196,501,24,24);
  119.             g.fillRect(221,501,24,24);
  120.  
  121.             //NextShape Blocks
  122.             g.setColor(Color.black);
  123.             g.drawRect(360,60,25,25);
  124.             g.drawRect(335,85,25,25);
  125.             g.drawRect(360,85,25,25);
  126.             g.drawRect(310,85,25,25);
  127.             Color deepRed = new Color(248,0,4);
  128.             g.setColor(deepRed);
  129.             g.fillRect(361,61,24,24);
  130.             g.fillRect(336,86,24,24);
  131.             g.fillRect(361,86,24,24);
  132.             g.fillRect(311,86,24,24);
  133.            
  134.  
  135.  
  136.             //Draw Pause
  137.             if(TetrisGUI.entered == true) {
  138.                 g.setColor(deepBlue);
  139.                 g.setFont(new Font("Arial", Font.BOLD, 30));
  140.                 g.drawString("Pause",100,290);
  141.                 g.drawRect(80,260,120,40);
  142.                
  143.             }
  144.             else{
  145.  
  146.             }
  147.         }
  148.     }
Advertisement
Add Comment
Please, Sign In to add comment