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? - import java.awt.*;
-
import javax.swing.*;
-
import java.awt.event.*;
-
import java.util.*;
-
-
-
/**
-
* Class l0gixGame - write a description of the class here
-
*
-
* @author (your name)
-
* @version (a version number)
-
*/
-
public class logixGame2 extends JApplet {
-
JButton btn;
-
private static final ImageIcon image[]={
-
new ImageIcon("On.png"),
-
new ImageIcon("Off.png")};
-
ImageIcon on = new ImageIcon(getImage(getCodeBase(),
-
"On.png"));
-
-
ImageIcon off = new ImageIcon(getImage(getCodeBase(),
-
"Off.png"));
-
-
public void init(){
-
-
/** creates the control panel, sets the size,locaiton and the background
-
* colour
-
*/
-
JPanel controlPanel = new JPanel();
-
controlPanel.setSize(new Dimension(400,275));
-
controlPanel.setLocation(10,100);
-
controlPanel.setBackground(Color.gray);
-
-
/** creates the background panel, sets the size,locaiton and the
-
* background color
-
*/
-
JPanel backGround = new JPanel();
-
backGround.setSize(new Dimension(400,400));
-
backGround.setLocation(0,0);
-
backGround.setBackground(Color.gray);
-
-
/** creates the play panel, sets the size,locaiton and the
-
* background color
-
*/
-
JPanel playPanel = new JPanel();
-
playPanel.setSize(new Dimension(400,275));
-
playPanel.setLocation(500,200);
-
playPanel.setBackground(Color.orange);
-
-
/** creates the layout for the play panel, and the control panel
-
* creates the content pane, and the three panels to the content pane
-
* and sets the dimensions for the content pane
-
*/
-
controlPanel.setLayout(new GridLayout(8,12));
-
playPanel.setLayout(new GridLayout(8,12));
-
Container cp = getContentPane();
-
cp.setSize(new Dimension(5000,5000));
-
cp.add(controlPanel);
-
cp.add(playPanel);
-
cp.add(backGround);
-
-
/**initialize the onbutton and the offbutton with the related graphics*/
-
ImageIcon on = new ImageIcon(getImage(getCodeBase(),
-
"On.png"));
-
-
ImageIcon off = new ImageIcon(getImage(getCodeBase(),
-
"Off.png"));
-
-
ArrayList<String> control = new ArrayList<String>();
-
ArrayList<String> play = new ArrayList<String>();
-
-
/** Randimization of control panel and play panel*/
-
/**1=off 2=on*/
-
int row,column,i,x,y;
-
for( column = 0; column <= 8; column = column+1)
-
{
-
for (row = 0; row <= 14; row = row+1)
-
{
-
i = 1;
-
y = row * 50;
-
x = column * 50;
-
if ( (column % 2) == (row % 2) )
-
{
-
-
Random r = new Random();
-
int n = r.nextInt();
-
if(n % 2 == 0){
-
JLabel btn2 = new JLabel(off);
-
controlPanel.add(btn2);
-
control.add("1");
-
JButton btn = new JButton(on);
-
btn.setBackground(Color.orange);
-
playPanel.add(btn);
-
btn.addActionListener(new bob());
-
play.add("2");
-
-
-
-
}
-
else{
-
JLabel btn2 = new JLabel(on);
-
controlPanel.add(btn2);
-
control.add("2");
-
JButton btn = new JButton(off);
-
btn.setBackground(Color.orange);
-
playPanel.add(btn);
-
btn.addActionListener(new bob());
-
play.add("1");
-
}
-
-
}
-
else
-
{
-
Random r = new Random();
-
int n = r.nextInt();
-
if(n % 3 == 0){
-
JLabel btn2 = new JLabel(on);
-
controlPanel.add(btn2);
-
control.add("2");
-
JButton btn = new JButton(on);
-
btn.setBackground(Color.orange);
-
playPanel.add(btn);
-
btn.addActionListener(new bob());
-
play.add("2");
-
-
}
-
-
}
-
-
-
}
-
}
-
-
String controlString =""+ control;
-
String playString =""+ play;
-
-
if(controlString.compareTo(playString)==0){
-
JLabel winner = new JLabel("Winner!");
-
backGround.add(winner);
-
}
-
}
-
public class bob implements ActionListener{
-
public void actionPerformed (ActionEvent event){
-
if(btn.getIcon().equals(on))
-
{
-
btn.setIcon(off);
-
}
-
else
-
{
-
btn.setIcon(on);
-
-
}
-
}
-
}
-
-
}
0 1009 Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
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
| |
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...
| |