/* * MadLib.java 5/9/2020 * * name: Kenny Tran * prd: b5 * description: We are creating a miniature version of a MadLib with the use of GUI_Custom * * I received help from... Mrs. Garcia */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Main implements ActionListener { //**custimize the game JFrame wml = new JFrame("Wee MadLib"); //titling the frame JPanel gameboard = new JPanel(new GridLayout(16,3)); //3 rows 3 columns JLabel subjectLabel = new JLabel("Subject"); //creating a label named subject JLabel verbLabel = new JLabel("Verb ending with ing"); // creating a label named verb JLabel objLabel = new JLabel("Object"); //creating a label name object JLabel sent = new JLabel("The man is "); //creating a label that a start a sentence JLabel sent2 = new JLabel("He gains some "); JTextField verb = new JTextField(25); //a textfield to input a verb JLabel verbLabel2 = new JLabel("Measurement"); JLabel subjectLabel2 = new JLabel("Subject"); //creating a label named subject JLabel placehold2 = new JLabel(" "); JLabel placeholda = new JLabel(" "); JLabel placeholdb = new JLabel(" "); JLabel subjectLabel3 = new JLabel("Subject"); //creating a label named subject JLabel verbLabel3 = new JLabel("Workout"); JLabel placehold3 = new JLabel("workout Verb with ING "); String[] objOptions = {" KFC. ", " Golden Chick. ", " Church's Chicken. ", " Popeyes. "}; JComboBox options = new JComboBox(objOptions); //a drop-down list with the options listed String[] objMeasurements = {" pounds", " stones", " kilograms", " newtons"}; JComboBox Measurements = new JComboBox(objMeasurements); //a drop-down list with the options listed JLabel placehold = new JLabel(" "); JLabel sent3 = new JLabel("The man "); String[] objwork = {" excercises by ", " works out by ", " hits the gym and starts ", " starts training and starts "}; JComboBox workout = new JComboBox(objwork); //a drop-down list with the options listed JTextField working = new JTextField(25); JLabel sent4 = new JLabel ("He loses some pounds but is still"); JTextField meanWord = new JTextField(25); JLabel placehold4 = new JLabel(" "); JLabel sent5 = new JLabel ("The man eats a "); JTextField food = new JTextField(25); JLabel subjectLabel5 = new JLabel("Subject"); JLabel fatfood = new JLabel("Food"); JLabel placehold5 = new JLabel(" "); JLabel placehold6 = new JLabel(" "); JLabel placehold8 = new JLabel(" "); JLabel placehold9 = new JLabel(" "); JLabel subjectLabel6 = new JLabel("Subject"); JLabel procedure = new JLabel("Procedure"); JLabel placehold7 = new JLabel(" "); JLabel sent6 = new JLabel ("The man decides to get the "); String[] objsurgeory = {" Liposuction ", " Gastric bypass ", " tummy tuck ", " CoolSculpting "}; JComboBox surgeory = new JComboBox(objsurgeory); //a drop-down list with the options listed JLabel subjectLabel4 = new JLabel("Subject"); JLabel meanName = new JLabel("Negative Adjective"); JLabel subjectLabel7 = new JLabel("Subject"); JLabel verblast = new JLabel (" Fake Promsie "); JLabel sent7 = new JLabel ("The man vows to "); String[] objstop = {" limit ", " control ", " restrict ", " ceil "}; JComboBox stop = new JComboBox(objstop); //a drop-down list with the options listed JButton Finished = new JButton("Finished"); JButton clear = new JButton("Clear"); //a button named clear JButton exit = new JButton("EXIT NOW!!"); // a button named EXIT NOW //**putting it all together on a gameboard public Main() //constructor .. has the same name as the class { // working on the frame wml.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); wml.setSize(300,300); //adding properties to your JLabel named subjectLabel subjectLabel.setOpaque(true); //allow color subjectLabel.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel.setHorizontalAlignment(JLabel.CENTER); //aligning to the center subjectLabel2.setOpaque(true); //allow color subjectLabel2.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel2.setHorizontalAlignment(JLabel.CENTER); //aligning to the center verbLabel2.setOpaque(true); //allow color verbLabel2.setBackground(new Color(0,255,0)); verbLabel2.setHorizontalAlignment(JLabel.CENTER); verbLabel3.setOpaque(true); //allow color verbLabel3.setBackground(new Color(0,255,0)); verbLabel3.setHorizontalAlignment(JLabel.CENTER); subjectLabel3.setOpaque(true); //allow color subjectLabel3.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel3.setHorizontalAlignment(JLabel.CENTER); //aligning to the center subjectLabel4.setOpaque(true); //allow color subjectLabel4.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel4.setHorizontalAlignment(JLabel.CENTER); //aligning to the center subjectLabel5.setOpaque(true); subjectLabel5.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel5.setHorizontalAlignment(JLabel.CENTER); //aligning to the center fatfood.setOpaque(true); fatfood.setBackground(new Color(0,255,0)); //adding the color in RGB format fatfood.setHorizontalAlignment(JLabel.CENTER); //aligning to the center meanName.setOpaque(true); //allow color meanName.setBackground(new Color(0,255,0)); //adding the color in RGB format meanName.setHorizontalAlignment(JLabel.CENTER); //aligning to the center subjectLabel6.setOpaque(true); subjectLabel6.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel6.setHorizontalAlignment(JLabel.CENTER); //aligning to the center subjectLabel7.setOpaque(true); subjectLabel7.setBackground(new Color(0,255,255)); //adding the color in RGB format subjectLabel7.setHorizontalAlignment(JLabel.CENTER); //aligning to the center verblast.setOpaque(true); verblast.setBackground(new Color(0,255,0)); //adding the color in RGB format verblast.setHorizontalAlignment(JLabel.CENTER); //aligning to the center procedure.setOpaque(true); procedure.setBackground(new Color(0,255,0)); //adding the color in RGB format procedure.setHorizontalAlignment(JLabel.CENTER); //aligning to the center //adding properties to your textarea named sentence //adding properties to your buttons,JTextField, JComboBox clear.addActionListener(this); //allowing it to hear a command verb.addActionListener(this); exit.addActionListener(this); options.addActionListener(this); working.addActionListener(this); Finished.addActionListener(this); //creating your masterpiece on the canvas named:gameboard gameboard.add(subjectLabel); //row 1 column1 gameboard.add(verbLabel); gameboard.add(objLabel); gameboard.add(sent); //row 2 column1 gameboard.add(verb); gameboard.add(options); gameboard.add(subjectLabel2); gameboard.add(verbLabel2); gameboard.add(placehold2); gameboard.add(sent2); gameboard.add(Measurements); gameboard.add(placehold); gameboard.add(subjectLabel3); gameboard.add(verbLabel3); gameboard.add(placehold3); gameboard.add(sent3); gameboard.add(workout); gameboard.add(working); gameboard.add(subjectLabel4); gameboard.add(meanName); gameboard.add(placeholda); gameboard.add(sent4); gameboard.add(meanWord); gameboard.add(placehold4); gameboard.add(subjectLabel5); gameboard.add(fatfood); gameboard.add(placehold5); gameboard.add(sent5); gameboard.add(food); gameboard.add(placehold6); gameboard.add(subjectLabel6); gameboard.add(procedure); gameboard.add(placehold7); gameboard.add(sent6); gameboard.add(surgeory); gameboard.add(placehold8); gameboard.add(subjectLabel7); gameboard.add(verblast); gameboard.add(placehold9); gameboard.add(sent7); gameboard.add(stop); gameboard.add(placeholdb); gameboard.add(clear); //row 3 column 1 gameboard.add(Finished); gameboard.add(exit); //framing my canvas wml.setContentPane(gameboard); wml.setVisible(true); wml.pack(); } //allow actions to take place public void actionPerformed(ActionEvent e) { if(e.getSource() == Finished) { JOptionPane.showMessageDialog(null," The man is " + verb.getText() + options.getSelectedItem() + "He gains some" + Measurements.getSelectedItem() + "." + " The man" + workout.getSelectedItem() + working.getText() + ". " + "\nHe loses some" + Measurements.getSelectedItem()+ " but is still " + meanWord.getText() + ". " + "The man eats a " + food.getText() + ". He gains more" + Measurements.getSelectedItem() + ". " + "\nThe man gets the" + surgeory.getSelectedItem()+"procedure. "+ "The man vows to" + stop.getSelectedItem() +"his eating. " + "\nHowever, the man cannot control his urges. He eats meals like it " + "is a buffet. \nThe man dies from overeating.", "A fat Death", JOptionPane.PLAIN_MESSAGE); } else if (e.getSource() == clear) { verb.setText(""); //resetting "sentence" meanWord.setText(""); //resetting "sentence" working.setText(""); //resetting "sentence" food.setText(""); //resetting "sentence" } else if (e.getSource() == exit) { wml.dispose(); //closes/discards the frame/panel } } public static void main(String[] arg) { new Main(); } }