Page 3 of 3 FirstFirst 123
Results 41 to 45 of 45
  1. #41
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Ohhh.. I added some libraries and just had 2 remaining errors..
    Last edited by Galore; 10-21-2009 at 01:49 PM.

  2. #42
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    I tried adding throws Exception but still nothing changed..
    :(

  3. #43
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    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..
    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);
    				}
    			}
    		}
    		}
    	
    }
    Please...
    Last edited by Galore; 10-19-2009 at 07:17 PM.

  4. #44
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    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:
    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);
    					}
    		}
    
    		
    }
    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:
    [code]

  5. #45
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    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 09:12 PM.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Java-programmed card game pairs
    By Galore in forum Java Applets
    Replies: 0
    Last Post: 08-30-2009, 08:34 AM
  2. need help coding my game (inkball)
    By tornbacchus in forum New To Java
    Replies: 2
    Last Post: 06-09-2009, 05:38 AM
  3. Creating a Card Game in Java
    By Natrix in forum New To Java
    Replies: 1
    Last Post: 05-05-2009, 06:55 PM
  4. card game Rummy
    By javafox in forum New To Java
    Replies: 4
    Last Post: 03-14-2009, 04:53 PM
  5. A Online Card Game
    By GonzaloP in forum Networking
    Replies: 0
    Last Post: 12-28-2008, 07:37 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •