hey Im trying to make a game of pairs (the memory game) i have set up a grid which displays a graphic for the card back. im trying to link the edit menu to choose the graphic to be displayed. i've set up a string variable called deck which will contain the path to the required image. and actionlisteners DA and DB corresponding to which style is choosen in the menu. I had to declare the deck to some initial image so it can load.
How do i impliment the change once the menuitem has been selected?
below is my code so far. -
-
import javax.swing.*;
-
-
import java.awt.*;
-
-
import java.awt.event.*;
-
-
import javax.swing.event.*;
-
-
import java.net.*;
-
-
-
-
class Filenew extends JFrame implements ActionListener
-
-
{
-
-
JMenuItem Exit, DA, DB, About, Instructions;
-
-
Filenew gameFrame = null;
-
-
String deck = "images/aqua.jpg";
-
JPanel[][] q;
-
-
public static void main (String[] args)
-
-
{
-
-
Filenew frame = new Filenew();
-
-
frame.display();
-
-
}
-
-
public Filenew()
-
{
-
this(2, 2);
-
}
-
-
public Filenew(int x, int y)
-
-
{
-
setBackground(Color.red);
-
-
JMenuBar menubar = new JMenuBar();
-
-
setJMenuBar(menubar);
-
-
JMenu filemenu = new JMenu("File");
-
-
menubar.add(filemenu);
-
-
JMenu New = new JMenu("New");
-
JMenuItem New43 = new JMenuItem("4x3");
-
New.add(New43);
-
JMenuItem New44 = new JMenuItem("4x4");
-
New.add(New44);
-
JMenuItem New54 = new JMenuItem("5x4");
-
New.add(New54);
-
-
Exit = new JMenuItem("Exit");
-
-
filemenu.add(New);
-
-
filemenu.add(Exit);
-
-
JMenu editmenu = new JMenu("Edit");
-
-
menubar.add(editmenu);
-
JMenuItem ChangeD = new JMenu("Change Deck");
-
editmenu.add(ChangeD);
-
JMenuItem DA = new JMenuItem("Style 1");
-
ChangeD.add(DA);
-
JMenuItem DB = new JMenuItem("Style 2");
-
ChangeD.add(DB);
-
JMenuItem ChangeB = new JMenu("Change Background");
-
editmenu.add(ChangeB);
-
JMenuItem BA = new JMenuItem("Style 1");
-
ChangeB.add(BA);
-
JMenuItem BB = new JMenuItem("Style 2");
-
ChangeB.add(BB);
-
-
-
-
New43.setActionCommand("43");
-
New44.setActionCommand("44");
-
New54.setActionCommand("54");
-
Exit.setActionCommand("Exit");
-
DA.setActionCommand("DA");
-
DB.setActionCommand("DB");
-
-
New43.addActionListener(this);
-
New44.addActionListener(this);
-
New54.addActionListener(this);
-
-
Exit.addActionListener(this);
-
DA.addActionListener(this);
-
-
DB.addActionListener(this);
-
-
-
-
-
getContentPane().setLayout(new GridLayout(x,y));
-
-
q = new JPanel[x][y];
-
-
for (int i=0; i<x; i++)
-
-
{
-
-
for (int j=0; j<y; j++)
-
-
{
-
-
q[i][j] = new JPanel();
-
-
getContentPane().add(q[i][j]);
-
URL address = myscene.class.getResource(deck);
-
-
ImageIcon image = new ImageIcon(address);
-
-
JLabel cardback = new JLabel(image);
-
-
q[i][j].add(cardback);
-
-
}
-
-
}
-
-
}
-
-
-
-
void display()
-
-
{
-
-
setTitle("The World's Most Amazing Game of Pairs to Ever Have Existed");
-
-
setDefaultCloseOperation(EXIT_ON_CLOSE);
-
-
setVisible(true);
-
setSize(600,400);
-
-
setMinimumSize(new Dimension (600,400));
-
-
-
}
-
-
-
-
protected void Exit()
-
-
{
-
-
System.exit(0);
-
-
}
-
-
-
-
public void actionPerformed(ActionEvent event)
-
{
-
String source = event.getActionCommand();
-
-
if(source.equals ("43"))
-
{
-
newGame(3, 4);
-
}
-
if(source.equals("44"))
-
{
-
newGame(4, 4);
-
}
-
if(source.equals("54"))
-
{
-
newGame(4, 5);
-
}
-
if(source.equals("Exit"))
-
-
{
-
-
Exit();
-
-
}
-
if(source.equals("DA"))
-
{
-
deck = "images/pairs.jpg";
-
-
}
-
if(source.equals("DB"))
-
{
-
deck = "images/carddeck.jpeg";
-
}
-
-
-
-
-
-
}
-
public void newGame(int x, int y)
-
{
-
closeGame();
-
gameFrame = new Filenew(x, y);
-
gameFrame.display();
-
}
-
public void closeGame()
-
{
-
if (gameFrame != null)
-
{
-
gameFrame.dispose();
-
gameFrame = null;
-
}
-
}
-
-
}
-
Any suggestion welcome
1 1343 BigDaddyLH 1,216
Recognized Expert Top Contributor
Call setIcon(yourNew IconImage) on the JLabel(s) whose image you want to change.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: duikboot |
last post by:
Hi all,
I'm trying to export a view tables from a Oracle database to a Mysql
database. I create insert statements (they look alright), but it all goes
wrong when I try to execute them in Mysql, because the dates must have
quotes on each side.
I just don't know how make the dates right.
Well I'll just show you the code and some insert statements it generates.
Could anyone please help me?
|
by: m3ckon |
last post by:
Hi there,
had to rush some sql and am now going back to it due to a slow db
performance. I have a db for sales leads and have created 3 views based
on the data I need to produce.
However one o the views, which has subqueries to the other views is VERY
slow and it needs to be speeded up, but am unsure how, can anyone
help... below is the sql?
|
by: Lodewijk van Haringhal |
last post by:
I'am new with javascritping not with programming. Is there nobody who can
help me with ths simple promblem? :) Please, please give me a hint.
Please help me with this script. I have two lists in my form. One to choose
a directory and one to choose a picture. The script bellow works perfect
without the directory choose function.
I tried to make the directory choose function myself but I did not succeed.
I think I made a mistake here:...
|
by: Kurt Watson |
last post by:
I’m having a different kind of problem with Hotmail when I sign in it
says, "Web Browser Software Limitations
Your Current Software Will Limit Your Ability to Use Hotmail
You are using a web browser that Hotmail does not support. If you
continue to use your current browser software we cannot guarantee that
Hotmail will work correctly for you".
Please help, this is very annoying. I have been searching for help on
|
by: Alan Bashy |
last post by:
Please, guys, In need help with this. It is due in the next week. Please,
help me to implement the functions in this programm especially the first
three constructor. I need them guys. Please, help me.
This was inspired by Exercise 7 and Programming Problem 8 in Chapter 3 of
our text.
I have done Exercise 7 for you: Below you will find the ADT specification
for a string
of characters. It represents slightly more that a minimal string...
| |
by: tyler_durden |
last post by:
thanks a lot for all your help..I'm really appreciated...
with all the help I've been getting in forums I've been able to continue
my program and it's almost done, but I'm having a big problem that I
believe if it's solved, the remaining stuff is easy...
my full program until now is here:
http://www.geocities.com/tom4_h4wk/progmail.zip
the problem is the segmentation fault when main trys to run
leficheiro.c.... the *.c2 files are the...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application to create certain textboxes, labels,
and combo boxes? Any ideas would be appreciated.
Thanks
|
by: sd00 |
last post by:
Hi all, can someone give me some coding help with a problem that
*should* be really simple, yet I'm struggling with.
I need the difference between 2 times (Target / Actual)
However, these times will fall somewhere between a Start & End time
Further more, there will be Break & Lunch times between Start & End.
Example...
Start 08:00
Break start 10:30
|
by: 2Barter.net |
last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA
Inbox
Reply
Reply to all
Forward
Print
Add 2Barter.net to Contacts list
Delete this message
Report phishing
Show original
|
by: jenipriya |
last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors...
The table structures i hav
Employee (EmpID, EmpName,DeptID,DateOfJoin, Sal, Addr)
Finance (EmpID, Sal)
Club (Clubname, EmpID, Fee, DateOfJoin)
Leave (EmpID, Date)
Department (DeptID, DeptName, NoOfEmployees)...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |