Package jbrickbreaker.view

Source Code of jbrickbreaker.view.TutorialView$JPanelBonus

package jbrickbreaker.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.Locale;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import javax.swing.text.html.HTMLEditorKit;

import jbrickbreaker.JBrickBreaker;
import jbrickbreaker.model.bonuses.*;
import net.miginfocom.swing.MigLayout;

/**
* This class represents the tutorial view that displays a little description of
* the game and a description of bonuses
*
* @author Christophe
*
*/
public class TutorialView extends JDialog implements ILanguage {

    private TitledBorder descriptionBorder, bonusBorder;
    private JBrickBreaker brickbreaker;
    private JTextPane text;

    public TutorialView(JBrickBreaker brickbreaker) {
        super();
        setIconImage(new ImageIcon(getClass().getResource(
                "/resources/ico_bb.png")).getImage()); //$NON-NLS-1$
        this.brickbreaker = brickbreaker;
        createView();
    }

    private void createView() {

        setModal(false);
        setLayout(new MigLayout());
        // setResizable(false);
        JPanel jpDescription = new JPanel(new MigLayout());
        descriptionBorder = BorderFactory.createTitledBorder(brickbreaker
                .getString("TutorialView.1")); //$NON-NLS-1$
        jpDescription.setBorder(descriptionBorder);
        text = new JTextPane();
        text.setEditorKit(new HTMLEditorKit());
        text.setEditable(false);
        text.setBorder(new EmptyBorder(2, 1, 1, 1));
        text.setAutoscrolls(false);
        text.setContentType("text/html"); //$NON-NLS-1$
        text.setFont(text.getFont().deriveFont(Font.PLAIN));
        text.setOpaque(false);
        text.setBackground(UIManager.getColor("control")); //$NON-NLS-1$
        text.setText(brickbreaker.getString("TutorialView.2")); //$NON-NLS-1$

        JPanelBonus jpb = new JPanelBonus();
        bonusBorder = BorderFactory.createTitledBorder(brickbreaker
                .getString("TutorialView.3")); //$NON-NLS-1$
        jpb.setBorder(bonusBorder);

        add(jpDescription, "width 100%, height 130,wrap"); //$NON-NLS-1$
        add(jpb, "width 280, height 270"); //$NON-NLS-1$
        jpDescription.add(text, "width 100%"); //$NON-NLS-1$
        updateLanguage(brickbreaker.getLanguage());
    }

    class JPanelBonus extends JPanel {

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;

            int i = 0;
            int j = 40;
            int x1 = 10;
            int x2 = 60;
            int y1 = 30;
            int y2 = 45;
            new FasterBallBonus(x1, y1 + (i * j)).draw(g2d);
            g.setColor(Color.BLACK);
            g2d.drawString(
                    brickbreaker.getString("TutorialView.4"), x2, y2 + (i * j)); //$NON-NLS-1$
            i++;
            new LargerPadBonus(x1, y1 + (i * j)).draw(g2d);
            g.setColor(Color.BLACK);
            g2d.drawString(
                    brickbreaker.getString("TutorialView.5"), x2, y2 + (i * j)); //$NON-NLS-1$
            i++;
            new MultipleBallBonus(x1, y1 + (i * j)).draw(g2d);
            g.setColor(Color.BLACK);
            g2d.drawString(
                    brickbreaker.getString("TutorialView.6"), x2, y2 + (i * j)); //$NON-NLS-1$
            i++;
            new SlowerBallBonus(x1, y1 + (i * j)).draw(g2d);
            g.setColor(Color.BLACK);
            g2d.drawString(
                    brickbreaker.getString("TutorialView.7"), x2, y2 + (i * j)); //$NON-NLS-1$
            i++;
            new SmallerPadBonus(x1, y1 + (i * j)).draw(g2d);
            g.setColor(Color.BLACK);
            g2d.drawString(
                    brickbreaker.getString("TutorialView.8"), x2, y2 + (i * j)); //$NON-NLS-1$
            i++;
            new StuckBonus(x1, y1 + (i * j)).draw(g2d);
            g.setColor(Color.BLACK);
            g2d.drawString(
                    brickbreaker.getString("TutorialView.9"), x2, y2 + (i * j)); //$NON-NLS-1$
        }
    }

    @Override
    public void updateLanguage(Locale lang) {
        setTitle(brickbreaker.getString("TutorialView.0")); //$NON-NLS-1$
        text.setText(brickbreaker.getString("TutorialView.2")); //$NON-NLS-1$
        repaint();
    }
}
TOP

Related Classes of jbrickbreaker.view.TutorialView$JPanelBonus

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.