Results 41 to 45 of 45
- 10-19-2009, 04:54 PM #41
Member
- Join Date
- Aug 2009
- Posts
- 38
- Rep Power
- 0
- 10-19-2009, 05:47 PM #42
Member
- Join Date
- Aug 2009
- Posts
- 38
- Rep Power
- 0
I tried adding throws Exception but still nothing changed..
:(
- 10-19-2009, 06:12 PM #43
Member
- Join Date
- Aug 2009
- Posts
- 38
- Rep Power
- 0
Oh now, I can run it..
However, the images aren't still showing on the screen.. Could you help me please? Fubarable, aren't you online? :( RamyaSivaKanth, are you no longer free? :( Eranga, would you help me please? Please please.. I got only a few hour extension.. :(
Here's the code. Please let me know what I need to edit to make the images appear, or if possible, please insert the code whch would make this run..I have to show 6 images on the first round..
Please...Java Code:import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; import javax.swing.*; import static java.util.Collections.*; import java.util.Random; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import java.awt.BorderLayout; public class FindingMemo extends JFrame implements ActionListener { JPanel mainPanel, firstPanel, secondPanel; JButton newButton, quitButton; public static final String IMAGE_DIR = "C:/Documents and Settings/Administrator/Desktop/images"; ImageIcon[] icon= new ImageIcon[6]; JButton[] button = new JButton[icon.length * 2]; private ArrayList<Integer> gameList = new ArrayList<Integer>(); private int counter = 0; private int[] btnID = new int[2]; private int[] btnValue = new int[2]; int temp; public FindingMemo(){ Container c = getContentPane(); panel (); firstPanelButtons (); secondPanelButtons (); setArrayListText(); c.add(mainPanel); } public void panel(){ mainPanel = new JPanel(); firstPanel = new JPanel(); secondPanel = new JPanel(); mainPanel.setLayout(new BorderLayout(10, 10)); firstPanel.setLayout(new FlowLayout()); secondPanel.setLayout(new GridLayout(4, 0)); mainPanel.add(firstPanel, BorderLayout.SOUTH); mainPanel.add(secondPanel, BorderLayout.CENTER); } public void firstPanelButtons (){ newButton = new JButton ("New Game"); newButton.addActionListener(this); quitButton = new JButton ("Quit Game"); quitButton.addActionListener(this); firstPanel.add(newButton); firstPanel.add(quitButton); } public void secondPanelButtons (){ for (int i = 0; i < icon.length; i++) { try { String imagePath = IMAGE_DIR + "image01" + "image02" +"image03"+"image04"+"image05"+".jpg"; File imageFile = new File(imagePath); Image image = ImageIO.read(imageFile); icon[0]=new ImageIcon("http://www.java-forums.org/images/image01.jpg"); icon[1]=new ImageIcon("http://www.java-forums.org/images/image02.jpg"); icon[2]=new ImageIcon("http://www.java-forums.org/images/image03.jpg"); icon[3]=new ImageIcon("http://www.java-forums.org/images/image04.jpg"); icon[4]=new ImageIcon("http://www.java-forums.org/images/image05.jpg"); icon[5]=new ImageIcon("http://www.java-forums.org/images/image06.jpg"); button[2 * i] = new JButton(); button[2 * i + 1] = new JButton(); button[2 * i].setIcon(icon[i]); button[2 * i + 1].setIcon(icon[i]); add(button[2 * i]); add(button[2 * i + 1]); } catch (IOException e) { e.printStackTrace(); } } } public void setArrayListText() { for (int i = 0; i < 2; i++) { for (int ii = 1; ii < (button.length / 2) + 1; ii++) { gameList.add(ii); } } shuffle(gameList); } public boolean sameValues() { if (btnValue[0] == btnValue[1]) { return true; } return false; } public static void main(String args[]) throws Exception{ FindingMemo application = new FindingMemo(); application.setTitle("FindingMemo"); application.setSize(850,610); application.setVisible(true); application.setLocationRelativeTo(null); application.setResizable(false); } public void actionPerformed(ActionEvent e){ if (newButton == e.getSource()){} if (quitButton == e.getSource()){} for (int i = 0; i < button.length; i++) { if (button[i] == e.getSource()) { temp = gameList.get(i); button[i].setIcon(icon[temp]); button[i].setEnabled(false); counter++; if (counter == 3) { if (sameValues()) { button[btnID[0]].setEnabled(false); button[btnID[1]].setEnabled(false); } else { button[btnID[0]].setEnabled(true); button[btnID[0]].setIcon(icon[5]); button[btnID[1]].setEnabled(true); button[btnID[1]].setIcon(icon[5]); } counter = 1; } if (counter == 1) { btnID[0] = i; btnValue[0] = gameList.get(i); } if (counter == 2) { btnID[1] = i; btnValue[1] = gameList.get(i); } } } } }Last edited by Galore; 10-19-2009 at 06:17 PM.
- 10-19-2009, 07:59 PM #44
Member
- Join Date
- Aug 2009
- Posts
- 38
- Rep Power
- 0
Hello everyone. Just got my code running.
It already show the images, checks if two cards the same, flips back if not, remove from the array if same. I guess it's a very small part of the proposal I made, but at least I have one running now.
I just would like to ask how would I make the images clearer? Whenever I push a button, the image isn't shown well. I mean, it's like it is just a shadow or something. And also, I'd like to know how I could manage to link the "Would you like to play" code9(haha) I had to the very program. I mean, I made this one on a separate file and it's running. And it's the main program. But I have like the one I used to battle in with. Anyway, let me put my codes here:
Like this code is for the start of the game, if the user chooses YES, then the game should follow. And here is the code for that:Java Code:import java.awt.event.*; import java.awt.*; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import javax.swing.*; public class FindingMemo{ public static void main(String[] args){ Memo memo = new Memo(); JFrame frame = new JFrame("Finding Memo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(memo); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } } class Memo extends JPanel implements ActionListener{ JLabel label; JRadioButton yes,no; ButtonGroup radioGroup; public Memo(){ label=new JLabel("Would You Like to Play?"); radioGroup=new ButtonGroup(); yes=new JRadioButton("Yes", true); no=new JRadioButton("No", false); yes.addActionListener(this); no.addActionListener(this); radioGroup.add(yes); radioGroup.add(no); label.setBounds(430,250,150,50); yes.setBounds(380,300,180,20); no.setBounds(560,300,200,20); add(label); add(yes); add(no); } public void actionPerformed(ActionEvent e){ if(e.getSource()==yes){ JOptionPane.showMessageDialog(null,"Welcome to Finding Memo!"); }else { JOptionPane.showMessageDialog(null,"Thanks for Visiting Memo!"); System.exit(0); } } }
[code]
- 10-19-2009, 08:07 PM #45
Member
- Join Date
- Aug 2009
- Posts
- 38
- Rep Power
- 0
Like if Fubarable,RamyaSivaKanth or even Eranga comes online, I hope you could answer some of my questions. Oh yeah, I still have a lot :D
But yeah, seriously, I really would like to thank everyone of you here, especially Fubarable who really helped me a lot. Real thanks!:)
Anyway, here are some of my remaining questions (well some are similar to those written above)
1.How would I link the code I made for welcoming the user to play the game to the code of the game itself?If possible, could you tell me which lines I should remove or like, I would be so grateful, if you post the entire code here(I mean, using the two codes I put above,merged into one).
2. Could you like tell me what I should write in the block of code if the user chooses to reset(New Game) the game?I already put something when the user chooses Quit. Of course that's System.exit(0);
3. Would it be easy to embed a timer into it? If so, could you like give me a sample code and tell me where exactly I should insert it? For this 10 cards, the player should solve it in 15 seconds.
Actually these are some more of the vital parts of my program but since I have already done the most basic one, that is of course, matching the cards, I feel really happy with it. But if you could help me more with this, I would insert such codes you would possibly teach(or give :D) me. I still have about like 10 hours before I finally present this project.However, I would have a Math exam 4 hours from now.
I hope you could help me polish more my code.
And with overflowing gratitude, I'd really like to thank Java-Forums for encouraging me do this project. I mean I was really hopeless especially that nobody was really helping me out, initially. Thanks Fubarable! You rock!Thanks! God bless :))Last edited by Galore; 10-19-2009 at 08:12 PM.
Similar Threads
-
Java-programmed card game pairs
By Galore in forum Java AppletsReplies: 0Last Post: 08-30-2009, 07:34 AM -
need help coding my game (inkball)
By tornbacchus in forum New To JavaReplies: 2Last Post: 06-09-2009, 04:38 AM -
Creating a Card Game in Java
By Natrix in forum New To JavaReplies: 1Last Post: 05-05-2009, 05:55 PM -
card game Rummy
By javafox in forum New To JavaReplies: 4Last Post: 03-14-2009, 03:53 PM -
A Online Card Game
By GonzaloP in forum NetworkingReplies: 0Last Post: 12-28-2008, 06:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks