Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-29-2007, 04:42 AM
Member
 
Join Date: Nov 2007
Posts: 4
rnavarro9 is on a distinguished road
Linked List
So I'm creating a SimonSays game. I'm now trying to add the action listener to the Start Button, but I'm not to sure how to tie all that to Linked Lists. Can someone help?

This is the SimonSaysFrame:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

public class SimonSaysFrame extends JFrame {

/**
* This class represents a listener for when a Game Button is pushed
*
*/
class GameButtonListener implements ActionListener, Runnable {

/**
* This function handles the event for when the game button is pushed
* @param event The ActionEvent corresponding to the event that happened
*/
public void actionPerformed(ActionEvent event) {
// if the user matches the enter sequence pushed by Simon,
// then create a new sequence. The new sequence is done
// by starting a new thread, which will call the run()
// function below. Make sure you use the code below.

// if ( user matches entire sequence pushed by Simon ) {
// Thread runStart = new Thread(this);
// runStart.start();
// }
}

/**
* This event runs the thread
*/
public void run() {
try {
Thread.sleep(300);
// Create Simon's sequence here (this happens after the user completely matches Simon's sequence and a new round starts)
} catch (InterruptedException e) {
System.out.println(e.getMessage());
e.printStackTrace();
System.exit(-1);
}
}
}

/**
* This class implements a listener for the Start button
*
*/
class StartButtonListener implements ActionListener, Runnable {

/**
* This function handles the event for when the start button is clicked
* @param event The ActionEvent corresponding to the event that happened
*/
public void actionPerformed(ActionEvent event) {
Thread runStart = new Thread(this);
runStart.start();
}

/**
* This event runs the thread
*/
public void run() {


// Create Simon's sequence here (this is for the first time you hit the Start button)



}
}


/**
* This is the default constructor for a SimonSaysFrame.
*
*/
public SimonSaysFrame() {
//constructor
}

// You will need to create your own main function either in this class
// or in a launcher class
}


GUI:

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
<Roberto Navarro> <10/12/07>
<This class is the GUI which the user will interact with; it will contain the next and previous buttons
which will allow the user to surf through the inventory>
*/

public class SimonSaysPanel extends SimonSaysFrame {


public static void main(String [] args){
//The frame will contain buttons and panels;
JFrame frame = new JFrame("Simon Says");

//Create start button which will begin the sequence
JButton button = new JButton("START");
JPanel buttonPanel = new JPanel();



// Adds the start button to the panel
buttonPanel.setPreferredSize(new Dimension(200,40));
buttonPanel.add(button);

/*
* Created a 2x2 grid which will contain the colored buttons
*/
JPanel squarePanel = new JPanel(new GridLayout(2,2));
JButton redSquare, blueSquare, greenSquare, yellowSquare;
redSquare = new JButton("Red");
blueSquare = new JButton("Blue");
greenSquare = new JButton("Green");
yellowSquare = new JButton("Yellow");

/*
* This piece of code colors each button with its corresponding color
*/
redSquare.setBackground(Color.RED);
blueSquare.setBackground(Color.BLUE);
greenSquare.setBackground(Color.GREEN);
yellowSquare.setBackground(Color.YELLOW);

/*
* This section adds the buttons created to the panel
*/
squarePanel.add(redSquare);
squarePanel.add(yellowSquare);
squarePanel.add(blueSquare);
squarePanel.add(greenSquare);

squarePanel.setPreferredSize(new Dimension(200,200));

//Set the frame's visibility to true and align the panels within the frame
frame.add(buttonPanel, BorderLayout.SOUTH);
frame.add(squarePanel, BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setVisible(true);










}

}

Any thoughts will help. Thanks.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Circular Double Linked List theonly Advanced Java 1 04-04-2008 08:18 AM
Linked List help neobie New To Java 8 12-22-2007 04:15 AM
linked list nodes all refernce same item. yllawwally New To Java 0 12-18-2007 09:45 PM
going from vectors to linked list? cbrown08 New To Java 3 12-01-2007 01:55 AM
Help with linked list trill New To Java 1 08-07-2007 08:29 AM


All times are GMT +3. The time now is 05:36 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org