SlideShare a Scribd company logo
1 of 8
Download to read offline
So I need to create a compound word game, and I don't quite understand how I can split up the
compound words that are selected by the user on a frame into individual buttons where each
button represents each letter, and the user can select which one starts the second word in a
compound word otherwise gives a prompt indicating their wrong and should try again without
having to make a class for each compound word I have. Below I have provided the array of
words, and the word class needed after that will be the startLetter class, where the compound
word is supposed to split into individual buttons. My whole goal is to fit it into one startLetter
class without needing a class for each of the compound words, so in this case, five different
classes I feel aren't necessary.
The compoundWordProject 4 Class/ Main
package compoundWordsProject4;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
//Creates class compoundWords4, extends JFrame and implemetns an ActionListener
public class compoundWords4 extends JFrame implements ActionListener {
//Creates instances for the Words array
static Word Words1 = new Word("SAND");
static Word Words2 = new Word("SANDWHICH", 5);
static Word Words3 = new Word("BED");
static Word Words4 = new Word("BEDROOM", 4);
static Word Words5 = new Word("CHESSECAKE", 7);
static Word Words6 = new Word("CAKE");
static Word Words7 = new Word("Apple");
static Word Words8 = new Word("FireHouse", 5);
static Word Words9 = new Word("Base");
static Word Words10 = new Word("BaseBall", 5);
static Word Words11 = new Word("Ball");
static Word Words12 = new Word("Bat");
// Creates an array for the word instances
static Word[] Words = { Words1, Words2, Words3, Words4, Words5, Words6, Words7,
Words8, Words9, Words10, Words11, Words12};
//Creates an empty array of buttons
JButton[] buttons;
//Creates a private variable for click
private JLabel click;
//Creates the constructor for compoundWords
public compoundWords4() {
setLayout(new FlowLayout()); //Sets the layout
//Creates a label
click = new JLabel("Click on a Compound Word:");
click.setFont(new Font("Arial", Font.BOLD, 25));
add(click);
//Adds words from the string array into Jbuttons
buttons = new JButton[Words.length];
//Creates all the buttons from array and adds actionListner
for(int i = 0; i < buttons.length; i++) {
buttons[i] = new JButton(Words[i].getWord());
buttons[i].addActionListener(this);
add(buttons[i]);
}
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Closes the program when the window
is closed
}
public void actionPerformed(ActionEvent e) {
//Creates action performed when buttons are clicked
if(e.getSource() == buttons[0]) {
JOptionPane.showMessageDialog(null, "This is not a compound Word", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
}else if(e.getSource() == buttons[1]) {
//Creates a window for startLetter if SandWhich is clicked
startLetter frame2 = new startLetter();
frame2.setVisible(true);
frame2.setSize(400,400);
frame2.setLocation(400,200);
frame2.setTitle("Starting Letter");
}
public static void main (String args[]){
//Creates a window for difficulty
difficulty frame7 = new difficulty();
frame7.setSize(400,400);
frame7.setTitle("Compound Word Game");
frame7.setVisible(true);
}
}
The Word class
package compoundWordsProject4;
//Creates the public class called "word" creates attributes called "word, index and isCompound"
public class Word{
private String word;
private int index;
private boolean isCompound;
//Creates attributes called "difficulty" and "topics"
private int difficulty;
private String[] topics;
//Creates the constructor for the compound words
public Word(String w, int i){
this.word = w;
this.index = i;
isCompound = true;
}
//Create the constructor for "word"
public Word(String w){
this.word = w;
isCompound = false;
}
//Creates a get method for difficulty
public int getDifficulty() {
return difficulty;
}
//Creates a set method for difficulty
public void setDifficulty(int d) {
this.difficulty = d;
}
//Creates a get method for topics
public String[] getTopics() {
return topics;
}
//Creates a set method for topics
public void setTopics(String[] t) {
this.topics = t;
}
//Creates a get method for "word"
public String getWord(){
return word;
}
//Creates a set method for "word"
public void setWord(String w){
this.word = w;
}
//Creates a get method for "index"
public int getIndex(){
return index;
}
//Creates a set method for "index"
public void setIndex(int i){
this.index = i;
}
//Creates a boolean method for "isCompound"
public boolean isCompound(){
return isCompound;
}
//Creates a set boolean method for "isCompound"
public void setCompound(boolean isCompound){
this.isCompound = isCompound;
}
}
The startLetter class
package compoundWordsProject4;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class startLetter extends JFrame implements ActionListener{
//Creates private variables
private JButton S;
private JButton A;
private JButton N;
private JButton D;
private JButton W;
private JButton H;
private JButton I;
private JButton C;
private JButton H2;
private JLabel click2;
//Creates a constructor for startLetter
public startLetter() {
setLayout(new FlowLayout()); //Sets layout
//Creates a label
click2 = new JLabel("Click on the letter where the second compound word begins: ");
click2.setFont(new Font("Arial", Font.BOLD, 13));
add(click2);
//Creates a button for letter S
S = new JButton("S");
S.addActionListener(this);
add(S);
//Creates a button for letter A
A = new JButton("A");
A.addActionListener(this);
add(A);
//Creates a button for letter N
N = new JButton("N");
N.addActionListener(this);
add(N);
//Creates a button for letter D
D = new JButton("D");
D.addActionListener(this);
add(D);
//Creates a button for letter W
W = new JButton("W");
W.addActionListener(this);
add(W);
//Creates a button for letter H
H = new JButton("H");
H.addActionListener(this);
add(H);
//Creates a button for letter I
I = new JButton("I");
I.addActionListener(this);
add(I);
//Creates a button for letter C
C = new JButton("C");
C.addActionListener(this);
add(C);
//Creates a button for the second letter H
H2 = new JButton("H");
H2.addActionListener(this);
add(H2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Stops program when window
closes
}
public void actionPerformed(ActionEvent e) {
//Creates action performed when the letters buttons are clicked
if(e.getSource() == S) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
} else if(e.getSource() == A) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
} else if(e.getSource() == N) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
} else if(e.getSource() == D) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
//Congratulates the user and closes the program
} else if(e.getSource() == W) {
JOptionPane.showMessageDialog(null, "That is correct!!", "Correct",
JOptionPane.PLAIN_MESSAGE);
System.exit(0);
} else if(e.getSource() == H) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
} else if(e.getSource() == I) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
} else if(e.getSource() == C) {
JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
} else if(e.getSource() == H2) {
JOptionPane.showMessageDialog(null, "This is not a compound Word", "Incorrect",
JOptionPane.PLAIN_MESSAGE);
}
}
}

More Related Content

Similar to So I need to create a compound word game, and I dont quite understa.pdf

I hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdfI hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdfapexelectronices01
 
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdfoptokunal1
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdfanokhijew
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfatulkapoor33
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz Dziuda
 
Convert the following program so that it uses JList instead of JComb.pdf
Convert the following program so that it uses JList instead of JComb.pdfConvert the following program so that it uses JList instead of JComb.pdf
Convert the following program so that it uses JList instead of JComb.pdfbermanbeancolungak45
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxRAHUL126667
 
10 awt event model
10 awt event model10 awt event model
10 awt event modelBayarkhuu
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfaakarcreations1
 
Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed contentYogesh Kumar
 
gUIsInterfacebuild.xml Builds, tests, and runs the pro.docx
gUIsInterfacebuild.xml      Builds, tests, and runs the pro.docxgUIsInterfacebuild.xml      Builds, tests, and runs the pro.docx
gUIsInterfacebuild.xml Builds, tests, and runs the pro.docxwhittemorelucilla
 
Program-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdfProgram-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdfaparnacollection
 
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdfPasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdfanjaniar7gallery
 
Object Oriented Programming Session 4 part 2 Slides .pptx
Object Oriented Programming Session 4 part 2 Slides .pptxObject Oriented Programming Session 4 part 2 Slides .pptx
Object Oriented Programming Session 4 part 2 Slides .pptxr209777z
 
Android tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingAndroid tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingVlad Kolesnyk
 
How to develop frontend application
How to develop frontend applicationHow to develop frontend application
How to develop frontend applicationSeokjun Kim
 
JSF Custom Components
JSF Custom ComponentsJSF Custom Components
JSF Custom ComponentsMichael Fons
 

Similar to So I need to create a compound word game, and I dont quite understa.pdf (20)

I hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdfI hope the below code is helpful to you, please give me rewards.im.pdf
I hope the below code is helpful to you, please give me rewards.im.pdf
 
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
1) Write a shortsnippetofcodethatcreates a J Panel objectcalled p1, .pdf
 
Code to copy Person.java .pdf
Code to copy Person.java .pdfCode to copy Person.java .pdf
Code to copy Person.java .pdf
 
final project for C#
final project for C#final project for C#
final project for C#
 
Java ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdfJava ProgrammingImplement an auction application with the followin.pdf
Java ProgrammingImplement an auction application with the followin.pdf
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
JavaScript ES6
JavaScript ES6JavaScript ES6
JavaScript ES6
 
Convert the following program so that it uses JList instead of JComb.pdf
Convert the following program so that it uses JList instead of JComb.pdfConvert the following program so that it uses JList instead of JComb.pdf
Convert the following program so that it uses JList instead of JComb.pdf
 
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docxC#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
C#_hw9_S17.docModify AnimatedBall on Chapter 13. Instead of dr.docx
 
10 awt event model
10 awt event model10 awt event model
10 awt event model
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdf
 
Gui programming a review - mixed content
Gui programming   a review - mixed contentGui programming   a review - mixed content
Gui programming a review - mixed content
 
gUIsInterfacebuild.xml Builds, tests, and runs the pro.docx
gUIsInterfacebuild.xml      Builds, tests, and runs the pro.docxgUIsInterfacebuild.xml      Builds, tests, and runs the pro.docx
gUIsInterfacebuild.xml Builds, tests, and runs the pro.docx
 
Program-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdfProgram-a. library is importedimport java.awt.; import j.pdf
Program-a. library is importedimport java.awt.; import j.pdf
 
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdfPasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
PasswordCheckerGUI.javaimport javafx.application.Application; im.pdf
 
Object Oriented Programming Session 4 part 2 Slides .pptx
Object Oriented Programming Session 4 part 2 Slides .pptxObject Oriented Programming Session 4 part 2 Slides .pptx
Object Oriented Programming Session 4 part 2 Slides .pptx
 
GUI programming
GUI programmingGUI programming
GUI programming
 
Android tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogrammingAndroid tutorials7 calculator_javaprogramming
Android tutorials7 calculator_javaprogramming
 
How to develop frontend application
How to develop frontend applicationHow to develop frontend application
How to develop frontend application
 
JSF Custom Components
JSF Custom ComponentsJSF Custom Components
JSF Custom Components
 

More from leolight2

Si el gobierno se hubiera apoderado de los activos de Global Trading.pdf
Si el gobierno se hubiera apoderado de los activos de Global Trading.pdfSi el gobierno se hubiera apoderado de los activos de Global Trading.pdf
Si el gobierno se hubiera apoderado de los activos de Global Trading.pdfleolight2
 
Si bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdf
Si bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdfSi bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdf
Si bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdfleolight2
 
SHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdf
SHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdfSHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdf
SHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdfleolight2
 
Si bien la mayor�a de los visitantes de Washington, DC, visitan los .pdf
Si bien la mayor�a de los visitantes de Washington, DC, visitan los .pdfSi bien la mayor�a de los visitantes de Washington, DC, visitan los .pdf
Si bien la mayor�a de los visitantes de Washington, DC, visitan los .pdfleolight2
 
Si bien es importante que los vendedores internacionales aprecien .pdf
Si bien es importante que los vendedores internacionales aprecien .pdfSi bien es importante que los vendedores internacionales aprecien .pdf
Si bien es importante que los vendedores internacionales aprecien .pdfleolight2
 
