473,468 Members | 1,475 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

alot of help needed....asap....anyone interested?

1 New Member
Hi,

I don't even know if this is the right place to post this but i will, because I need help. I'm trying to finish this basic game. but I am having troubles. If anyone wants to help me out it would be great. I will admit this might take a long time, i am new to java and i suck at it(yes i will also admit that). by anyones standards this program probably really sucks, but its the best that i can do.

my objectives:
- when a button is pressed down, switch it to the opposite button ( on goes to off, off goes to on) but at the same time, switch the buttons that are left, right, up and down from it.
Before:

http://i15.photobucket.com/albums/a385/t_dimock/Picture3-2.png
After:

http://i15.photobucket.com/albums/a385/t_dimock/Picture2-9.png

graphics

http://i15.photobucket.com/albums/a385/t_dimock/On.png

http://i15.photobucket.com/albums/a385/t_dimock/Off.png
Anyone have any ideas?
Expand|Select|Wrap|Line Numbers
  1. import java.awt.*;
  2. import javax.swing.*;
  3. import java.awt.event.*;
  4. import java.util.*;
  5.  
  6.  
  7. /**
  8.  * Class l0gixGame - write a description of the class here
  9.  * 
  10.  * @author (your name) 
  11.  * @version (a version number)
  12.  */
  13. public class logixGame2 extends JApplet {
  14.     JButton btn;
  15.     private static final ImageIcon image[]={
  16.         new ImageIcon("On.png"),
  17.         new ImageIcon("Off.png")};
  18.    ImageIcon on = new ImageIcon(getImage(getCodeBase(),
  19.        "On.png"));
  20.  
  21.    ImageIcon off = new ImageIcon(getImage(getCodeBase(),
  22.        "Off.png"));
  23.  
  24.    public void init(){
  25.  
  26.        /** creates the control panel, sets the size,locaiton and the background
  27.         * colour
  28.         */
  29.        JPanel controlPanel = new JPanel();
  30.        controlPanel.setSize(new Dimension(400,275));
  31.        controlPanel.setLocation(10,100);
  32.        controlPanel.setBackground(Color.gray);
  33.  
  34.        /** creates the background panel, sets the size,locaiton and the
  35.        * background color
  36.        */
  37.        JPanel backGround = new JPanel();
  38.        backGround.setSize(new Dimension(400,400));
  39.        backGround.setLocation(0,0);
  40.        backGround.setBackground(Color.gray);
  41.  
  42.        /** creates the play panel, sets the size,locaiton and the
  43.        * background color
  44.        */
  45.        JPanel playPanel = new JPanel();
  46.        playPanel.setSize(new Dimension(400,275));
  47.        playPanel.setLocation(500,200);
  48.        playPanel.setBackground(Color.orange);
  49.  
  50.        /** creates the layout for the play panel, and the control panel
  51.         * creates the content pane, and the three panels to the content pane
  52.         * and sets the dimensions for the content pane
  53.         */
  54.        controlPanel.setLayout(new GridLayout(8,12));
  55.        playPanel.setLayout(new GridLayout(8,12));
  56.        Container cp = getContentPane();
  57.        cp.setSize(new Dimension(5000,5000));
  58.        cp.add(controlPanel);
  59.        cp.add(playPanel);
  60.        cp.add(backGround);
  61.  
  62.        /**initialize the onbutton and the offbutton with the related graphics*/
  63.        ImageIcon on = new ImageIcon(getImage(getCodeBase(),
  64.        "On.png"));
  65.  
  66.        ImageIcon off = new ImageIcon(getImage(getCodeBase(),
  67.        "Off.png"));
  68.  
  69.        ArrayList<String> control = new ArrayList<String>();
  70.        ArrayList<String> play = new ArrayList<String>();
  71.  
  72.        /** Randimization of control panel and play panel*/
  73.        /**1=off 2=on*/
  74.        int row,column,i,x,y;
  75.          for( column = 0; column <= 8; column = column+1)
  76.          {
  77.                 for (row = 0; row <= 14; row = row+1)
  78.                 {
  79.                     i = 1;
  80.                     y = row * 50;
  81.                     x = column * 50;
  82.                     if ( (column % 2) == (row % 2) )
  83.                     {
  84.  
  85.                         Random r = new Random();
  86.                         int n = r.nextInt();
  87.                         if(n % 2 == 0){
  88.                              JLabel btn2 = new JLabel(off);
  89.                             controlPanel.add(btn2);
  90.                             control.add("1");
  91.                             JButton btn = new JButton(on);
  92.                             btn.setBackground(Color.orange);
  93.                             playPanel.add(btn);
  94.                             btn.addActionListener(new bob());
  95.                             play.add("2");
  96.  
  97.  
  98.  
  99.                         }
  100.                         else{
  101.                             JLabel btn2 = new JLabel(on);
  102.                             controlPanel.add(btn2);
  103.                             control.add("2");
  104.                             JButton btn = new JButton(off);
  105.                             btn.setBackground(Color.orange);
  106.                             playPanel.add(btn);
  107.                             btn.addActionListener(new bob());
  108.                             play.add("1");
  109.                         }
  110.  
  111.                     }
  112.                     else
  113.                     {
  114.                         Random r = new Random();
  115.                         int n = r.nextInt();
  116.                         if(n % 3 == 0){
  117.                             JLabel btn2 = new JLabel(on);
  118.                             controlPanel.add(btn2);
  119.                             control.add("2");
  120.                             JButton btn = new JButton(on);
  121.                             btn.setBackground(Color.orange);
  122.                             playPanel.add(btn);
  123.                             btn.addActionListener(new bob());
  124.                             play.add("2");
  125.  
  126.                     }
  127.  
  128.                     }
  129.  
  130.  
  131.                 }
  132.             }
  133.  
  134.             String controlString =""+ control;
  135.             String playString =""+ play;
  136.  
  137.             if(controlString.compareTo(playString)==0){
  138.                 JLabel winner = new JLabel("Winner!");
  139.                 backGround.add(winner);
  140.             }
  141.         }
  142. public class bob implements ActionListener{
  143.     public void actionPerformed (ActionEvent event){
  144.         if(btn.getIcon().equals(on))
  145.         {
  146.             btn.setIcon(off);
  147.         }
  148.         else
  149.         {
  150.             btn.setIcon(on);
  151.  
  152.         }
  153. }
  154. }
  155.  
  156. }
