import java.awt.*;
import javax.swing.*;
public class TextTwist extends javax.swing.JFrame
implements java.awt.event.ActionListener
{
// hard code, should be picked from a Problem class
private String[] letters = {"U","Y","I","I","V","R","E","S","N","T"};
// hard code, should be picked from a Problem class
private String[] solutions = {"ITS", "NET", "NIT", "RUN", "SET", "SIN", "SIR", "SIT", "SUN",
"TEN", "TER", "TIE", "TIN", "TIR", "TRY", "UNI", "URN", "USE", "VET", "VIN", "YEN", "YET",
"NEST", "NETS", "NUTS", "REIN", "RENT", "REST", "RITE", "RUNS", "RUST", "SENT", "SINE",
"SITE", "TENS", "TIES", "TIRE", "UNIT", "USER", "VEIN", "VENT", "VEST", "VETS", "VINE", "VISE",
"ENTRY", "RENTS", "TIRES", "TRIES", "UNITE", "UNITY", "URINE", "VENTS", "VINES", "VIRUS", "VISIT",
"INSERT", "INVERT", "INVEST", "INVITE", "UNITES", "VIRTUE", "UNIVERSITY"};
// required designer variables
private javax.swing.JButton[] letterButtons;
private javax.swing.JButton enterButton;
private javax.swing.JButton clearButton;
private javax.swing.JLabel bufferLabel;
private javax.swing.JLabel CountdownTimer;
private javax.swing.JLabel[] solutionLabels;
// these are the GUI components
public TextTwist()
{
// needed for the Windows GUI
initializeComponent();
}
private void CountdownTimer(){
}
private void initializeComponent()
{
this.letterButtons = new javax.swing.JButton[10];
for (int i=0;i<this.letterButtons.length;i++)
{
this.letterButtons[i] = new javax.swing.JButton();
}
this.solutionLabels = new javax.swing.JLabel[solutions.length];
for (int i=0;i<this.solutions.length;i++)
{
this.solutionLabels[i] = new javax.swing.JLabel();
}
this.setLayout(null);
javax.swing.JButton button = null;
for (int i=0;i<letterButtons.length;i++)
{
button = this.letterButtons[i];
button.setBounds(500+80*i, 300, 65, 65);
button.setActionCommand("letterButton"+i);
button.setText(letters[i]);
button.setFocusable(false);
button.addActionListener(this);
button.setFont(new Font("Arial Black", Font.BOLD, 30));
button.setForeground(Color.black);
button.setBackground(Color.pink);
}
//
button = enterButton = new javax.swing.JButton();
button.setBounds(690, 400, 100, 60);
button.setActionCommand("enterButton");
button.setText("Enter");
button.setFocusable(false);
button.addActionListener(this);
enterButton.setFont(new Font("Arial Black", Font.PLAIN, 20));
enterButton.setForeground(Color.PINK);
enterButton.setBackground(Color.GRAY);
button = clearButton = new javax.swing.JButton();
button.setBounds(900, 400, 100, 60);
button.setActionCommand("clearButton");
button.setText("Clear");
button.setFocusable(false);
button.addActionListener(this);
clearButton.setFont(new Font("Arial Black", Font.PLAIN, 20));
clearButton.setForeground(Color.PINK);
clearButton.setBackground(Color.GRAY);
//
// bufferLabel
//
javax.swing.JLabel label = null;
label = this.bufferLabel = new javax.swing.JLabel();
label.setBounds(750,60,600,150);
label.setFont(new Font("Arial Black", Font.PLAIN, 40));
label.setForeground(Color.black);
label.setBackground(Color.GRAY);
for (int i=0;i<solutionLabels.length;i++)
{
label = this.solutionLabels[i];
int row=i%10;
int column=i/10;
label.setBounds(70+column*65, 50+row*65, 250, 25);
label.setFont(new Font("calibri", Font.PLAIN, 15));
label.setForeground(Color.BLACK);
for (int letterCount=0;letterCount<solutions[i].length();letterCount++)
{
label.setText( label.getText() + "-" );
label.setFont(new Font("Calibri",Font.ITALIC, 20));
label.setForeground(Color.black);
}
}
// basic Window Frame
//
this.setBounds(0, 0, 1000,1000);
for (int i=0;i<letterButtons.length;i++)
{
this.add(this.letterButtons[i]);
}
this.add(this.enterButton);
this.add(this.clearButton);
this.add(this.bufferLabel);
for (int i=0;i<solutionLabels.length;i++)
{
this.add(this.solutionLabels[i]);
}
this.setTitle("Text Twist");
this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(java.awt.event.ActionEvent ev)
{
String command = ev.getActionCommand();
if (command.equals("clearButton"))
{
clearButton_click(clearButton, ev);
}
else if (command.equals("enterButton"))
{
enterButton_click(enterButton, ev);
}
else if (command.startsWith("letterButton"))
{
int i = Integer.parseInt(command.substring(command.length( )-1,command.length()));
letterButton_click(letterButtons[i], ev);
}
}
private void letterButton_click(Object sender, java.awt.event.ActionEvent ev)
{
javax.swing.JButton button = (javax.swing.JButton) sender;
String letter = button.getText();
button.setEnabled(false);
bufferLabel.setText(bufferLabel.getText() + letter);
}
private void clearButton_click(Object sender, java.awt.event.ActionEvent ev)
{
clearBuffer();
}
private void clearBuffer()
{
for (int i=0;i<letterButtons.length;i++)
{
letterButtons[i].setEnabled(true);
}
bufferLabel.setText("");
}
private void enterButton_click(Object sender, java.awt.event.ActionEvent ev)
{
for (int i=0;i<solutions.length;i++)
{
if (bufferLabel.getText().equals(solutions[i]))
{
solutionLabels[i].setText(solutions[i]);
clearBuffer();
}
}
}
public static void main(String[] args) throws Exception
{
new TextTwist();
}
} // class TextTwist