Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Janty Kojakali
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class MadLibs extends JApplet implements ActionListener
- {
- JTextArea area1;
- JPanel panel1;
- JPanel panel2;
- JPanel panel3;
- JButton button1;
- JRadioButton radio1;
- JRadioButton radio2;
- JRadioButton radio3;
- JRadioButton radio4;
- JRadioButton radio5;
- JRadioButton radio6;
- JTextField field1;
- JTextField field2;
- JTextField field3;
- JTextField field4;
- JTextField field5;
- JTextField field6;
- JTextField field7;
- JTextField field8;
- JTextField field9;
- JTextField field10;
- ButtonGroup group1;
- ButtonGroup group2;
- ButtonGroup group3;
- Font font;
- String a,b,c,d,f,g,h,i,j,x,k;
- int l,m;
- public void init()
- {
- Container cp;
- cp = getContentPane();
- cp.setLayout(new GridLayout(2,1));
- field1 = new JTextField("Enter a number");
- field2 = new JTextField("Enter an adjective");
- field3 = new JTextField("Enter an adjective");
- field4 = new JTextField("Enter a noun");
- field5 = new JTextField("Enter an adverb");
- field6 = new JTextField("Enter a noun");
- field7 = new JTextField("Enter a plural noun");
- field8 = new JTextField("Enter an adjective");
- field9 = new JTextField("Enter a noun");
- field10 = new JTextField("Enter a noun");
- radio1 = new JRadioButton("Arial");
- radio2 = new JRadioButton("TimesNewRoman");
- radio3 = new JRadioButton("12");
- radio4 = new JRadioButton("14");
- radio5 = new JRadioButton("Bold");
- radio6 = new JRadioButton("Italic");
- ButtonGroup group1 = new ButtonGroup();
- ButtonGroup group2 = new ButtonGroup();
- ButtonGroup group3 = new ButtonGroup();
- button1 = new JButton("Submit");
- area1 = new JTextArea(20,100);
- panel1 = new JPanel();
- panel2 = new JPanel();
- panel3 = new JPanel();
- cp.add(panel1);
- cp.add(panel2);
- cp.add(panel3);
- panel1.add(button1);
- group1.add(radio1);
- group1.add(radio2);
- group2.add(radio3);
- group2.add(radio4);
- group3.add(radio5);
- group3.add(radio6);
- panel1.add(field1);
- panel1.add(field2);
- panel1.add(field3);
- panel1.add(field4);
- panel1.add(field5);
- panel1.add(field6);
- panel1.add(field7);
- panel1.add(field8);
- panel1.add(field9);
- panel1.add(field10);
- panel2.add(radio1);
- panel2.add(radio2);
- panel2.add(radio3);
- panel2.add(radio4);
- panel2.add(radio5);
- panel2.add(radio6);
- panel3.add(area1);
- setLayout(new FlowLayout());
- panel1.setLayout(new FlowLayout());
- panel2.setLayout(new FlowLayout());
- panel3.setLayout(new FlowLayout());
- button1.addActionListener(this);
- field1.addActionListener(this);
- field2.addActionListener(this);
- field3.addActionListener(this);
- field4.addActionListener(this);
- field5.addActionListener(this);
- field6.addActionListener(this);
- field7.addActionListener(this);
- field8.addActionListener(this);
- field9.addActionListener(this);
- field10.addActionListener(this);
- radio1.addActionListener(this);
- radio2.addActionListener(this);
- radio3.addActionListener(this);
- radio4.addActionListener(this);
- radio5.addActionListener(this);
- radio6.addActionListener(this);
- }
- public void actionPerformed (ActionEvent e)
- {
- if (e.getSource() == button1)
- {
- a = field1.getText();
- b = field2.getText();
- c = field3.getText();
- d = field4.getText();
- x = field5.getText();
- f = field6.getText();
- g = field7.getText();
- h = field8.getText();
- i = field9.getText();
- j = field10.getText();
- if(radio1.isSelected())
- {
- k = "Arial";
- }
- if(radio2.isSelected())
- {
- k = "Times New Roman";
- }
- if(radio3.isSelected())
- {
- m = 12;
- }
- if(radio4.isSelected())
- {
- m = 14;
- }
- if(radio5.isSelected())
- {
- l = Font.BOLD;
- }
- if(radio6.isSelected())
- {
- l = Font.ITALIC;
- }
- Font font = new Font(k, l, m);
- area1.setFont(font);
- area1.setText("There was a boy who was " + a + " years old. He wanted to prove himself so he set out on a journey. During his journey he ran into a " + b + "," + c + " " + d + ". Prepared for a situation like this, he " + x + " pull out his " + f + ". After defeating the " + d + " , he gets hungry so he eats " + g + " with some ketchup. After eating he got thirsty so he drank some " + h + "," + i + " with his " + j + ".He then dies of food poisoning. THE END!!" );
- area1.setLineWrap(true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment