import java.util.Set; import java.util.TreeSet; public class BoggleGUI extends javax.swing.JFrame { private BoggleGame game; /** Creates new form BoggleGUI */ public BoggleGUI() { initComponents(); initGame(); } private void initGame() { game = new BoggleGame(); boardArea.setText(game.getBoard()); guessedArea.setText("Guessed so far:\n"); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); boardArea = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); guessedArea = new javax.swing.JTextArea(); jLabel2 = new javax.swing.JLabel(); entered = new javax.swing.JTextField(); submitButton = new javax.swing.JButton(); DoneButton = new javax.swing.JButton(); AgainButton = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); boardArea.setColumns(7); boardArea.setFont(new java.awt.Font("Courier New", 0, 13)); boardArea.setRows(4); boardArea.setText("a b c d\ne f g h\ni j k l\nm n o p"); jScrollPane1.setViewportView(boardArea); guessedArea.setColumns(20); guessedArea.setFont(new java.awt.Font("Courier New", 0, 13)); guessedArea.setRows(5); jScrollPane2.setViewportView(guessedArea); jLabel2.setText("Enter word:"); submitButton.setText("Submit"); submitButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { submitButtonMouseClicked(evt); } }); DoneButton.setText("I Give Up"); DoneButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { DoneButtonMouseClicked(evt); } }); AgainButton.setText("Play Again"); AgainButton.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { AgainButtonMouseClicked(evt); } }); jLabel1.setFont(new java.awt.Font("Arial", 1, 14)); jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel1.setText("Dave's Boggle Game"); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .addContainerGap() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE) .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, submitButton) .add(org.jdesktop.layout.GroupLayout.LEADING, entered, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE) .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))) .add(layout.createSequentialGroup() .add(DoneButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 52, Short.MAX_VALUE) .add(AgainButton))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(jLabel1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 16, Short.MAX_VALUE) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) .add(layout.createSequentialGroup() .add(jLabel2) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(entered, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(submitButton)) .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 255, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(DoneButton) .add(AgainButton)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private void AgainButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_AgainButtonMouseClicked initGame(); }//GEN-LAST:event_AgainButtonMouseClicked private void DoneButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_DoneButtonMouseClicked guessedArea.append("You missed: \n"); for (String str : this.game.getUnguessedWords()) { guessedArea.append(str + "\n"); } }//GEN-LAST:event_DoneButtonMouseClicked private void submitButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_submitButtonMouseClicked String response = entered.getText(); if (this.game.makeGuess(response)) { guessedArea.append(response+"\n"); } entered.setText(""); }//GEN-LAST:event_submitButtonMouseClicked /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new BoggleGUI().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton AgainButton; private javax.swing.JButton DoneButton; private javax.swing.JTextArea boardArea; private javax.swing.JTextField entered; private javax.swing.JTextArea guessedArea; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JButton submitButton; // End of variables declaration//GEN-END:variables }