Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.*;
- import java.awt.datatransfer.Clipboard;
- import java.awt.datatransfer.StringSelection;
- /**
- * Created by Zachary on 6/15/2016.
- *
- * Look at the buttons :P
- *
- * Dedicated to all the fun people of the SHO server, and especially Spellbound Order
- */
- public class ButtonBox extends JFrame{
- final int maxChar = 256;
- int charLeft = 256;
- int x = 0;
- int y = 0;
- public String lastColor = "black";
- public String text = new String();
- JPanel preview = new JPanel();
- JPanel charCounter = new JPanel();
- JLabel charactersLeft = new JLabel();
- Color mcBlack = new Color(0,0,0);
- Color darkBlue = new Color(0,0,170);
- Color darkGreen = new Color(0,170,0);
- Color darkAqua = new Color(0,170,170);
- Color darkRed = new Color(170,0,0);
- Color purple = new Color(170,0,170);
- Color gold = new Color(255,170,0);
- Color mcGray = new Color(170,170,170);
- Color darkGray = new Color(85,85,85);
- Color lightBlue = new Color(85,85,255);
- Color lightGreen = new Color(85,255,85);
- Color aqua = new Color(85,255,255);
- Color lightRed = new Color(255,85,85);
- Color lightPurple = new Color(255,85,255);
- Color mcYellow = new Color(255,255,85);
- Color mcWhite = new Color(255,255,255);
- GridBagConstraints c = new GridBagConstraints();
- ButtonBox(){
- setLayout(new BorderLayout());
- setTitle("MC BookArt");
- setSize(500,500);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
- JPanel color = new JPanel();
- color.setLayout(new BorderLayout());
- JPanel buttons = new JPanel();
- preview.setLayout(new GridBagLayout());
- buttons.setLayout(new GridLayout(8,2));
- JButton blackButton = new JButton();
- blackButton.addActionListener(e -> addBlack());
- JButton darkBlueButton = new JButton();
- darkBlueButton.addActionListener(e -> addDarkBlue());
- JButton darkGreenButton = new JButton();
- darkGreenButton.addActionListener(e -> addDarkGreen());
- JButton darkAquaButton = new JButton();
- darkAquaButton.addActionListener(e -> addDarkAqua());
- JButton darkRedButton = new JButton();
- darkRedButton.addActionListener(e -> addDarkRed());
- JButton darkPurpleButton = new JButton();
- darkPurpleButton.addActionListener(e -> addDarkPurple());
- JButton goldButton = new JButton();
- goldButton.addActionListener(e -> addGold());
- JButton grayButton = new JButton();
- grayButton.addActionListener(e -> addGray());
- JButton darkGrayButton = new JButton();
- darkGrayButton.addActionListener(e -> addDarkGray());
- JButton blueButton = new JButton();
- blueButton.addActionListener(e -> addBlue());
- JButton greenButton = new JButton();
- greenButton.addActionListener(e -> addGreen());
- JButton aquaButton = new JButton();
- aquaButton.addActionListener(e -> addAqua());
- JButton redButton = new JButton();
- redButton.addActionListener(e -> addRed());
- JButton lightPurpleButton = new JButton();
- lightPurpleButton.addActionListener(e -> addLightPurple());
- JButton yellowButton = new JButton();
- yellowButton.addActionListener(e -> addYellow());
- JButton whiteButton = new JButton();
- whiteButton.addActionListener(e -> addWhite());
- JButton copy = new JButton("Copy to Clipboard");
- copy.addActionListener(e -> copyAsText());
- charCounter.setLayout(new GridLayout(1,2));
- add(color,BorderLayout.EAST);
- color.add(buttons,BorderLayout.CENTER);
- add(preview,BorderLayout.CENTER);
- color.add(new JLabel("Colors"),BorderLayout.NORTH);
- add(copy,BorderLayout.SOUTH);
- add(charCounter,BorderLayout.NORTH);
- charCounter.add(new JLabel("Characters Left"));
- charCounter.add(charactersLeft);
- buttons.add(blackButton);
- blackButton.setBackground(mcBlack);
- buttons.add(darkBlueButton);
- darkBlueButton.setBackground(darkBlue);
- buttons.add(darkGreenButton);
- darkGreenButton.setBackground(darkGreen);
- buttons.add(darkAquaButton);
- darkAquaButton.setBackground(darkAqua);
- buttons.add(darkRedButton);
- darkRedButton.setBackground(darkRed);
- buttons.add(darkPurpleButton);
- darkPurpleButton.setBackground(purple);
- buttons.add(goldButton);
- goldButton.setBackground(gold);
- buttons.add(grayButton);
- grayButton.setBackground(mcGray);
- buttons.add(darkGrayButton);
- darkGrayButton.setBackground(darkGray);
- buttons.add(blueButton);
- blueButton.setBackground(lightBlue);
- buttons.add(greenButton);
- greenButton.setBackground(lightGreen);
- buttons.add(aquaButton);
- aquaButton.setBackground(aqua);
- buttons.add(redButton);
- redButton.setBackground(lightRed);
- buttons.add(lightPurpleButton);
- lightPurpleButton.setBackground(lightPurple);
- buttons.add(yellowButton);
- yellowButton.setBackground(mcYellow);
- buttons.add(whiteButton);
- whiteButton.setBackground(mcWhite);
- revalidate();
- setVisible(true);
- }
- /**
- * Copies to clipboard
- */
- private void copyAsText() {
- StringSelection selection = new StringSelection(text);
- Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
- clipboard.setContents(selection, selection);
- JOptionPane.showMessageDialog(null,"Text copied to Clipboard");
- }
- /**
- * Adds black
- */
- private void addBlack() {
- c.gridx = x;
- c.gridy = y;
- JPanel blackPanel = new JPanel();
- blackPanel.setBackground(mcBlack);
- blackPanel.setSize(10,10);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "black"))) {
- preview.add(blackPanel,c);
- blackPanel.setAlignmentX(x);
- blackPanel.setAlignmentY(y);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "black"){
- text = text + "§0";
- lastColor = "black";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds dark blue
- */
- private void addDarkBlue(){
- c.gridx = x;
- c.gridy = y;
- JPanel darkBluePanel = new JPanel();
- darkBluePanel.setBackground(darkBlue);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark blue"))) {
- preview.add(darkBluePanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "dark blue"){
- text = text + "§1";
- lastColor = "dark blue";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds dark green
- */
- private void addDarkGreen(){
- c.gridx = x;
- c.gridy = y;
- JPanel darkGreenPanel = new JPanel();
- darkGreenPanel.setBackground(darkGreen);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark green"))) {
- preview.add(darkGreenPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "dark green"){
- text = text + "§2";
- lastColor = "dark green";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds dark aqua
- */
- private void addDarkAqua(){
- c.gridx = x;
- c.gridy = y;
- JPanel darkAquaPanel = new JPanel();
- darkAquaPanel.setBackground(darkAqua);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark aqua"))) {
- preview.add(darkAquaPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "dark aqua"){
- text = text + "§3";
- lastColor = "dark aqua";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds dark red
- */
- private void addDarkRed(){
- c.gridx = x;
- c.gridy = y;
- JPanel darkRedPanel = new JPanel();
- darkRedPanel.setBackground(darkRed);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark red"))) {
- preview.add(darkRedPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "dark red"){
- text = text + "§4";
- lastColor = "dark red";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds dark purple
- */
- private void addDarkPurple(){
- c.gridx = x;
- c.gridy = y;
- JPanel darkPurplePanel = new JPanel();
- darkPurplePanel.setBackground(purple);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark purple"))) {
- preview.add(darkPurplePanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "dark purple"){
- text = text + "§5";
- lastColor = "dark purple";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds gold
- */
- private void addGold(){
- c.gridx = x;
- c.gridy = y;
- JPanel goldPanel = new JPanel();
- goldPanel.setBackground(gold);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "gold"))) {
- preview.add(goldPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "gold"){
- text = text + "§6";
- lastColor = "gold";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds gray
- */
- private void addGray(){
- c.gridx = x;
- c.gridy = y;
- JPanel grayPanel = new JPanel();
- grayPanel.setBackground(mcGray);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "gray"))) {
- preview.add(grayPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "gray"){
- text = text + "§7";
- lastColor = "gray";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds dark gray
- */
- private void addDarkGray() {
- c.gridx = x;
- c.gridy = y;
- JPanel darkGrayPanel = new JPanel();
- darkGrayPanel.setBackground(darkGray);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "dark gray"))) {
- preview.add(darkGrayPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "dark gray"){
- text = text + "§8";
- lastColor = "dark gray";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds blue
- */
- private void addBlue() {
- c.gridx = x;
- c.gridy = y;
- JPanel bluePanel = new JPanel();
- bluePanel.setBackground(lightBlue);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "blue"))) {
- preview.add(bluePanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "blue"){
- text = text + "§9";
- lastColor = "blue";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds green
- */
- private void addGreen(){
- c.gridx = x;
- c.gridy = y;
- JPanel greenPanel = new JPanel();
- greenPanel.setBackground(lightGreen);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "green"))) {
- preview.add(greenPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "green"){
- text = text + "§a";
- lastColor = "green";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds aqua
- */
- private void addAqua(){
- c.gridx = x;
- c.gridy = y;
- JPanel aquaPanel = new JPanel();
- aquaPanel.setBackground(aqua);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "aqua"))) {
- preview.add(aquaPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "aqua"){
- text = text + "§b";
- lastColor = "aqua";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds red
- */
- private void addRed(){
- c.gridx = x;
- c.gridy = y;
- JPanel redPanel = new JPanel();
- redPanel.setBackground(lightRed);
- if ((y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "red")))) {
- preview.add(redPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "red"){
- text = text + "§c";
- lastColor = "red";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds light purple
- */
- private void addLightPurple(){
- c.gridx = x;
- c.gridy = y;
- JPanel lightPurplePanel = new JPanel();
- lightPurplePanel.setBackground(lightPurple);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "light purple"))) {
- preview.add(lightPurplePanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "light purple"){
- text = text + "§d";
- lastColor = "light purple";
- }
- text = text + "█";
- revalidate();
- }else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * adds yellow
- */
- private void addYellow(){
- c.gridx = x;
- c.gridy = y;
- JPanel yellowPanel = new JPanel();
- yellowPanel.setBackground(mcYellow);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "yellow"))) {
- preview.add(yellowPanel,c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "yellow"){
- text = text + "§e";
- lastColor = "yellow";
- }
- text = text + "█";
- revalidate();
- setCharLeft();
- }else{
- errorBox("Max Space Reached");
- }
- }
- /**
- * adds white
- */
- private void addWhite() {
- c.gridx = x;
- c.gridy = y;
- JPanel whitePanel = new JPanel();
- whitePanel.setBackground(mcWhite);
- if (y < 14 && (maxChar - charLeft + 2 < maxChar || (maxChar - charLeft < maxChar && lastColor == "white"))) {
- preview.add(whitePanel, c);
- x++;
- if (x >= 12) {
- x = 0;
- y++;
- }
- if (lastColor != "white"){
- text = text + "§f";
- lastColor = "white";
- }
- text = text + "█";
- revalidate();
- } else{
- errorBox("Max Space Reached");
- }
- setCharLeft();
- }
- /**
- * Keeps track of character left
- */
- private void setCharLeft(){
- charLeft = maxChar - text.length();
- charactersLeft.setText(charLeft + "");
- }
- /**
- * I have this method in so many of my programs
- * @param reason What went wrong
- */
- private void errorBox(String reason){
- JOptionPane.showMessageDialog(null, reason, "Error", JOptionPane.ERROR_MESSAGE);
- }
- public static void main(String[] args) {
- ButtonBox app = new ButtonBox();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment