Expand|Select|Wrap|Line Numbers
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.GridLayout;
- import java.awt.Window;
- import java.util.Random;
- import java.awt.CardLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class MAINFRAMES extends JFrame {
- String[] adulteasy =
- {
- "What’s full of holes but still holds water?",
- //Sponge
- "What is the best month for a parade?",
- //March
- "Pronounced as one letter, And written with three, Two letters there are, And two only in me. I'm double, I'm single, I'm black, blue, and gray, I'm read from both ends, And the same either way.",
- //An Eye
- "What two words have thousands of letters in them?", "At night they come without being fetched. By day they are lost without being stolen. What are they?",
- //Post Office
- "When one does not know what it is, then it is something; but when one knows what it is, then it is nothing.",
- //A Riddle
- "It cannot be seen, cannot be felt, Cannot be heard, and cannot be smelt. It lies behind stars and under hills, And empty holes it fills. It comes first and follows after, Ends life, kills laughter.",
- //Dark
- "A box without hinges, key or lid, Yet golden treasure inside is hid.",
- //Egg
- "What goes up the chimney when down, but can't go down the chimney when up?",
- //Umbrella
- "Each morning I appear, To lie at your feet All day, I will follow you, No matter how fast you run, Yet I nearly perish In the midday sun."
- //Shadow
- };
- int length = adulteasy.length;
- int rand = (int) (Math.random() * length);
- int length1 = adulteasy.length;
- int rand1 = (int) (Math.random() * length);
- int length2 = adulteasy.length;
- int rand2 = (int) (Math.random() * length);
- int length3 = adulteasy.length;
- int rand3 = (int) (Math.random() * length);
- int length4 = adulteasy.length;
- int rand4 = (int) (Math.random() * length);
- int length5 = adulteasy.length;
- int rand5 = (int) (Math.random() * length);
- int length6 = adulteasy.length;
- int rand6 = (int) (Math.random() * length);
- int length7 = adulteasy.length;
- int rand7 = (int) (Math.random() * length);
- int length8 = adulteasy.length;
- int rand8 = (int) (Math.random() * length);
- int length9 = adulteasy.length;
- int rand9 = (int) (Math.random() * length);
- private int currentCard = 1;
- private JPanel cardPanel;
- private CardLayout cl;
- public MAINFRAMES() {
- setTitle("The Riddle Republic");
- setSize(500, 600);
- cardPanel = new JPanel();
- cardPanel.setLayout(null);
- // getContentPane().add(cardPanel);
- cl = new CardLayout();
- cardPanel.setLayout(cl);
- JPanel q1 = new JPanel(new GridLayout(1, 0, 0, 0));
- JPanel q2 = new JPanel ();
- JPanel q3 = new JPanel ();
- JPanel q4 = new JPanel ();
- JPanel q5 = new JPanel ();
- JPanel q6 = new JPanel ();
- JPanel q7 = new JPanel ();
- JPanel q8 = new JPanel ();
- JPanel q9 = new JPanel ();
- JPanel q10 = new JPanel ();
- JLabel qq1 = new JLabel (adulteasy[rand], SwingConstants.CENTER);
- qq1.setHorizontalAlignment(SwingConstants.CENTER);
- qq1.setVerticalAlignment(SwingConstants.CENTER);
- JLabel qq2 = new JLabel (adulteasy[rand1]);
- qq2.setLocation(500, 500);
- JLabel qq3 = new JLabel (adulteasy[rand2]);
- qq3.setLocation(450, 200);
- JLabel qq4 = new JLabel (adulteasy[rand3]);
- qq4.setLocation(450, 200);
- JLabel qq5 = new JLabel (adulteasy[rand4]);
- qq5.setLocation(450, 200);
- JLabel qq6 = new JLabel (adulteasy[rand5]);
- qq6.setLocation(450, 200);
- JLabel qq7 = new JLabel (adulteasy[rand6]);
- qq7.setLocation(450, 200);
- JLabel qq8 = new JLabel (adulteasy[rand7]);
- qq8.setLocation(450, 200);
- JLabel qq9 = new JLabel (adulteasy[rand8]);
- qq9.setLocation(450, 200);
- JLabel qq10 = new JLabel(adulteasy[rand9]);
- qq10.setLocation(450, 200);
- q1.add (qq1);
- q2.add (qq2);
- q3.add (qq3);
- q4.add (qq4);
- q5.add (qq5);
- q6.add (qq6);
- q7.add (qq7);
- q8.add (qq8);
- q9.add (qq9);
- q10.add (qq10);
- cardPanel.add(q1, "1");
- cardPanel.setBounds (300,300,180, 80);
- cardPanel.add(q2, "2");
- cardPanel.add(q3, "3");
- cardPanel.add(q4, "4");
- cardPanel.add(q5, "5");
- cardPanel.add(q6, "6");
- cardPanel.add(q7, "7");
- cardPanel.add(q8, "8");
- cardPanel.add(q9, "9");
- cardPanel.add(q10, "10");
- JPanel buttonPanel = new JPanel();
- JButton firstBtn = new JButton("First");
- JButton nextBtn = new JButton("Next");
- JButton previousBtn = new JButton("Previous");
- JButton lastBtn = new JButton("Last");
- buttonPanel.add(firstBtn);
- buttonPanel.add(nextBtn);
- buttonPanel.add(previousBtn);
- buttonPanel.add(lastBtn);
- firstBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- cl.first(cardPanel);
- currentCard = 1
- ;
- }
- });
- lastBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- cl.last(cardPanel);
- currentCard = 10;
- }
- });
- nextBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if (currentCard < 10) {
- currentCard += 1;
- cl.show(cardPanel, "" + (currentCard));
- }
- }
- });
- previousBtn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- if (currentCard > 1) {
- currentCard -= 1;
- cl.show(cardPanel, "" + (currentCard));
- }
- }
- });
- getContentPane().add(cardPanel, BorderLayout.NORTH);
- getContentPane().add(buttonPanel, BorderLayout.SOUTH);
- }
- public static void main(String[] args) {
- MAINFRAMES cl = new MAINFRAMES();
- cl.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- cl.setVisible(true);
- }
- }