473,549 Members | 2,948 Online
Bytes | Software Development & Data Engineering Community
+ 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 1009

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

Similar topics

2
1404
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, so this is just a snippet. If there are blank entries, the script is to change the appropriate images to warning icons. Unfortunately it aways...
2
2016
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 stick together. What I want to do is type information on these tags rather than write on them, the only problem that I am having is that there is NO...
3
1989
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 of the student like stid, last name, first name, and a subform in the same form with the courses that the student enrolled. I have a click button in...
36
1760
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 "(?<sentence>.*(?<eos>{1}$)?)" Say I have the phrase 'My Taylor is /' as input; I'd like 'sentence' and 'eos' to match. Now if I have 'My Taylor is //' or 'My...
53
4627
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, and .Net2005 code. I'm developing in vb.net 2005. This test sub just reads an input text file, writing out records to another text file, eliminating...
15
2560
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 determine who needs to receive the text message then send the message to the address. Only problem is, the employee may receive up to 4 of the...
1
1645
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 networking. The object is to bring them on board and train in SAN/NAS switching, as long as they are solid C, Unix and Embedded programmers that have...
1
2489
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 is running asp.net 1.0 ...i tried to use the cmd aspnet_regiis.exe -i n didnt work ...please anyone help me asap ...im new to development n started...
5
2196
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 the following project: take a DICOM medical image viewer from our existing code base, which is written in C# with some C++ from toolkits, and expand...
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6041
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1936
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 we have to send another system
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.