Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Need help with areas of code

  1. #1
    punchy187 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Arrow Need help with areas of code

    The areas I need some suggestions with are commented \\TODO there are about three areas I am stumped on. I have my attempted code written in a few of the areas which will be in red bold and underlined and the last one or two are left blank. Any suggestions or a point in the right direction would be great. I have been staring at this code for too long and can't seem to get it completed. Thanks.

    [highlight=java]
    package timer.scoreboard;

    import java.awt.Color;
    import java.awt.Dimension;

    import java.awt.Font;
    import java.awt.Rectangle;

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;

    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.SwingConstants;

    public class ScoreboardConsoleFrame
    extends JFrame
    {
    private JLabel lblHome = new JLabel();
    private JLabel lblGuest = new JLabel();
    private JButton btnHomeNameChange = new JButton();
    private JButton btnGuestNameChange = new JButton();
    private JButton btnHomeSubtract1 = new JButton();
    private JButton btnHomeAdd1 = new JButton();
    private JButton btnHomeAdd2 = new JButton();
    private JButton btnHomeAdd3 = new JButton();
    private JButton btnGuestSubtract1 = new JButton();
    private JButton btnGuestAdd1 = new JButton();
    private JButton btnGuestAdd2 = new JButton();
    private JButton btnGuestAdd3 = new JButton();
    private JButton btnHomeFouls = new JButton();
    private JButton btnGuestFouls = new JButton();
    private JButton btnPeriod = new JButton();
    private JButton btnClock = new JButton();
    private JButton btnReset = new JButton();

    private ScoreboardData data;
    private ScoreboardRefresh refreshBoard;

    int ScoreboardTimer timer;
    ScoreboardTimer timer = new ScoreboardTimer(TimerTask task,
    long delay,
    long period,
    "Created new timer");
    // TODO: declare a timer variable

    public ScoreboardConsoleFrame(ScoreboardData data, ScoreboardRefresh refresh, ScoreboardTimer timer
    {
    this.data = data;
    this.refreshBoard = refresh;


    // TODO: Assign timer instance variable to timer argument

    try
    {
    jbInit();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
    }

    private void jbInit()
    throws Exception
    {
    this.getContentPane().setLayout( null );
    this.setSize(new Dimension(523, 251));
    this.setTitle( "Scoreboard Console" );
    lblHome.setText("Home");
    lblHome.setBounds(new Rectangle(15, 10, 80, 20));
    lblHome.setFocusable(false);
    lblHome.setRequestFocusEnabled(false);
    lblHome.setVerifyInputWhenFocusTarget(false);
    lblHome.setFont(new Font("Tahoma", 1, 20));
    lblHome.setHorizontalAlignment(SwingConstants.CENT ER);
    lblHome.setHorizontalTextPosition(SwingConstants.C ENTER);
    lblGuest.setText("Guest");
    lblGuest.setBounds(new Rectangle(275, 10, 80, 20));
    lblGuest.setFocusable(false);
    lblGuest.setRequestFocusEnabled(false);
    lblGuest.setVerifyInputWhenFocusTarget(false);
    lblGuest.setFont(new Font("Tahoma", 1, 20));
    lblGuest.setHorizontalAlignment(SwingConstants.CEN TER);
    lblGuest.setHorizontalTextPosition(SwingConstants. CENTER);
    btnHomeNameChange.setText("Change Name");
    btnHomeNameChange.setBounds(new Rectangle(25, 45, 110, 25));
    btnHomeNameChange.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnHomeNameChange_actionPerformed(e);
    }
    });
    btnGuestNameChange.setText("Change Name");
    btnGuestNameChange.setBounds(new Rectangle(285, 45, 110, 25));
    btnGuestNameChange.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnGuestNameChange_actionPerformed(e);
    }
    });
    btnHomeSubtract1.setText("-1");
    btnHomeSubtract1.setBounds(new Rectangle(25, 85, 50, 30));
    btnHomeSubtract1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnHomeSubtract1_actionPerformed(e);
    }
    });
    btnHomeAdd1.setText("+1");
    btnHomeAdd1.setBounds(new Rectangle(80, 85, 50, 30));
    btnHomeAdd1.setFont(new Font("Tahoma", 0, 9));
    btnHomeAdd1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnHomeAdd1_actionPerformed(e);
    }
    });
    btnHomeAdd2.setText("+2");
    btnHomeAdd2.setBounds(new Rectangle(135, 85, 50, 30));
    btnHomeAdd2.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnHomeAdd2_actionPerformed(e);
    }
    });
    btnHomeAdd3.setText("+3");
    btnHomeAdd3.setBounds(new Rectangle(190, 85, 50, 30));
    btnHomeAdd3.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnHomeAdd3_actionPerformed(e);
    }
    });
    btnGuestSubtract1.setText("-1");
    btnGuestSubtract1.setBounds(new Rectangle(285, 85, 45, 30));
    btnGuestSubtract1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnGuestSubtract1_actionPerformed(e);
    }
    });
    btnGuestAdd1.setText("+1");
    btnGuestAdd1.setBounds(new Rectangle(335, 85, 50, 30));
    btnGuestAdd1.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnGuestAdd1_actionPerformed(e);
    }
    });
    btnGuestAdd2.setText("+2");
    btnGuestAdd2.setBounds(new Rectangle(390, 85, 50, 30));
    btnGuestAdd2.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnGuestAdd2_actionPerformed(e);
    }
    });
    btnGuestAdd3.setText("+3");
    btnGuestAdd3.setBounds(new Rectangle(445, 85, 50, 30));
    btnGuestAdd3.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnGuestAdd3_actionPerformed(e);
    }
    });
    btnHomeFouls.setText("Home Foul");
    btnHomeFouls.setBounds(new Rectangle(25, 130, 110, 25));
    btnHomeFouls.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnHomeFouls_actionPerformed(e);
    }
    });
    btnGuestFouls.setText("Guest Foul");
    btnGuestFouls.setBounds(new Rectangle(285, 130, 110, 25));
    btnGuestFouls.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnGuestFouls_actionPerformed(e);
    }
    });
    btnPeriod.setText("Period");
    btnPeriod.setBounds(new Rectangle(130, 170, 110, 25));
    btnPeriod.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnPeriod_actionPerformed(e);
    }
    });
    btnClock.setText("Stop/Start");
    btnClock.setBounds(new Rectangle(285, 170, 110, 25));
    btnClock.setActionCommand("Clock");
    btnClock.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnClock_actionPerformed(e);
    }
    });
    btnReset.setText("Reset");
    btnReset.setBounds(new Rectangle(430, 10, 75, 25));
    btnReset.setForeground(Color.red);
    btnReset.addActionListener(new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
    btnReset_actionPerformed(e);
    }
    });
    this.getContentPane().add(btnReset, null);
    this.getContentPane().add(btnClock, null);
    this.getContentPane().add(btnPeriod, null);
    this.getContentPane().add(btnGuestFouls, null);
    this.getContentPane().add(btnHomeFouls, null);
    this.getContentPane().add(btnGuestAdd3, null);
    this.getContentPane().add(btnGuestAdd2, null);
    this.getContentPane().add(btnGuestAdd1, null);
    this.getContentPane().add(btnGuestSubtract1, null);
    this.getContentPane().add(btnHomeAdd3, null);
    this.getContentPane().add(btnHomeAdd2, null);
    this.getContentPane().add(btnHomeAdd1, null);
    this.getContentPane().add(btnHomeSubtract1, null);
    this.getContentPane().add(btnGuestNameChange, null);
    this.getContentPane().add(btnHomeNameChange, null);
    this.getContentPane().add(lblGuest, null);
    this.getContentPane().add(lblHome, null);
    }

    private void btnHomeNameChange_actionPerformed(ActionEvent e)
    {
    data.setHomeName(JOptionPane.showInputDialog(this, "Please enter home team name", "Enter Home Team", JOptionPane.QUESTION_MESSAGE));
    refreshBoard.refresh(data); // tell the scoreboard something has changed
    }

    private void btnGuestNameChange_actionPerformed(ActionEvent e)
    {
    data.setGuestName(JOptionPane.showInputDialog(this , "Please enter guest team name", "Enter Guest Team", JOptionPane.QUESTION_MESSAGE));
    refreshBoard.refresh(data); // tell the scoreboard something has changed
    }

    private void btnHomeSubtract1_actionPerformed(ActionEvent e)
    {
    data.setHomeScore(data.getHomeScore() - 1);
    refreshBoard.refresh(data);
    }

    private void btnHomeAdd1_actionPerformed(ActionEvent e)
    {
    data.setHomeScore(data.getHomeScore() + 1);
    refreshBoard.refresh(data);
    }

    private void btnHomeAdd2_actionPerformed(ActionEvent e)
    {
    data.setHomeScore(data.getHomeScore() + 2);
    refreshBoard.refresh(data);
    }

    private void btnHomeAdd3_actionPerformed(ActionEvent e)
    {
    data.setHomeScore(data.getHomeScore() + 3);
    refreshBoard.refresh(data);
    }

    private void btnGuestSubtract1_actionPerformed(ActionEvent e)
    {
    data.setGuestScore(data.getGuestScore() - 1);
    refreshBoard.refresh(data);
    }

    private void btnGuestAdd1_actionPerformed(ActionEvent e)
    {
    data.setGuestScore(data.getGuestScore() + 1);
    refreshBoard.refresh(data);
    }

    private void btnGuestAdd2_actionPerformed(ActionEvent e)
    {
    data.setGuestScore(data.getGuestScore() + 2);
    refreshBoard.refresh(data);
    }

    private void btnGuestAdd3_actionPerformed(ActionEvent e)
    {
    data.setGuestScore(data.getGuestScore() + 3);
    refreshBoard.refresh(data);
    }

    private void btnHomeFouls_actionPerformed(ActionEvent e)
    {
    data.setHomeFouls(data.getHomeFouls() + 1);
    String player = JOptionPane.showInputDialog(this, "Please enter player number", "Enter Player", JOptionPane.QUESTION_MESSAGE);
    String fouls = JOptionPane.showInputDialog(this, "Please enter fouls", "Enter Fouls", JOptionPane.QUESTION_MESSAGE);
    data.setPlayerFouls(player + "-" + fouls);
    refreshBoard.refresh(data);
    }

    private void btnGuestFouls_actionPerformed(ActionEvent e)
    {
    data.setGuestFouls(data.getGuestFouls() + 1);
    String player = JOptionPane.showInputDialog(this, "Please enter player number", "Enter Player", JOptionPane.QUESTION_MESSAGE);
    String fouls = JOptionPane.showInputDialog(this, "Please enter fouls", "Enter Fouls", JOptionPane.QUESTION_MESSAGE);
    data.setPlayerFouls(player + "-" + fouls);
    refreshBoard.refresh(data);
    }

    private void btnPeriod_actionPerformed(ActionEvent e)
    {
    String period = JOptionPane.showInputDialog(this, "Please enter period", "Enter Period", JOptionPane.QUESTION_MESSAGE);
    data.setPeriod(Integer.parseInt(period));
    String time = JOptionPane.showInputDialog(this, "Please enter time in minutes", "Enter Time", JOptionPane.QUESTION_MESSAGE);
    // TODO: update the timer's initial time
    refreshBoard.refresh(data); // tell the scoreboard something has changed
    refreshBoard.updateTime(0 /* TODO: replace this with the time in seconds from the timer*/);
    }

    private void btnClock_actionPerformed(ActionEvent e)
    {

    function timer.toggle(TimerTask task, long delay, long period);

    {

    this.TimerTask task = TimerTask task;

    this.long delay = long delay;

    this.long period = long period;

    }
    // TODO: call the timer's toggle method
    }

    private void btnReset_actionPerformed(ActionEvent e)
    {
    data.reset();
    refreshBoard.reset();
    }
    }

    [/highlight]

  2. #2
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    6

    Default Re: Need help with areas of code

    put the code in [code] tags =) I doubt someone will read it all. See if you can shorten it and only include the stuff that the question was about.

  3. #3
    punchy187 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Need help with areas of code

    Java Code:
    int ScoreboardTimer timer;
    
    ScoreboardTimer timer = new ScoreboardTimer(TimerTask task, long delay, long period, "Created new timer");
    
    // TODO: declare a timer variable
    
    // TODO: Assign timer instance variable to timer argument
    
    // TODO: update the timer's initial time
    
    refreshBoard.updateTime(0/* TODO: replace this with the time in seconds from the timer*/);
    
    function timer.toggle(TimerTask task, long delay, long period); {
    
    this.TimerTask task = TimerTask task;
    
    this.long delay = long delay;
     
    this.long period = long period;
    
    } //Use timers toggle method

  4. #4
    punchy187 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Question Re: Need help with areas of code

    Here is the ScoreboardTimer.java file that goes along with the previous ScoreboardConsoleFrame.java file I posted above. This file has 3 // TODO comments I need to complete. I just need to be pointed in the right direction. Thanks.

    Java Code:
    package week3.scoreboard;
    
    public class ScoreboardTimer extends Thread
    {
       private int counter = 600; // time remaining in seconds; set to 10 minutes by default
       private boolean running = false; // not running at first
       ScoreboardRefresh refresh;
    
       // TODO constructor that sets the initial time and refresh object
    
       // TODO getters and setters
    
       // TODO run method that runs the thread
    
       public void run()
       {
          while (counter > 0)
          {
             sleep(1000); // pause for one second
             if (running)
             {
                // decrement counter and update time display on scoreboard via the refresh object
             }
         }
       }
    }

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

    Default Re: Need help with areas of code

    My nudge is this: give it a go -- try to solve each todo first. Then if you get stuck, come back with your code and any questions you may have. Otherwise you're just cheating yourself out of a valuable learning experience.
    DarrylBurke likes this.

Similar Threads

  1. Replies: 0
    Last Post: 08-07-2011, 09:32 PM
  2. text areas expanding
    By aizen92 in forum New To Java
    Replies: 5
    Last Post: 03-20-2011, 09:51 PM
  3. Triangle Areas - Please help before I smash my laptop into pieces!
    By Atia of the julii in forum New To Java
    Replies: 67
    Last Post: 11-10-2010, 06:40 PM
  4. AWT: Painting buttons and text areas in a canvas
    By chappa in forum AWT / Swing
    Replies: 6
    Last Post: 01-09-2010, 03:37 PM
  5. text areas, printstream, and "\n"
    By diggitydoggz in forum New To Java
    Replies: 10
    Last Post: 12-26-2008, 05:03 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
  •