Zach205502hcaz

MC Book Art Source

Oct 4th, 2016
624
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.38 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.datatransfer.Clipboard;
  4. import java.awt.datatransfer.StringSelection;
  5.  
  6. /**
  7.  * Created by Zachary on 6/15/2016.
  8.  *
  9.  * Look at the buttons :P
  10.  *
  11.  * Dedicated to all the fun people of the SHO server, and especially Spellbound Order
  12.  */
  13. public class ButtonBox extends JFrame{
  14.  
  15.     final int maxChar = 256;
  16.     int charLeft = 256;
  17.     int x = 0;
  18.     int y = 0;
  19.     public String lastColor = "black";
  20.     public String text = new String();
  21.     JPanel preview = new JPanel();
  22.     JPanel charCounter = new JPanel();
  23.     JLabel charactersLeft = new JLabel();
  24.     Color mcBlack = new Color(0,0,0);
  25.     Color darkBlue = new Color(0,0,170);
  26.     Color darkGreen = new Color(0,170,0);
  27.     Color darkAqua = new Color(0,170,170);
  28.     Color darkRed = new Color(170,0,0);
  29.     Color purple = new Color(170,0,170);
  30.     Color gold = new Color(255,170,0);
  31.     Color mcGray = new Color(170,170,170);
  32.     Color darkGray = new Color(85,85,85);
  33.     Color lightBlue = new Color(85,85,255);
  34.     Color lightGreen = new Color(85,255,85);
  35.     Color aqua = new Color(85,255,255);
  36.     Color lightRed = new Color(255,85,85);
  37.     Color lightPurple = new Color(255,85,255);
  38.     Color mcYellow = new Color(255,255,85);
  39.     Color mcWhite = new Color(255,255,255);
  40.  
  41.     GridBagConstraints c = new GridBagConstraints();
  42.  
  43.  
  44.  
  45.     ButtonBox(){
  46.         setLayout(new BorderLayout());
  47.         setTitle("MC BookArt");
  48.         setSize(500,500);
  49.         setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  50.  
  51.  
  52.         JPanel color = new JPanel();
  53.         color.setLayout(new BorderLayout());
  54.         JPanel buttons = new JPanel();
  55.         preview.setLayout(new GridBagLayout());
  56.         buttons.setLayout(new GridLayout(8,2));
  57.         JButton blackButton = new JButton();
  58.         blackButton.addActionListener(e -> addBlack());
  59.         JButton darkBlueButton = new JButton();
  60.         darkBlueButton.addActionListener(e -> addDarkBlue());
  61.         JButton darkGreenButton = new JButton();
  62.         darkGreenButton.addActionListener(e -> addDarkGreen());
  63.         JButton darkAquaButton = new JButton();
  64.         darkAquaButton.addActionListener(e -> addDarkAqua());
  65.         JButton darkRedButton = new JButton();
  66.         darkRedButton.addActionListener(e -> addDarkRed());
  67.         JButton darkPurpleButton = new JButton();
  68.         darkPurpleButton.addActionListener(e -> addDarkPurple());
  69.         JButton goldButton = new JButton();
  70.         goldButton.addActionListener(e -> addGold());
  71.         JButton grayButton = new JButton();
  72.         grayButton.addActionListener(e -> addGray());
  73.         JButton darkGrayButton = new JButton();
  74.         darkGrayButton.addActionListener(e -> addDarkGray());
  75.         JButton blueButton = new JButton();
  76.         blueButton.addActionListener(e -> addBlue());
  77.         JButton greenButton = new JButton();
  78.         greenButton.addActionListener(e -> addGreen());
  79.         JButton aquaButton = new JButton();
  80.         aquaButton.addActionListener(e -> addAqua());
  81.         JButton redButton = new JButton();
  82.         redButton.addActionListener(e -> addRed());
  83.         JButton lightPurpleButton = new JButton();
  84.         lightPurpleButton.addActionListener(e -> addLightPurple());
  85.         JButton yellowButton = new JButton();
  86.         yellowButton.addActionListener(e -> addYellow());
  87.         JButton whiteButton = new JButton();
  88.         whiteButton.addActionListener(e -> addWhite());
  89.         JButton copy = new JButton("Copy to Clipboard");
  90.         copy.addActionListener(e -> copyAsText());
  91.         charCounter.setLayout(new GridLayout(1,2));
  92.  
  93.  
  94.         add(color,BorderLayout.EAST);
  95.         color.add(buttons,BorderLayout.CENTER);
  96.         add(preview,BorderLayout.CENTER);
  97.         color.add(new JLabel("Colors"),BorderLayout.NORTH);
  98.         add(copy,BorderLayout.SOUTH);
  99.         add(charCounter,BorderLayout.NORTH);
  100.         charCounter.add(new JLabel("Characters Left"));
  101.         charCounter.add(charactersLeft);
  102.  
  103.  
  104.  
  105.         buttons.add(blackButton);
  106.         blackButton.setBackground(mcBlack);
  107.         buttons.add(darkBlueButton);
  108.         darkBlueButton.setBackground(darkBlue);
  109.         buttons.add(darkGreenButton);
  110.         darkGreenButton.setBackground(darkGreen);
  111.         buttons.add(darkAquaButton);
  112.         darkAquaButton.setBackground(darkAqua);
  113.         buttons.add(darkRedButton);
  114.         darkRedButton.setBackground(darkRed);
  115.         buttons.add(darkPurpleButton);
  116.         darkPurpleButton.setBackground(purple);
  117.         buttons.add(goldButton);
  118.         goldButton.setBackground(gold);
  119.         buttons.add(grayButton);
  120.         grayButton.setBackground(mcGray);
  121.         buttons.add(darkGrayButton);
  122.         darkGrayButton.setBackground(darkGray);
  123.         buttons.add(blueButton);
  124.         blueButton.setBackground(lightBlue);
  125.         buttons.add(greenButton);
  126.         greenButton.setBackground(lightGreen);
  127.         buttons.add(aquaButton);
  128.         aquaButton.setBackground(aqua);
  129.         buttons.add(redButton);
  130.         redButton.setBackground(lightRed);
  131.         buttons.add(lightPurpleButton);
  132.         lightPurpleButton.setBackground(lightPurple);
  133.         buttons.add(yellowButton);
  134.         yellowButton.setBackground(mcYellow);
  135.         buttons.add(whiteButton);
  136.         whiteButton.setBackground(mcWhite);
  137.         revalidate();
  138.  
  139.         setVisible(true);
  140.  
  141.     }
  142.  
  143.     /**
  144.      * Copies to clipboard
  145.      */
  146.     private void copyAsText() {
  147.         StringSelection selection = new StringSelection(text);
  148.         Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  149.         clipboard.setContents(selection, selection);
  150.         JOptionPane.showMessageDialog(null,"Text copied to Clipboard");
  151.     }
  152.  
  153.     /**
  154.      * Adds black
  155.      */
  156.     private void addBlack() {
  157.         c.gridx = x;
  158.         c.gridy = y;
  159.         JPanel blackPanel = new JPanel();
  160.         blackPanel.setBackground(mcBlack);
  161.         blackPanel.setSize(10,10);
  162.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "black"))) {
  163.             preview.add(blackPanel,c);
  164.             blackPanel.setAlignmentX(x);
  165.             blackPanel.setAlignmentY(y);
  166.             x++;
  167.             if (x >= 12) {
  168.                 x = 0;
  169.                 y++;
  170.             }
  171.             if (lastColor != "black"){
  172.                 text = text + "§0";
  173.                 lastColor = "black";
  174.             }
  175.             text = text + "█";
  176.             revalidate();
  177.         }else{
  178.             errorBox("Max Space Reached");
  179.         }
  180.         setCharLeft();
  181.     }
  182.     /**
  183.      * adds dark blue
  184.      */
  185.     private void addDarkBlue(){
  186.         c.gridx = x;
  187.         c.gridy = y;
  188.         JPanel darkBluePanel = new JPanel();
  189.         darkBluePanel.setBackground(darkBlue);
  190.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark blue"))) {
  191.             preview.add(darkBluePanel,c);
  192.             x++;
  193.             if (x >= 12) {
  194.                 x = 0;
  195.                 y++;
  196.             }
  197.             if (lastColor != "dark blue"){
  198.                 text = text + "§1";
  199.                 lastColor = "dark blue";
  200.             }
  201.             text = text + "█";
  202.             revalidate();
  203.         }else{
  204.             errorBox("Max Space Reached");
  205.         }
  206.         setCharLeft();
  207.     }
  208.  
  209.     /**
  210.      * adds dark green
  211.      */
  212.     private void addDarkGreen(){
  213.         c.gridx = x;
  214.         c.gridy = y;
  215.         JPanel darkGreenPanel = new JPanel();
  216.         darkGreenPanel.setBackground(darkGreen);
  217.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark green"))) {
  218.             preview.add(darkGreenPanel,c);
  219.             x++;
  220.             if (x >= 12) {
  221.                 x = 0;
  222.                 y++;
  223.             }
  224.             if (lastColor != "dark green"){
  225.                 text = text + "§2";
  226.                 lastColor = "dark green";
  227.             }
  228.             text = text + "█";
  229.             revalidate();
  230.         }else{
  231.             errorBox("Max Space Reached");
  232.         }
  233.         setCharLeft();
  234.     }
  235.  
  236.     /**
  237.      * adds dark aqua
  238.      */
  239.     private void addDarkAqua(){
  240.         c.gridx = x;
  241.         c.gridy = y;
  242.         JPanel darkAquaPanel = new JPanel();
  243.         darkAquaPanel.setBackground(darkAqua);
  244.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark aqua"))) {
  245.             preview.add(darkAquaPanel,c);
  246.             x++;
  247.             if (x >= 12) {
  248.                 x = 0;
  249.                 y++;
  250.             }
  251.             if (lastColor != "dark aqua"){
  252.                 text = text + "§3";
  253.                 lastColor = "dark aqua";
  254.             }
  255.             text = text + "█";
  256.             revalidate();
  257.         }else{
  258.             errorBox("Max Space Reached");
  259.         }
  260.         setCharLeft();
  261.     }
  262.  
  263.     /**
  264.      * adds dark red
  265.      */
  266.     private void addDarkRed(){
  267.         c.gridx = x;
  268.         c.gridy = y;
  269.         JPanel darkRedPanel = new JPanel();
  270.         darkRedPanel.setBackground(darkRed);
  271.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark red"))) {
  272.             preview.add(darkRedPanel,c);
  273.             x++;
  274.             if (x >= 12) {
  275.                 x = 0;
  276.                 y++;
  277.             }
  278.             if (lastColor != "dark red"){
  279.                 text = text + "§4";
  280.                 lastColor = "dark red";
  281.             }
  282.             text = text + "█";
  283.             revalidate();
  284.         }else{
  285.             errorBox("Max Space Reached");
  286.         }
  287.         setCharLeft();
  288.     }
  289.  
  290.     /**
  291.      * adds dark purple
  292.      */
  293.     private void addDarkPurple(){
  294.         c.gridx = x;
  295.         c.gridy = y;
  296.         JPanel darkPurplePanel = new JPanel();
  297.         darkPurplePanel.setBackground(purple);
  298.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark purple"))) {
  299.             preview.add(darkPurplePanel,c);
  300.             x++;
  301.             if (x >= 12) {
  302.                 x = 0;
  303.                 y++;
  304.             }
  305.             if (lastColor != "dark purple"){
  306.                 text = text + "§5";
  307.                 lastColor = "dark purple";
  308.             }
  309.             text = text + "█";
  310.             revalidate();
  311.         }else{
  312.             errorBox("Max Space Reached");
  313.         }
  314.         setCharLeft();
  315.     }
  316.  
  317.     /**
  318.      * adds gold
  319.      */
  320.     private void addGold(){
  321.         c.gridx = x;
  322.         c.gridy = y;
  323.         JPanel goldPanel = new JPanel();
  324.         goldPanel.setBackground(gold);
  325.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "gold"))) {
  326.             preview.add(goldPanel,c);
  327.             x++;
  328.             if (x >= 12) {
  329.                 x = 0;
  330.                 y++;
  331.             }
  332.             if (lastColor != "gold"){
  333.                 text = text + "§6";
  334.                 lastColor = "gold";
  335.             }
  336.             text = text + "█";
  337.             revalidate();
  338.         }else{
  339.             errorBox("Max Space Reached");
  340.         }
  341.         setCharLeft();
  342.     }
  343.  
  344.     /**
  345.      * adds gray
  346.      */
  347.     private void addGray(){
  348.         c.gridx = x;
  349.         c.gridy = y;
  350.         JPanel grayPanel = new JPanel();
  351.         grayPanel.setBackground(mcGray);
  352.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "gray"))) {
  353.             preview.add(grayPanel,c);
  354.             x++;
  355.             if (x >= 12) {
  356.                 x = 0;
  357.                 y++;
  358.             }
  359.             if (lastColor != "gray"){
  360.                 text = text + "§7";
  361.                 lastColor = "gray";
  362.             }
  363.             text = text + "█";
  364.             revalidate();
  365.         }else{
  366.             errorBox("Max Space Reached");
  367.         }
  368.         setCharLeft();
  369.     }
  370.  
  371.     /**
  372.      * adds dark gray
  373.      */
  374.     private void addDarkGray() {
  375.         c.gridx = x;
  376.         c.gridy = y;
  377.         JPanel darkGrayPanel = new JPanel();
  378.         darkGrayPanel.setBackground(darkGray);
  379.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark gray"))) {
  380.             preview.add(darkGrayPanel,c);
  381.             x++;
  382.             if (x >= 12) {
  383.                 x = 0;
  384.                 y++;
  385.             }
  386.             if (lastColor != "dark gray"){
  387.                 text = text + "§8";
  388.                 lastColor = "dark gray";
  389.             }
  390.             text = text + "█";
  391.             revalidate();
  392.         }else{
  393.             errorBox("Max Space Reached");
  394.         }
  395.         setCharLeft();
  396.     }
  397.  
  398.     /**
  399.      * adds blue
  400.      */
  401.     private void addBlue() {
  402.         c.gridx = x;
  403.         c.gridy = y;
  404.         JPanel bluePanel = new JPanel();
  405.         bluePanel.setBackground(lightBlue);
  406.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "blue"))) {
  407.             preview.add(bluePanel,c);
  408.             x++;
  409.             if (x >= 12) {
  410.                 x = 0;
  411.                 y++;
  412.             }
  413.             if (lastColor != "blue"){
  414.                 text = text + "§9";
  415.                 lastColor = "blue";
  416.             }
  417.             text = text + "█";
  418.             revalidate();
  419.         }else{
  420.             errorBox("Max Space Reached");
  421.         }
  422.         setCharLeft();
  423.     }
  424.  
  425.     /**
  426.      * adds green
  427.      */
  428.     private void addGreen(){
  429.         c.gridx = x;
  430.         c.gridy = y;
  431.         JPanel greenPanel = new JPanel();
  432.         greenPanel.setBackground(lightGreen);
  433.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "green"))) {
  434.             preview.add(greenPanel,c);
  435.             x++;
  436.             if (x >= 12) {
  437.                 x = 0;
  438.                 y++;
  439.             }
  440.             if (lastColor != "green"){
  441.                 text = text + "§a";
  442.                 lastColor = "green";
  443.             }
  444.             text = text + "█";
  445.             revalidate();
  446.         }else{
  447.             errorBox("Max Space Reached");
  448.         }
  449.         setCharLeft();
  450.     }
  451.  
  452.     /**
  453.      * adds aqua
  454.      */
  455.     private void addAqua(){
  456.         c.gridx = x;
  457.         c.gridy = y;
  458.         JPanel aquaPanel = new JPanel();
  459.         aquaPanel.setBackground(aqua);
  460.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "aqua"))) {
  461.             preview.add(aquaPanel,c);
  462.             x++;
  463.             if (x >= 12) {
  464.                 x = 0;
  465.                 y++;
  466.             }
  467.             if (lastColor != "aqua"){
  468.                 text = text + "§b";
  469.                 lastColor = "aqua";
  470.             }
  471.             text = text + "█";
  472.             revalidate();
  473.         }else{
  474.             errorBox("Max Space Reached");
  475.         }
  476.         setCharLeft();
  477.     }
  478.  
  479.     /**
  480.      * adds red
  481.      */
  482.     private void addRed(){
  483.         c.gridx = x;
  484.         c.gridy = y;
  485.         JPanel redPanel = new JPanel();
  486.         redPanel.setBackground(lightRed);
  487.         if ((y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "red")))) {
  488.             preview.add(redPanel,c);
  489.             x++;
  490.             if (x >= 12) {
  491.                 x = 0;
  492.                 y++;
  493.             }
  494.             if (lastColor != "red"){
  495.                 text = text + "§c";
  496.                 lastColor = "red";
  497.             }
  498.             text = text + "█";
  499.             revalidate();
  500.         }else{
  501.             errorBox("Max Space Reached");
  502.         }
  503.         setCharLeft();
  504.     }
  505.  
  506.     /**
  507.      * adds light purple
  508.      */
  509.     private void addLightPurple(){
  510.         c.gridx = x;
  511.         c.gridy = y;
  512.         JPanel lightPurplePanel = new JPanel();
  513.         lightPurplePanel.setBackground(lightPurple);
  514.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "light purple"))) {
  515.             preview.add(lightPurplePanel,c);
  516.             x++;
  517.             if (x >= 12) {
  518.                 x = 0;
  519.                 y++;
  520.             }
  521.             if (lastColor != "light purple"){
  522.                 text = text + "§d";
  523.                 lastColor = "light purple";
  524.             }
  525.             text = text + "█";
  526.             revalidate();
  527.         }else{
  528.             errorBox("Max Space Reached");
  529.         }
  530.         setCharLeft();
  531.     }
  532.  
  533.     /**
  534.      * adds yellow
  535.      */
  536.     private void addYellow(){
  537.         c.gridx = x;
  538.         c.gridy = y;
  539.         JPanel yellowPanel = new JPanel();
  540.         yellowPanel.setBackground(mcYellow);
  541.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "yellow"))) {
  542.             preview.add(yellowPanel,c);
  543.             x++;
  544.             if (x >= 12) {
  545.                 x = 0;
  546.                 y++;
  547.             }
  548.             if (lastColor != "yellow"){
  549.                 text = text + "§e";
  550.                 lastColor = "yellow";
  551.             }
  552.             text = text + "█";
  553.             revalidate();
  554.         setCharLeft();
  555.     }else{
  556.         errorBox("Max Space Reached");
  557.     }
  558. }
  559.  
  560.     /**
  561.      * adds white
  562.      */
  563.     private void addWhite() {
  564.         c.gridx = x;
  565.         c.gridy = y;
  566.         JPanel whitePanel = new JPanel();
  567.         whitePanel.setBackground(mcWhite);
  568.         if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "white"))) {
  569.             preview.add(whitePanel, c);
  570.             x++;
  571.             if (x >= 12) {
  572.                 x = 0;
  573.                 y++;
  574.             }
  575.             if (lastColor != "white"){
  576.                 text = text + "§f";
  577.                 lastColor = "white";
  578.             }
  579.             text = text + "█";
  580.             revalidate();
  581.         } else{
  582.         errorBox("Max Space Reached");
  583.         }
  584.         setCharLeft();
  585.     }
  586.  
  587.     /**
  588.      * Keeps track of character left
  589.      */
  590.     private void setCharLeft(){
  591.         charLeft = maxChar - text.length();
  592.         charactersLeft.setText(charLeft + "");
  593.     }
  594.  
  595.     /**
  596.      * I have this method in so many of my programs
  597.      * @param reason What went wrong
  598.      */
  599.     private void errorBox(String reason){
  600.         JOptionPane.showMessageDialog(null, reason, "Error", JOptionPane.ERROR_MESSAGE);
  601.     }
  602.  
  603.     public static void main(String[] args) {
  604.  
  605.         ButtonBox app = new ButtonBox();
  606.  
  607.     }
  608.  
  609. }
Advertisement
Add Comment
Please, Sign In to add comment