Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class TetrisGUI implements ActionListener{
- public static JButton quit = new JButton();
- public static JLabel label1 = new JLabel();
- public static JLabel label2 = new JLabel();
- public static JLabel label3 = new JLabel();
- public static JFrame frame = new JFrame();
- public static MyDrawPanel drawPanel = new MyDrawPanel();
- public static MainAreaPanel mainArea = new MainAreaPanel();
- public static boolean entered = false;
- public static void main(String[] args) {
- TetrisGUI gui = new TetrisGUI();
- gui.go();
- }
- public void go() {
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- quit = new JButton("QUIT");
- label1 = new JLabel("Level: 1");
- label2 = new JLabel("Lines: 0");
- label3 = new JLabel("Score: 0");
- quit.setFont(new Font("Arial", Font.BOLD, 20));
- label1.setFont(new Font("Arial", Font.BOLD, 20));
- label2.setFont(new Font("Arial", Font.BOLD, 20));
- label3.setFont(new Font("Arial", Font.BOLD, 20));
- MyDrawPanel drawPanel = new MyDrawPanel();
- quit.addActionListener(this);
- mainArea.addMouseListener(new CustomListener(){});
- frame.getContentPane().add(quit);
- frame.getContentPane().add(label1);
- frame.getContentPane().add(label2);
- frame.getContentPane().add(label3);
- frame.getContentPane().add(mainArea);
- frame.getContentPane().add(drawPanel);
- drawPanel.setOpaque(false);//Set the drawPanel opaque
- label1.setSize(100,200);
- label1.setLocation(310,130);
- label2.setSize(100,200);
- label2.setLocation(310,180);
- label3.setSize(100,200);
- label3.setLocation(310,230);
- mainArea.setSize(250,500);
- mainArea.setLocation(20,50);
- quit.setSize(100,40);
- quit.setLocation(300,510);
- frame.setSize(450,600);
- frame.setVisible(true);
- }
- public void actionPerformed(ActionEvent event) {
- System.exit(0);
- }
- }
- class MyDrawPanel extends JPanel {
- public void paintComponent(Graphics g) {
- repaint();
- g.setColor(Color.black);
- g.drawRect(20,50,250,500);//Main Area
- g.drawRect(300,50,100,70);//NextShape
- g.drawRect(145,80,25,25);//Tian Block
- g.drawRect(145,105,25,25);
- g.drawRect(120,80,25,25);
- g.drawRect(120,105,25,25);
- Color deepGreen = new Color(35,165,63);
- g.setColor(deepGreen);
- g.fillRect(121,81,24,24);//Tian Block
- g.fillRect(121,106,24,24);
- g.fillRect(146,81,24,24);
- g.fillRect(146,106,24,24);
- g.setColor(Color.black);
- g.drawRect(245,525,25,25);//Right bottom
- g.drawRect(220,525,25,25);
- g.drawRect(195,525,25,25);
- g.drawRect(170,525,25,25);
- g.drawRect(245,500,25,25);
- g.drawRect(245,475,25,25);
- g.drawRect(220,500,25,25);
- g.drawRect(195,500,25,25);
- Color deepBlue = new Color(11,90,178);
- g.setColor(deepBlue);
- g.fillRect(246,526,24,24);
- g.fillRect(221,526,24,24);
- g.fillRect(246,501,24,24);
- g.fillRect(246,476,24,24);
- Color brightYellow = new Color(255,255,12);
- g.setColor(brightYellow);
- g.fillRect(196,526,24,24);
- g.fillRect(171,526,24,24);
- g.fillRect(196,501,24,24);
- g.fillRect(221,501,24,24);
- //NextShape Blocks
- g.setColor(Color.black);
- g.drawRect(360,60,25,25);
- g.drawRect(335,85,25,25);
- g.drawRect(360,85,25,25);
- g.drawRect(310,85,25,25);
- Color deepRed = new Color(248,0,4);
- g.setColor(deepRed);
- g.fillRect(361,61,24,24);
- g.fillRect(336,86,24,24);
- g.fillRect(361,86,24,24);
- g.fillRect(311,86,24,24);
- //Draw Pause
- if(TetrisGUI.entered == true) {
- g.setColor(deepBlue);
- g.setFont(new Font("Arial", Font.BOLD, 30));
- g.drawString("Pause",100,290);
- g.drawRect(80,260,120,40);
- }
- else{
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment