Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create an educational program for children that distinguishes between vowels and

ID: 672671 • Letter: C

Question

Create an educational program for children that distinguishes between vowels and consonants as the user clicks buttons. Create 26 JButtons, each labeled with a different letter of the alphabet. Create a JFrame to hold three JPanels in a two- by-two grid. Randomly select eight of the 26 JButtons and place four in each of the first two JPanels. Add a JLabel to the third JPanel. When the user clicks

a JButton, the text of the JLabel identifies the button’s letter as a vowel or consonant, and then a new randomly selected letter replaces the letter on the JButton. Save the file as JVowelConsonant.java.

Explanation / Answer

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;

public class MainFrame extends javax.swing.JFrame {

public MainFrame() {
initComponents();
}

static String secretWord = "";
StringBuilder mainWord = new StringBuilder();
String[] words = {"temporary", "education", "playing", "technical", "digital" };
Random r = new Random();
int randValue = r.nextInt(11)+1;
String guessWord = words[0];
int errors = 0;
public static int wins = 0, losses = 0;
String foundWord = null;
String currentLetter;
private void RestartButtonActionPerformed(java.awt.event.ActionEvent evt) {
  
DirectionsFrame DFrame = new DirectionsFrame();
DFrame.setVisible(true);
setVisible(false);
MainFrame MFrame = new MainFrame();
MFrame.dispose();
secretWord = "";
foundWord = null;
DirectionsFrame.WinsLabel.setText(null);
DirectionsFrame.LossesLabel.setText(null);
}   

private void GetButtonActionPerformed(java.awt.event.ActionEvent evt) {
for (int i = 0; i < guessWord.length(); i++) {
mainWord.append("_ ");
}
String SetMain = mainWord.toString();
mainWord.append(secretWord);
WordLabel.setText(SetMain);
GetButton.setEnabled(false);
AButton.setEnabled(true);
BButton.setEnabled(true);
CButton.setEnabled (true);
DButton.setEnabled(true);
EButton.setEnabled(true);
  
FButton.setEnabled(true);
GButton.setEnabled(true);
HButton.setEnabled (true);
IButton.setEnabled(true);
JButton.setEnabled(true);
KButton.setEnabled(true);
LButton.setEnabled(true);
MButton.setEnabled(true);
NButton.setEnabled(true);
OButton.setEnabled(true);
PButton.setEnabled(true);
QButton.setEnabled(true);
RButton.setEnabled(true);
SButton.setEnabled(true);
TButton.setEnabled(true);
UButton.setEnabled(true);
VButton.setEnabled(true);
WButton.setEnabled(true);
XButton.setEnabled(true);
YButton.setEnabled(true);
ZButton.setEnabled(true);
}   

private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {   
// Exit the program
System.exit(0);
}

private void AButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void BButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void CButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void DButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void EButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void FButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void GButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void HButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void IButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void JButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void KButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void LButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void MButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void NButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void OButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void PButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void QButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void RButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void SButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void TButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void UButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void VButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void WButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void XButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void YButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void ZButtonActionPerformed(java.awt.event.ActionEvent evt) {
DoButton.doClick();
}   

private void DoButtonActionPerformed(java.awt.event.ActionEvent evt) {   
JButton button = (JButton) evt.getSource();
String currentLetter = button.getText();

//replace underscores with letters as they are guessed
do {
for (int i = 0; i < 1; i++) {
secretWord = secretWord + currentLetter.charAt(0);
foundWord = words[0].replaceAll("[^" + secretWord + "]", "_ ");
//if letter isn't in word
if (guessWord.indexOf(currentLetter) == -1) {
JOptionPane.showMessageDialog(null, "Sorry, that wasn't in the word.");
errors++;
if (errors == 1) {
Hangman0.setVisible(false);
}
if (errors == 2) {
Hangman1.setVisible(false);
}
if (errors == 3) {
Hangman2.setVisible(false);
}
if (errors == 4) {
Hangman3.setVisible(false);
}
if (errors == 5) {
Hangman4.setVisible(false);
}
if (errors == 6) {
Hangman5.setVisible(false);
}
if (errors == 7) {
Hangman6.setVisible(false);
}
if (errors == 8) {
Hangman7.setVisible(false);
}
if (errors == 9) {
Hangman8.setVisible(false);
}
if (errors == 10) {
Hangman9.setVisible(false);
JOptionPane.showMessageDialog(null, "You lost! The word was: " + guessWord);
losses++;
DirectionsFrame DFrame = new DirectionsFrame();
DFrame.setVisible(true);
setVisible(false);
MainFrame MFrame = new MainFrame();
MFrame.dispose();
secretWord = "";
foundWord = null;
String strLosses = Integer.toString(losses);
String strWin = Integer.toString(wins);
DirectionsFrame.WinsLabel.setText(strWin);
DirectionsFrame.LossesLabel.setText(strLosses);
}
}
}
WordLabel.setText(foundWord.toUpperCase());
} while (foundWord == null);
if (foundWord.equalsIgnoreCase(guessWord)) {
JOptionPane.showMessageDialog(null, "Yay!");
wins++;
DirectionsFrame DFrame = new DirectionsFrame();
DFrame.setVisible(true);
setVisible(false);
MainFrame MFrame = new MainFrame();
MFrame.dispose();
secretWord = "";
foundWord = null;
String strWin = Integer.toString(wins);
String strLosses = Integer.toString(losses);
DirectionsFrame.WinsLabel.setText(strWin);
DirectionsFrame.LossesLabel.setText(strLosses);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote