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

    Default

    Yeah, it might really vary with my experience, especially that I am just really new into it. I guess a four month-term isn't enough to explore such a wide field of study, but I can't help it. So if you really could spare and help me out, please do so. You've been actually helping me out realize these stuffs, but I am not completely informed yet..
    Sorry..
    And I really thank you for responding to my concern..

  2. #22
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Galore View Post
    ...So if you really could spare and help me out, please do so. ...
    We'll help you where you can, but as always, the more specific the question, the more specific the help. Other than creating this app in its entirety (which we can't do for you obviously), I'm not sure where you are currently stuck.

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

    Default

    I am stuck thinking how I could use my own images to be displayed for the first round.. I should have 6 cards..

  4. #24
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Galore View Post
    I am stuck thinking how I could use my own images to be displayed for the first round.. I should have 6 cards..
    Again, the more specific your question the more specific the reply. The best answer for this one is to direct you to the tutorial on JLabel which will show how to display images on JLabels: How to use Labels

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

    Default

    I could not fully comprehend how exactly I should implement the JButtons to use my images..
    Feeling so down for the nth time for this project, I went back and polished the code for the start of the game, and I think, I came up with a better output.. Unlike the varying outputs I used to get, I finally got an unchanging result and started to get happy with it though it was not the game itself at the first place..
    I am just wondering if what I am thinking is right..Let me place my code first to put my words into clarity,
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    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);
    		 Toolkit kit = Toolkit.getDefaultToolkit();
             Dimension screenSize = kit.getScreenSize();
             int screenHeight = screenSize.height;
             int screenWidth = screenSize.width;
             setSize(screenWidth, screenHeight);
    	}
    	
    	
    		public void actionPerformed(ActionEvent e){
                        if(e.getSource()==yes){
    						JOptionPane.showMessageDialog(null,"Welcome to Finding Memo!");
    						/*******startGame();********/
    
    						
    
    					}else { 
    					    JOptionPane.showMessageDialog(null,"Thanks for Visiting Memo!");
    						System.exit(0);
    					}
    		}
    
    		
    }
    /*******startGame();********/---> is it fine if I insert the entire GAME code(which I am still struggling with) in this area?
    If so, what should my first lines be?
    I tried putting into codes what the tutorial said based on the link but I got some errors
    Java Code:
    public class ImageIcon extends Object implements Icon, Serializable, Accessible{
    			ImageIcon icon = createImageIcon("1.jpg");
    			ImageIcon icon2 = createImageIcon("2.jpg");
    			ImageIcon icon3 = createImageIcon("3.jpg");
    			ImageIcon icon4 = createImageIcon("4.jpg");
    			ImageIcon icon5 = createImageIcon("5.jpg");
    			ImageIcon icon6 = createImageIcon("6.jpg");
    	}
    help please.. ;(
    Last edited by Galore; 10-18-2009 at 09:32 AM.

  6. #26
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    I made this without getting any errors. My images are saved as 1 through 10 same with the param I used but nothing was shown on my screen after pressing YES aside from the prompt message "Welcome to Finding Memo" which I made to confirm that the user chose YES. Here's the code:
    Java Code:
    public void actionPerformed(ActionEvent e){
                        if(e.getSource()==yes){
    						JOptionPane.showMessageDialog(null,"Welcome to Finding Memo!");
    						//startGame();
    							class JButton{
    								// Declaring and initializing buttons
    							private JButton bt[] = new JButton[10];
    							private JButton bt1 = new JButton();
    							private JButton bt2 = new JButton();
    							private JButton bt3 = new JButton();
    							private JButton bt4 = new JButton();
    							private JButton bt5 = new JButton();
    							private JButton bt6 = new JButton();
    							private JButton bt7 = new JButton();
    							private JButton bt8 = new JButton();
    							private JButton bt9 = new JButton();
    							private JButton bt10 = new JButton();
    							
    							private JButton btTimer = new JButton();
    							private JButton Exit = new JButton();
    							private JButton btreset = new JButton();
    							
    							//Declaring and initializing icons for the pictures
    							ImageIcon image1 = new ImageIcon("1.jpg");
    							ImageIcon image2 = new ImageIcon("2.jpg");
    							ImageIcon image3 = new ImageIcon("3.jpg");
    							ImageIcon image4 = new ImageIcon("4.jpg");
    							ImageIcon image5 = new ImageIcon("5.jpg");
    							ImageIcon image6 = new ImageIcon("6.jpg");
    							ImageIcon image7 = new ImageIcon("7.jpg");
    							ImageIcon image8 = new ImageIcon("8.jpg");
    							ImageIcon image9 = new ImageIcon("9.jpg");
    							ImageIcon image10 = new ImageIcon("10.jpg");
    							
    							
    
    						}
    
    					}else { 
    					    JOptionPane.showMessageDialog(null,"Thanks for Visiting Memo!");
    						System.exit(0);
    					}
    		}
    Could you tell me what's wrong with this please? And, how should I make the images appear appropriately for the player? Another thing is, my game has 3 categories, Easy has 6 cards, average has 8 and difficult has 10. What I wrote here was the maximum thinking there could be some ways to set the number of card in each category but just can't identify how..
    Last edited by Galore; 10-18-2009 at 10:08 AM.

  7. #27
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You'll need to read the tutorial on JButtons. It will show you how to place images on buttons. I don't see you adding your buttons to any container, such as one or several JPanels, and then adding that to a root container such as a JFrame. Nothing will be visible until these things are accomplished. Again, the Swing tutorials can show you the way.

  8. #28
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Like could you just show me a working code? A code which I can use and make as a guide for some other functions I would need. I really appreciate that you are giving me some links to some tutorials, but I just really don't have the luxury of time to comprehend them, it's already dawn, and like just a few more hours, I would need to go to our university and tell an update about this overdue project. I know you know exactly how I should code this, but not of course to spoon feed me, you are giving me some links so I should also learn myself..and I really appreciate that.. only that I really don't have so much time to pinch a lot to comprehend all the tutorials.. I promise I would study more about the tutorials, but I guess I really can't now.. Just a few more days our semestral break would begin, I promise I would study more about this and post forums to get things clearer if ever I would encounter some problems along my self study..Please...If you can just really help me..Please Fubarable.. I don't belong to any university organizations since my mom doesn't want me to get affiliated to any and of course, I must follow her, reason why I really don't have anyone, especially older to guide me make this project.. It's only you right now,honestly, who's helping me along the way.. You just don't know how you're giving me hope by responding to this thread. It's a policy that without a project, we would have a grade of 5..so please.If you really would just help me more.. :(
    Last edited by Galore; 10-18-2009 at 06:56 PM.

  9. #29
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Galore View Post
    Like could you just show me a working code? ... but I just really don't have the luxury of time to comprehend them...
    To do this would require me to basically make your app for you, and we just don't do that here. I'm sorry.

    There are examples of this sort of program that can be found online via Google, but I must say caveat emptor as some of these are not so good.

    I can't do anything about your time constraints either, again sorry.

    Again, any of us here would be willing to try to answer any specific questions you have, but we have to follow our consciences on just how much help to give. I'm sure you understand.

    Best of luck.

  10. #30
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    To do this would require me to basically make your app for you, and we just don't do that here. I'm sorry.

    There are examples of this sort of program that can be found online via Google, but I must say caveat emptor as some of these are not so good.

    I can't do anything about your time constraints either, again sorry.

    Again, any of us here would be willing to try to answer any specific questions you have, but we have to follow our consciences on just how much help to give. I'm sure you understand.

    Best of luck.
    Of course I do. And I am definitely not asking about the entire code..of course that's really conscience bothering. Lucky I am that I made it to this forum, but how about the others having similar problems, right?; of course I do have the concept of "others"..
    What I meant when I asked if you could give me a working code was for me to display the images, like I was asking about how I could manage my own images appear on the screen, that was my latest question which you responded with a link.. and that was what I was referring when I asked for a working code, not the code for the entire game.. If only I could have a stable foundation of reliable code from which I could move on, then I would really be thankful..

    And again, I really thank you Fubarable for helping me out with this..

  11. #31
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Here's an example of adding images to buttons, buttons to panels and panels to jframes. For example:
    Java Code:
    import java.awt.*;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    
    public class ButtonPanel extends JPanel {
       // this image path String will have to change depending on where images are located
       public static final String IMAGE_DIR = "C:/Users/Pete/Documents/Programming/Eclipse Workspace/Fubar2009/src/images/";
       ImageIcon[] icons = new ImageIcon[6];
       JButton[] buttons = new JButton[icons.length * 2];
    
       public ButtonPanel() {
          setLayout(new GridLayout(4, 0)); // 4 columns any number of rows
          
          // for each ImageIcon in the icons array
          for (int i = 0; i < icons.length; i++) {
             // do this in a try block 
             try {
                // create a String that is a path to a JPG image, image00.jpg through image05.jpg
                String imagePath = IMAGE_DIR + "image0" + i + ".jpg";
    
                // create a File Object for the image
                File imageFile = new File(imagePath);
    
                // read the image held by the file by using ImageIO.read
                Image image = ImageIO.read(imageFile);
    
                // create an Icon with the image
                icons[i] = new ImageIcon(image);
    
                // create two buttons
                buttons[2 * i] = new JButton();
                buttons[2 * i + 1] = new JButton();
    
                // place the same icon into the two buttons
                buttons[2 * i].setIcon(icons[i]);
                buttons[2 * i + 1].setIcon(icons[i]);
    
                // add the buttons to "this" which is the class's JPanel
                add(buttons[2 * i]);
                add(buttons[2 * i + 1]);
             }
             catch (IOException e) {
                e.printStackTrace();
             }
    
          }
       }
    }
    This code assumes that there are a bunch of image files named image00.jpg up to image05.jpg located in the directory,
    "C:/Users/Pete/Documents/Programming/Eclipse Workspace/Fubar2009/src/images/"
    For someone else's program, the directory string and perhaps the image name must change

    It creates an array of 6 ImageIcons called icons and an array of 12 (icons.length * 2) JButtons, called buttons.

    The JPanel that is the class has its layout set to GridLayout(4, 0) which means that it will have 4 columns and any number of rows.

    To add an image to a button, you add it as an ImageIcon. So first you must create an Image object,

    In your program, I imagine that your buttons won't be displaying icons until they've been pressed, so you may need to do the JButton's setIcon(...) call your button's actionperformed method.

    This code does not swap images or have any of your program's necessary logic. It just shows how to create a grid of buttons with images on them.

    Here's sample code where I place the ButtonPanel object above into another JPanel (in the BorderLayout.CENTER position) and then display this JPanel in a root container:
    Java Code:
    import java.awt.BorderLayout;
    import javax.swing.*;
    
    public class ButtonPanelMain extends JPanel{
       
       // here's are class that we defined above.
       private ButtonPanel buttonPanel = new ButtonPanel();
       private String[] strings = {"Some", "Buttons", "Go", "Here"};
       
       public ButtonPanelMain() {
          
          // to hold the useless buttons in the bottom panel
          JPanel bottomPanel = new JPanel();
          
          // create buttons that don't do a darn thing, but are here just for illustrative
          // purposes.
          for (String str : strings) {
             JButton btn = new JButton(str);
             bottomPanel.add(btn);
          }
          
          // set the main class's JPanel (this) to use BorderLayout with 10 point gaps
          setLayout(new BorderLayout(10, 10));
          
          // place our button panel in the center position of this JPanel
          add(buttonPanel, BorderLayout.CENTER);
          
          // and the panel with useless buttons on the button (south)
          add(bottomPanel, BorderLayout.SOUTH);
       }
    
       private static void createAndShowUI() {
          // create a JFrame
          JFrame frame = new JFrame("Button Panel Main");
          
          // add the main panel created by the ButtonPanelMain to the 
          // JFrame's contentPane
          frame.getContentPane().add(new ButtonPanelMain());
          
          // Java will quit if the GUI is closed.
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          
          // tell the layout managers to do their thing with pack()
          frame.pack();
          
          // center the app
          frame.setLocationRelativeTo(null);
          
          // show the app
          frame.setVisible(true);
       }
    
       // call swing in a thread safe manner
       public static void main(String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                createAndShowUI();
             }
          });
       }
    }

  12. #32
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Oh thank you Fubarable.. I really thank you.. Just like last night, I plan not to sleep so I can afford your time zone. Hope you'll just be there as I would be buzzing in if ever I would encounter more problems after I analyze this code.I hope it would be fine with you.

    Thanks a lot Fubarable. A real lot!

  13. #33
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Hi Fubarable,

    I tried to make this code but got some errors.
    Hope you could help me sustain this code in this format. I am getting a little confused every time there would be separate ones so as much as possible I want it fixed in just, if possible.Thanks

    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;
    
    public class FindingMemo extends JFrame implements ActionListener {
    	
    	JPanel mainPanel, firstPanel, secondPanel;
    	JButton newButton, quitButton;
    	ImageIcon[] icons = new ImageIcon[6];
        JButton[] buttons = new JButton[icons.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(wholePanel); //
    		
    	}
    	
    	
    	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 (){	
    		initIcons();		
    		for(int i=0; i<icons.length; i++){
    		buttons[i]=new JButton(icons[12]);	
    		secondPanel.add(buttons[i]);	
    		buttons[i].addActionListener(this);	
    		}		
    	}
    	
    	public void initIcons(){
    		icons[1]=new ImageIcon("images/image01.jpg");
    		icons[2]=new ImageIcon("images/image02.jpg");
    		icons[3]=new ImageIcon("images/image03.jpg");
    		icons[4]=new ImageIcon("images/image04.jpg");
    		icons[5]=new ImageIcon("images/image05.jpg");
    		icons[6]=new ImageIcon("images/image06.jpg");	
    		}	
    		
    	public void setArrayListText() {
    		for (int i = 0; i < 2; i++) {
    			for (int ii = 1; ii < (buttons.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[]){
    		FindingMemo application = new FindingMemo();
    	//	Toolkit kit = Toolkit.getDefaultToolkit();
    	//	Image img = kit.getImage("any picture na maliit para icon sa taas");
    	//	application.setIconImage(img); 
    		application.setTitle("FindingMemo");
    		application.setSize(610,610);
    		application.setVisible(true);		
    		application.setResizable(false); //para di nababago size
    	}
    	
    		
    	public void actionPerformed(ActionEvent e){
    		if (newButton == e.getSource()){}
    		if (quitButton == e.getSource()){}
    		for (int i = 0; i < buttons.length; i++) {
    			if (buttons[i] == e.getSource()) {
    				temp = gameList.get(i);
    				buttons[i].setIcon(icons[temp]);
    				buttons[i].setEnabled(false);
    				counter++;
    				if (counter == 3) {
    					if (sameValues()) {
    						buttons[btnID[0]].setEnabled(false);
    						buttons[btnID[1]].setEnabled(false);
    					} else {
    						buttons[btnID[0]].setEnabled(true);
    						buttons[btnID[0]].setIcon(icons[12]);
    						buttons[btnID[1]].setEnabled(true);
    						buttons[btnID[1]].setIcon(icons[12]);
    					}
    					counter = 1;
    				}
    				if (counter == 1) {
    					btnID[0] = i;
    					btnValue[0] = gameList.get(i);
    				}
    				if (counter == 2) {
    					btnID[1] = i;
    					btnValue[1] = gameList.get(i);
    				}
    			}
    		}
    		}
    
    }

  14. #34
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    Hi,
    without posting the error messges ,it is very difficult to sacn the entire piece of code.

    But,from the top level I can say problem started with initIcon method below.

    Array index starts with 0.But u tried to initialize the value from 1 to 6 results to "Array Index Out Of Bounds" Exception.
    public void initIcons(){
    icons[1]=new ImageIcon("images/image01.jpg");
    icons[2]=new ImageIcon("images/image02.jpg");
    icons[3]=new ImageIcon("images/image03.jpg");
    icons[4]=new ImageIcon("images/image04.jpg");
    icons[5]=new ImageIcon("images/image05.jpg");
    icons[6]=new ImageIcon("images/image06.jpg");
    }
    Ramya:cool:

  15. #35
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Ohh thank you RamyaSivaKanth!
    I did change the part which you commented about..but still I could not run the program..
    Java Code:
    public void initIcons(){
    		icons[0]=new ImageIcon("images/image01.jpg");
    		icons[1]=new ImageIcon("images/image02.jpg");
    		icons[2]=new ImageIcon("images/image03.jpg");
    		icons[3]=new ImageIcon("images/image04.jpg");
    		icons[4]=new ImageIcon("images/image05.jpg");
    		icons[5]=new ImageIcon("images/image06.jpg");	
    		}	
    		
    	public void setArrayListText() {
    		for (int i = 0; i < 2; i++) {
    			for (int ii = 1; ii < (buttons.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[]){
    		FindingMemo application = new FindingMemo();
    	//	Toolkit kit = Toolkit.getDefaultToolkit();
    	//	Image img = kit.getImage("any picture na maliit para icon sa taas");
    	//	application.setIconImage(img); 
    		application.setTitle("FindingMemo");
    		application.setSize(610,610);
    		application.setVisible(true);		
    		application.setResizable(false); //para di nababago size
    	}
    	
    		
    	public void actionPerformed(ActionEvent e){
    		if (newButton == e.getSource()){}
    		if (quitButton == e.getSource()){}
    		for (int i = 0; i < buttons.length; i++) {
    			if (buttons[i] == e.getSource()) {
    				temp = gameList.get(i);
    				buttons[i].setIcon(icons[temp]);
    				buttons[i].setEnabled(false);
    				counter++;
    				if (counter == 3) {
    					if (sameValues()) {
    						buttons[btnID[0]].setEnabled(false);
    						buttons[btnID[1]].setEnabled(false);
    					} else {
    						buttons[btnID[0]].setEnabled(true);
    						buttons[btnID[0]].setIcon(icons[6]);
    						buttons[btnID[1]].setEnabled(true);
    						buttons[btnID[1]].setIcon(icons[6]);
    					}
    					counter = 1;
    				}
    				if (counter == 1) {
    					btnID[0] = i;
    					btnValue[0] = gameList.get(i);
    				}
    				if (counter == 2) {
    					btnID[1] = i;
    					btnValue[1] = gameList.get(i);
    				}
    			}
    		}
    		}
    
    }
    cmd prmt said the main class FindingMemo could not be found though I think it was inside my code..

  16. #36
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    u put try catch block and use printStackTrace meth for finding out the error.
    Ramya:cool:

  17. #37
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Actually, I wanted to use this
    Java Code:
    public class ButtonPanel extends JPanel {
       // this image path String will have to change depending on where images are located
       public static final String IMAGE_DIR = "C:/Documents and Settings/Administrator/Desktop/images";
       ImageIcon[] icons = new ImageIcon[6];
       JButton[] buttons = new JButton[icons.length * 2];
       
    
       public ButtonPanel() {
          setLayout(new GridLayout(4, 0)); // 4 columns any number of rows
          
          // for each ImageIcon in the icons array
          for (int i = 0; i < icons.length; i++) {
             // do this in a try block 
             try {
                // create a String that is a path to a JPG image, image00.jpg through image05.jpg
                String imagePath = IMAGE_DIR + "image01" + "image02" +"image03"+"image04"+"image05"+".jpg";
    
                // create a File Object for the image
                File imageFile = new File(imagePath);
    
                // read the image held by the file by using ImageIO.read
                Image image = ImageIO.read(imageFile);
    
                // create an Icon with the image
                icons[i] = new ImageIcon(image);
    
                // create two buttons
                buttons[2 * i] = new JButton();
                buttons[2 * i + 1] = new JButton();
    
                // place the same icon into the two buttons
                buttons[2 * i].setIcon(icons[i]);
                buttons[2 * i + 1].setIcon(icons[i]);
    
                // add the buttons to "this" which is the class's JPanel
                add(buttons[2 * i]);
                add(buttons[2 * i + 1]);
             }
             catch (IOException e) {
                e.printStackTrace();
             }
    
          }
       }
    }
    Since I think it has to do with the positioning of the images.
    I should show 6 images on the first round.That's why I used [6]
    But I don't how exactly I could apply the code I wrote here in the code I posted including the whole of what I have done so far..
    Last edited by Galore; 10-19-2009 at 02:41 PM.

  18. #38
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    Have u tried to put try-catch and printStackTrace? do that and paste the error what u are getting.
    Ramya:cool:

  19. #39
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    Hi. Thanks,
    Could you tell me exactly how this works? Or say, it's purpose?
    Java Code:
    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;
    Thanks,

  20. #40
    Galore is offline Member
    Join Date
    Aug 2009
    Posts
    38
    Rep Power
    0

    Default

    I tried doing this
    Java Code:
    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[i] = new ImageIcon(image);
    
                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();
             }
    
          }
    	
    	}
    instead of this
    Java Code:
    public void secondPanelButtons (){	
    		initIcons();		
    		for(int i=0; i<icons.length; i++){
    		buttons[i]=new JButton(icons[12]);	
    		secondPanel.add(buttons[i]);	
    		buttons[i].addActionListener(this);	
    		}		
    	}
    Since I was thinking that the second panel should hold the buttons for the icons. But I have some errors like saying FindingMemo isn't an abstract class and could not be overridden
    SetArrayListText was another issue(included in the whole code) and a couple of errors about Image and File.. I got 7 errors in this code:
    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;
    
    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];
    				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[i] = new ImageIcon(image);
    
                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();
             }
    
          }
    	
    	}
    	
    	
    }

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

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