Dec 8 '07 #1
0 1002

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: SC | last post by:
I'm having a problem getting this validation script to work. There are two images on the page with the ids of img_antirobot and img_chk_agree. In the final page it will validate about 12 entries,...
2
by: ratedr1 | last post by:
I am currently trying to label rings (jewelry). They make specialized tags (shaped like a butterfly, barbell, dumbell, etc) for this purpose, the label goes through the ring, and then the ends...
3
by: srani | last post by:
Hello Everyone, I am in a need of some one who can help me with the database iam building. I have student enrollment to distance program database with the first form having the general info...
36
by: Jules | last post by:
All, how do I describe a string consisting of any number of characters, with an optional (but unique when occuring) end-of-line expression '/'? With groups if possible, as in...
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
1
by: leeanngriego | last post by:
I have a client who has asked me to find him some solid up and coming embedded engineers. 2 to 3 years expereince with Embedded Linux, VxWorks, Nucleus or any other RTOS who has working in L2/L3...
1
by: Miss Hyder | last post by:
hi everyone i really need help ...i bought a laptop with windows vista already installed now i hv installed vs.net 2003 n when i want to create asp web app/service it gives error that web server...
5
by: byrnes | last post by:
We are looking to immediately recruit programmers for a project; we are interested in obtaining proposals ASAP. Will offer favorable compensation. We need immediately, an individual to complete...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.