Results 1 to 8 of 8
  1. #1
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

    Default i need to simplify my code

    hi guys, i have a problem with my code, i can't do anything more (rules) because my code is complex and eventually unnecessarily

    can anyone take a look?

    Java Code:
    ActionListener one = new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    				if (gr1.getCounter1() < 5) {
    					gr1.setCounter1(gr1.getCounter1() + 1);
    					test1.setIcon(play1a);
    					pn1.setText(Integer.toString(play2a));
    					pn5.setText(play3a);
    					pn50.setText(play4a);
    				} else {
    					pn5.setText("No more cards");
    				}
    			}
    		};
    
    		arraybtn[1].addActionListener(one);
    		arraybtn[1].setPreferredSize(new Dimension(120, 20));
    
    		play1a = hand.get(0).getImage();
    		play2a = hand.get(0).toInt();
    		play3a = hand.get(0).toString();
    		play4a = hand.get(0).suit();
    
    		arraybtn[1].setText(play3a);
    		arraybtn[1].setFont(new Font("sansserif", Font.BOLD, 7));
    Last edited by felito; 02-06-2011 at 03:54 PM.

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

    Default

    I think you may be asking a volunteer to review too much code to be honest. But general refactoring recommendations include use of arrays or collections of similar things, create methods to reduce code redundancy (which you have a ton of by the way) and creating separate classes for separate concepts.

    Edit: On review of your code, I can say that just creating a method anywhere you see code redundancy will reduce the size of your program greatly. Code refactoring can be boring work but it's necessary. Much luck.
    Last edited by Fubarable; 02-06-2011 at 03:57 PM.

  3. #3
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    618
    Rep Power
    4

    Default

    So What do you want create? It is freaks code ) Sorry.
    Skype: petrarsentev
    http://TrackStudio.com

  4. #4
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

    Default

    for simplicity only put the part where I'm having problems. The issue is that I only know what card was played by an overwrite of the panel, that's my problem

    i don't have much experience with java or another language and i don't have time to study unfortunately because of deadlines

  5. #5
    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 felito View Post
    i don't have much experience with java or another language and i don't have time to study unfortunately because of deadlines
    You may not like what I have to say, but:

    <soap_box>
    Then I doubt we can help you. Seriously. Why should we put in effort if you can't or won't.
    </soap_box>

  6. #6
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

    Default

    if you do not want to help me, ok, but do not doubt my effort for this work

  7. #7
    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 felito View Post
    if you do not want to help me, ok, but do not doubt my effort for this work
    I don't doubt your effort either, but your statement above implies that you value your own time more than ours, which usually raises hackles. But regardless, you're creating a card game of some sort it seems, so it would seem logical for you to create classes that are typical of these types of applications, a Player class, a Card class, a Deck class, a GameManager and so forth, but to do this will require further study and work on your part. I don't know of any simple easy fix for your code other than the drudge work that you will need to do. Sorry.

  8. #8
    felito is offline Member
    Join Date
    Nov 2010
    Posts
    48
    Rep Power
    0

Similar Threads

  1. Code to check if a piece of code is legal.
    By vahshir in forum New To Java
    Replies: 3
    Last Post: 08-30-2010, 04:21 AM
  2. Replies: 1
    Last Post: 03-04-2010, 11:19 AM
  3. Replies: 0
    Last Post: 11-29-2009, 10:32 AM
  4. Any comments, can anyone simplify it further?
    By PeterFeng in forum New To Java
    Replies: 3
    Last Post: 01-15-2009, 05:45 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

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