Show the Relational Algebra formula for each. This one may be a phot.pdf
Show the Relational Algebra formula for each. This one may be a phot.pdfShow the Relational Algebra formula for each. This one may be a phot.pdf
Show the Relational Algebra formula for each. This one may be a phot.pdfleolight2
 
should be at least two paragraphs long, or more, depending upon the .pdf
should be at least two paragraphs long, or more, depending upon the .pdfshould be at least two paragraphs long, or more, depending upon the .pdf
should be at least two paragraphs long, or more, depending upon the .pdfleolight2
 
Should Governments Report Like BusinessesHistorically, states a.pdf
Should Governments Report Like BusinessesHistorically, states a.pdfShould Governments Report Like BusinessesHistorically, states a.pdf
Should Governments Report Like BusinessesHistorically, states a.pdfleolight2
 
Seventy-three percent of adults in a certain country believe that li.pdf
Seventy-three percent of adults in a certain country believe that li.pdfSeventy-three percent of adults in a certain country believe that li.pdf
Seventy-three percent of adults in a certain country believe that li.pdfleolight2
 
Sheffield Corporation, a private corporation, was organized on Febru.pdf
Sheffield Corporation, a private corporation, was organized on Febru.pdfSheffield Corporation, a private corporation, was organized on Febru.pdf
Sheffield Corporation, a private corporation, was organized on Febru.pdfleolight2
 
SHOW ANSWER ON GRAPH Many demographers predict that the United State.pdf
SHOW ANSWER ON GRAPH Many demographers predict that the United State.pdfSHOW ANSWER ON GRAPH Many demographers predict that the United State.pdf
SHOW ANSWER ON GRAPH Many demographers predict that the United State.pdfleolight2
 
Ser capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdf
Ser capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdfSer capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdf
Ser capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdfleolight2
 
Solve all of them If the marginal propensity to save is 0.25 , then.pdf
Solve all of them  If the marginal propensity to save is 0.25 , then.pdfSolve all of them  If the marginal propensity to save is 0.25 , then.pdf
Solve all of them If the marginal propensity to save is 0.25 , then.pdfleolight2
 
Solution Register a service endpoint in the Dataverse instance that.pdf
Solution Register a service endpoint in the Dataverse instance that.pdfSolution Register a service endpoint in the Dataverse instance that.pdf
Solution Register a service endpoint in the Dataverse instance that.pdfleolight2
 
Solutions for The Toliza Museum of Art, did not cover all the answer.pdf
Solutions for The Toliza Museum of Art, did not cover all the answer.pdfSolutions for The Toliza Museum of Art, did not cover all the answer.pdf
Solutions for The Toliza Museum of Art, did not cover all the answer.pdfleolight2
 
Soles es una empresa de calzado que ha abierto recientemente su tien.pdf
Soles es una empresa de calzado que ha abierto recientemente su tien.pdfSoles es una empresa de calzado que ha abierto recientemente su tien.pdf
Soles es una empresa de calzado que ha abierto recientemente su tien.pdfleolight2
 
So I have 3 enums named land_type, entity, tile as shown enum lan.pdf
So I have 3 enums named land_type, entity, tile as shown enum lan.pdfSo I have 3 enums named land_type, entity, tile as shown enum lan.pdf
So I have 3 enums named land_type, entity, tile as shown enum lan.pdfleolight2
 
So for C-ferns the CP is the commonwild type (green) and the cp is .pdf
So for C-ferns the CP is the commonwild type (green) and the cp is .pdfSo for C-ferns the CP is the commonwild type (green) and the cp is .pdf
So for C-ferns the CP is the commonwild type (green) and the cp is .pdfleolight2
 
SLL Corporation�s balance sheet is shown below. The current rate on .pdf
SLL Corporation�s balance sheet is shown below. The current rate on .pdfSLL Corporation�s balance sheet is shown below. The current rate on .pdf
SLL Corporation�s balance sheet is shown below. The current rate on .pdfleolight2
 
So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfleolight2
 

More from leolight2 (20)

Si el gobierno se hubiera apoderado de los activos de Global Trading.pdf
Si el gobierno se hubiera apoderado de los activos de Global Trading.pdfSi el gobierno se hubiera apoderado de los activos de Global Trading.pdf
Si el gobierno se hubiera apoderado de los activos de Global Trading.pdf
 
Si bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdf
Si bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdfSi bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdf
Si bien puede diferir en otros pa�ses, en los Estados Unidos la dist.pdf
 
SHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdf
SHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdfSHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdf
SHOW STEPS IN EXCEL PLEASE.Data DayDateWeekdayDaily Deman.pdf
 
Si bien la mayor�a de los visitantes de Washington, DC, visitan los .pdf
Si bien la mayor�a de los visitantes de Washington, DC, visitan los .pdfSi bien la mayor�a de los visitantes de Washington, DC, visitan los .pdf
Si bien la mayor�a de los visitantes de Washington, DC, visitan los .pdf
 
Si bien es importante que los vendedores internacionales aprecien .pdf
Si bien es importante que los vendedores internacionales aprecien .pdfSi bien es importante que los vendedores internacionales aprecien .pdf
Si bien es importante que los vendedores internacionales aprecien .pdf
 
Show the Relational Algebra formula for each. This one may be a phot.pdf
Show the Relational Algebra formula for each. This one may be a phot.pdfShow the Relational Algebra formula for each. This one may be a phot.pdf
Show the Relational Algebra formula for each. This one may be a phot.pdf
 
should be at least two paragraphs long, or more, depending upon the .pdf
should be at least two paragraphs long, or more, depending upon the .pdfshould be at least two paragraphs long, or more, depending upon the .pdf
should be at least two paragraphs long, or more, depending upon the .pdf
 
Should Governments Report Like BusinessesHistorically, states a.pdf
Should Governments Report Like BusinessesHistorically, states a.pdfShould Governments Report Like BusinessesHistorically, states a.pdf
Should Governments Report Like BusinessesHistorically, states a.pdf
 
Seventy-three percent of adults in a certain country believe that li.pdf
Seventy-three percent of adults in a certain country believe that li.pdfSeventy-three percent of adults in a certain country believe that li.pdf
Seventy-three percent of adults in a certain country believe that li.pdf
 
Sheffield Corporation, a private corporation, was organized on Febru.pdf
Sheffield Corporation, a private corporation, was organized on Febru.pdfSheffield Corporation, a private corporation, was organized on Febru.pdf
Sheffield Corporation, a private corporation, was organized on Febru.pdf
 
SHOW ANSWER ON GRAPH Many demographers predict that the United State.pdf
SHOW ANSWER ON GRAPH Many demographers predict that the United State.pdfSHOW ANSWER ON GRAPH Many demographers predict that the United State.pdf
SHOW ANSWER ON GRAPH Many demographers predict that the United State.pdf
 
Ser capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdf
Ser capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdfSer capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdf
Ser capaz de amplificar fragmentos de ADN espec�ficos es fundamental.pdf
 
Solve all of them If the marginal propensity to save is 0.25 , then.pdf
Solve all of them  If the marginal propensity to save is 0.25 , then.pdfSolve all of them  If the marginal propensity to save is 0.25 , then.pdf
Solve all of them If the marginal propensity to save is 0.25 , then.pdf
 
Solution Register a service endpoint in the Dataverse instance that.pdf
Solution Register a service endpoint in the Dataverse instance that.pdfSolution Register a service endpoint in the Dataverse instance that.pdf
Solution Register a service endpoint in the Dataverse instance that.pdf
 
Solutions for The Toliza Museum of Art, did not cover all the answer.pdf
Solutions for The Toliza Museum of Art, did not cover all the answer.pdfSolutions for The Toliza Museum of Art, did not cover all the answer.pdf
Solutions for The Toliza Museum of Art, did not cover all the answer.pdf
 
Soles es una empresa de calzado que ha abierto recientemente su tien.pdf
Soles es una empresa de calzado que ha abierto recientemente su tien.pdfSoles es una empresa de calzado que ha abierto recientemente su tien.pdf
Soles es una empresa de calzado que ha abierto recientemente su tien.pdf
 
So I have 3 enums named land_type, entity, tile as shown enum lan.pdf
So I have 3 enums named land_type, entity, tile as shown enum lan.pdfSo I have 3 enums named land_type, entity, tile as shown enum lan.pdf
So I have 3 enums named land_type, entity, tile as shown enum lan.pdf
 
So for C-ferns the CP is the commonwild type (green) and the cp is .pdf
So for C-ferns the CP is the commonwild type (green) and the cp is .pdfSo for C-ferns the CP is the commonwild type (green) and the cp is .pdf
So for C-ferns the CP is the commonwild type (green) and the cp is .pdf
 
SLL Corporation�s balance sheet is shown below. The current rate on .pdf
SLL Corporation�s balance sheet is shown below. The current rate on .pdfSLL Corporation�s balance sheet is shown below. The current rate on .pdf
SLL Corporation�s balance sheet is shown below. The current rate on .pdf
 
So here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdfSo here is the code from the previous assignment that we need to ext.pdf
So here is the code from the previous assignment that we need to ext.pdf
 

Recently uploaded

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 

Recently uploaded (20)

Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 

So I need to create a compound word game, and I dont quite understa.pdf

  • 1. So I need to create a compound word game, and I don't quite understand how I can split up the compound words that are selected by the user on a frame into individual buttons where each button represents each letter, and the user can select which one starts the second word in a compound word otherwise gives a prompt indicating their wrong and should try again without having to make a class for each compound word I have. Below I have provided the array of words, and the word class needed after that will be the startLetter class, where the compound word is supposed to split into individual buttons. My whole goal is to fit it into one startLetter class without needing a class for each of the compound words, so in this case, five different classes I feel aren't necessary. The compoundWordProject 4 Class/ Main package compoundWordsProject4; import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; //Creates class compoundWords4, extends JFrame and implemetns an ActionListener public class compoundWords4 extends JFrame implements ActionListener { //Creates instances for the Words array static Word Words1 = new Word("SAND"); static Word Words2 = new Word("SANDWHICH", 5); static Word Words3 = new Word("BED"); static Word Words4 = new Word("BEDROOM", 4); static Word Words5 = new Word("CHESSECAKE", 7); static Word Words6 = new Word("CAKE");
  • 2. static Word Words7 = new Word("Apple"); static Word Words8 = new Word("FireHouse", 5); static Word Words9 = new Word("Base"); static Word Words10 = new Word("BaseBall", 5); static Word Words11 = new Word("Ball"); static Word Words12 = new Word("Bat"); // Creates an array for the word instances static Word[] Words = { Words1, Words2, Words3, Words4, Words5, Words6, Words7, Words8, Words9, Words10, Words11, Words12}; //Creates an empty array of buttons JButton[] buttons; //Creates a private variable for click private JLabel click; //Creates the constructor for compoundWords public compoundWords4() { setLayout(new FlowLayout()); //Sets the layout //Creates a label click = new JLabel("Click on a Compound Word:"); click.setFont(new Font("Arial", Font.BOLD, 25)); add(click); //Adds words from the string array into Jbuttons buttons = new JButton[Words.length]; //Creates all the buttons from array and adds actionListner for(int i = 0; i < buttons.length; i++) { buttons[i] = new JButton(Words[i].getWord()); buttons[i].addActionListener(this); add(buttons[i]); }
  • 3. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//Closes the program when the window is closed } public void actionPerformed(ActionEvent e) { //Creates action performed when buttons are clicked if(e.getSource() == buttons[0]) { JOptionPane.showMessageDialog(null, "This is not a compound Word", "Incorrect", JOptionPane.PLAIN_MESSAGE); }else if(e.getSource() == buttons[1]) { //Creates a window for startLetter if SandWhich is clicked startLetter frame2 = new startLetter(); frame2.setVisible(true); frame2.setSize(400,400); frame2.setLocation(400,200); frame2.setTitle("Starting Letter"); } public static void main (String args[]){ //Creates a window for difficulty difficulty frame7 = new difficulty(); frame7.setSize(400,400); frame7.setTitle("Compound Word Game"); frame7.setVisible(true); } } The Word class package compoundWordsProject4; //Creates the public class called "word" creates attributes called "word, index and isCompound" public class Word{ private String word; private int index; private boolean isCompound;
  • 4. //Creates attributes called "difficulty" and "topics" private int difficulty; private String[] topics; //Creates the constructor for the compound words public Word(String w, int i){ this.word = w; this.index = i; isCompound = true; } //Create the constructor for "word" public Word(String w){ this.word = w; isCompound = false; } //Creates a get method for difficulty public int getDifficulty() { return difficulty; } //Creates a set method for difficulty public void setDifficulty(int d) { this.difficulty = d; } //Creates a get method for topics public String[] getTopics() { return topics; } //Creates a set method for topics public void setTopics(String[] t) { this.topics = t; } //Creates a get method for "word" public String getWord(){ return word; } //Creates a set method for "word" public void setWord(String w){
  • 5. this.word = w; } //Creates a get method for "index" public int getIndex(){ return index; } //Creates a set method for "index" public void setIndex(int i){ this.index = i; } //Creates a boolean method for "isCompound" public boolean isCompound(){ return isCompound; } //Creates a set boolean method for "isCompound" public void setCompound(boolean isCompound){ this.isCompound = isCompound; } } The startLetter class package compoundWordsProject4; import java.awt.Container; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; public class startLetter extends JFrame implements ActionListener{ //Creates private variables private JButton S; private JButton A;
  • 6. private JButton N; private JButton D; private JButton W; private JButton H; private JButton I; private JButton C; private JButton H2; private JLabel click2; //Creates a constructor for startLetter public startLetter() { setLayout(new FlowLayout()); //Sets layout //Creates a label click2 = new JLabel("Click on the letter where the second compound word begins: "); click2.setFont(new Font("Arial", Font.BOLD, 13)); add(click2); //Creates a button for letter S S = new JButton("S"); S.addActionListener(this); add(S); //Creates a button for letter A A = new JButton("A"); A.addActionListener(this); add(A); //Creates a button for letter N N = new JButton("N"); N.addActionListener(this); add(N); //Creates a button for letter D D = new JButton("D"); D.addActionListener(this); add(D); //Creates a button for letter W
  • 7. W = new JButton("W"); W.addActionListener(this); add(W); //Creates a button for letter H H = new JButton("H"); H.addActionListener(this); add(H); //Creates a button for letter I I = new JButton("I"); I.addActionListener(this); add(I); //Creates a button for letter C C = new JButton("C"); C.addActionListener(this); add(C); //Creates a button for the second letter H H2 = new JButton("H"); H2.addActionListener(this); add(H2); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Stops program when window closes } public void actionPerformed(ActionEvent e) { //Creates action performed when the letters buttons are clicked if(e.getSource() == S) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect", JOptionPane.PLAIN_MESSAGE); } else if(e.getSource() == A) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect", JOptionPane.PLAIN_MESSAGE); } else if(e.getSource() == N) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect", JOptionPane.PLAIN_MESSAGE); } else if(e.getSource() == D) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect",
  • 8. JOptionPane.PLAIN_MESSAGE); //Congratulates the user and closes the program } else if(e.getSource() == W) { JOptionPane.showMessageDialog(null, "That is correct!!", "Correct", JOptionPane.PLAIN_MESSAGE); System.exit(0); } else if(e.getSource() == H) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect", JOptionPane.PLAIN_MESSAGE); } else if(e.getSource() == I) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect", JOptionPane.PLAIN_MESSAGE); } else if(e.getSource() == C) { JOptionPane.showMessageDialog(null, "It does not start here", "Incorrect", JOptionPane.PLAIN_MESSAGE); } else if(e.getSource() == H2) { JOptionPane.showMessageDialog(null, "This is not a compound Word", "Incorrect", JOptionPane.PLAIN_MESSAGE); } } }