Repaint() in JPanel doesn't align correctly

Hey all,
I'm running into this problem with a program I'm writing for work. It's basically a dispatch board which connects to our SQL server via ODBC. When the user presses a "Next" or "Prev" button, the dates will change and show the dispatching for the next or previous week respectively. However, the refreshed components go where they are supposed to, but the old screen is underneath, and shifted slightly so that nothing aligns. In turn, you can make heads or tails as to what's happening. However, if you select File -> Refresh from my menubar (calls repaint() the same way) everything is repainted correctly. Any ideas?
package dispatchBoard.DispatchBoard;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.sql.*;
import javax.swing.JPanel;
import sun.misc.Queue;
public class DB_MainWindow extends JPanel implements MouseListener{
     private static final long serialVersionUID = 1L;
     private int _xRes, _yRes;
     private int _techs;
     private String _dayOption, _monday, _tuesday, _wednesday, _thursday, _friday, _odbcName, _databaseName, _currYear;
     private String[] _months;
     private Tech _myTechList;
     private Font _defaultFont;
     DB_Frame _mainFrame;
     private Calendar cal = new GregorianCalendar();
     public DB_MainWindow(String _resolution, String optionString, String ofTechs, DB_Frame frame, String _odbc, String _database, String _year)
          _xRes = Integer.valueOf(_resolution.substring(0, findCharPosition(_resolution, 'x'))).intValue() - 5;
          _yRes = Integer.valueOf(_resolution.substring(findCharPosition(_resolution, 'x')+1)).intValue() - 30;
          _techs = Integer.valueOf(ofTechs).intValue();
          _dayOption = optionString;
          _mainFrame = frame;
          _odbcName = _odbc;
          _databaseName = _database;
          _currYear = _year;
          setDaysFiveStraight();
          System.out.println(_xRes + " " + _yRes);
          this.setBackground(Color.GRAY);
          this.setPreferredSize(new Dimension(_xRes,_yRes));
          this.addMouseListener(this);
     public void paint(Graphics g)
          _myTechList = null;
          int _spacing = 0;
          int _spacing2 = 0;
          g.setColor(Color.BLACK);
          g.drawLine(60,0,60,_yRes);
          _defaultFont =g.getFont();
          //draw tech barriers
          for (int i = 1; i < _techs+1; i ++)
               _spacing = _yRes / (_techs+1);
               g.drawLine(0, _spacing*i, 1366, _spacing*i);
          //draw day barriers
          for (int j = 1; j < 5; j++)
               _spacing2 = (_xRes-60) / 5;
               g.drawLine(_spacing2*j + 60, 0, _spacing2*j + 60, 768);
          int _curPos = 60, _timePos = 0;
          int _time[] = {8,9,10,11,12,1,2,3,4,5};
          for (int k = 0; k < 5; k++)
               _curPos = 60+(k*_spacing2);
               for (int l = 0; l < 9; l++)
                    g.drawLine( _curPos + (l*(_spacing2/9)), 0+_spacing, _curPos + (l*(_spacing2/9)), _yRes);
                    String _tempString = ""+_time[_timePos];
                    g.drawString(_tempString, _curPos + (l*(_spacing2/9)), _spacing);
                    _timePos++;
               _timePos = 0;
          //draw graph labels
          System.out.println(_dayOption);
          g.drawString("TECHS", 10, _spacing);
          g.drawString("Monday "+_monday, 60+(_spacing2/2) - 23, _spacing/2);
          g.drawString("Tuesday "+_tuesday, 60+_spacing2+(_spacing2/2) - 26, _spacing/2);
          g.drawString("Wednesday "+_wednesday, 60+2*_spacing2+(_spacing2/2) - 33, _spacing/2);
          g.drawString("Thursday "+_thursday, 60+3*_spacing2+(_spacing2/2) - 28, _spacing/2);
          g.drawString("Friday "+_friday, 60+4*_spacing2+(_spacing2/2) - 25, _spacing/2);
           * At this point the default grid, including all labels, have been drawn on
           * the dispatch board.  Now, we have to fetch the data from the SQL server,
           * place it into some sort of form (possibly 2d array?!) and then print it out
           * on the board....
           * Here goes!
//          this.addMouseMotionListener(this);
//          g.drawRect(_mousePosition.x, _mousePosition.y, 10, 10);
          fillInTimes(g, _spacing, _spacing2);
     public void setDaysFiveStraight()
          if (_dayOption.equals(new String("work_week")))
               _monday = new String("");
               _tuesday = new String("");
               _wednesday = new String("");
               _thursday = new String("");
               _friday = new String("");
               String[] _months2 = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
               _months = _months2;
                * Sunday = 1
                * Monday = 2
               System.out.println("DAY OF THE WEEK = "+cal.get(Calendar.DAY_OF_WEEK));
               if (cal.get(Calendar.DAY_OF_WEEK) == 2)
                    _monday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _tuesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _wednesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _thursday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _friday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
               else if (cal.get(Calendar.DAY_OF_WEEK) == 3)
               {     //tuesday
                    _tuesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    System.out.println("TUESDAY = "+_tuesday);
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _wednesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _thursday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _friday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)-4);
                    _monday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
               else if (cal.get(Calendar.DAY_OF_WEEK) == 4)
                    _wednesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _thursday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _friday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)-4);
                    _monday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _tuesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    //System.out.println("TUESDAY = "+_tuesday);
               else if (cal.get(Calendar.DAY_OF_WEEK) == 5)
               {     //thursday
                    _thursday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _friday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)-4);
                    _monday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _tuesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _wednesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
               else if (cal.get(Calendar.DAY_OF_WEEK) == 6)
               {     //friday
                    _friday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)-4);
                    _monday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _tuesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _wednesday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
                    cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+1);
                    _thursday = new String(_months[cal.get(Calendar.MONTH)] + "/"+cal.get(Calendar.DAY_OF_MONTH)+"/"+cal.get(Calendar.YEAR));
     private void fillInTimes(Graphics g, int _spacing, int _spacing2) {
          // need to get the data first, building pre-defined array for test data...
          //****START REAL DATA LOAD****\\
//          Calendar cal = new GregorianCalendar();
         try {
             // Load the JDBC-ODBC bridge
             Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
             // specify the ODBC data source's URL
             String url = "jdbc:odbc:"+_odbcName;
             // connect
             Connection con = DriverManager.getConnection(url,"sa",_currYear);
             // create and execute a SELECT
             Statement stmt = con.createStatement();
             Statement stmt2 = con.createStatement();
             ResultSet techList = stmt2.executeQuery("USE "+_databaseName+" SELECT Distinct(SV00301.Technician) from SV00301 join SV00115 on SV00301.Technician = SV00115.Technician where SV00115.SV_Inactive<>1");
             // traverse through results
             Tech temp;
             int counter = 0;
             while(techList.next())
                  if (_myTechList == null)
                       _myTechList = new Tech(techList.getString(1).trim());
                       System.out.println(_myTechList.getName());
                       counter++;
                  else if (!_myTechList.hasNext())
                       _myTechList.setNext(new Tech(techList.getString(1).trim()));
                       System.out.println(_myTechList.getNext().getName());
                       counter++;
                  else
                       temp = _myTechList.getNext();
                       while(temp.hasNext())
                            temp = temp.getNext();
                       temp.setNext(new Tech(techList.getString(1).trim()));
                       System.out.println(temp.getNext().getName());
                       counter++;
//             printTechList();
             String nextMonth, prevMonth;
             if(cal.get(Calendar.MONTH)==11)
                  nextMonth=_months[0];
             else
                  nextMonth = _months[cal.get(Calendar.MONTH)+1];
             if(cal.get(Calendar.MONTH) == 0)
                  prevMonth = _months[11];
             else
                  prevMonth = _months[cal.get(Calendar.MONTH)-1];
             ResultSet rs = stmt.executeQuery
             ("USE "+_databaseName+" SELECT * from SV00301 JOIN SV00300 on SV00300.Service_Call_ID = SV00301.Service_Call_ID JOIN SV00115 on SV00300.Technician = SV00115.Technician JOIN SV000805 on SV000805.Service_Call_ID = SV00301.Service_Call_ID and SV000805.Note_Service_Index='Description' where (Month(SV00301.Task_Date)="+_months[cal.get(Calendar.MONTH)]+" or Month(SV00301.Task_Date)="+prevMonth+" or Month(SV00301.Task_Date)="+nextMonth+") and SV00300.Status_of_Call='OPEN' and SV00115.SV_Inactive<>1");
             System.out.println("USE "+_databaseName+" SELECT * from SV00301 JOIN SV00300 on SV00300.Service_Call_ID = SV00301.Service_Call_ID JOIN SV00115 on SV00300.Technician = SV00115.Technician JOIN SV000805 on SV000805.Service_Call_ID = SV00301.Service_Call_ID and SV000805.Note_Service_Index='Description' where (Month(SV00300.Date_of_Service_Call)="+_months[cal.get(Calendar.MONTH)]+" or Month(SV00300.Date_of_Service_Call)="+prevMonth+" or Month(SV00300.Date_of_Service_Call)="+nextMonth+") and SV00300.Status_of_Call='OPEN' and SV00115.SV_Inactive<>1");
              while (rs.next()) {
                  // get current row values
                   String servicecallid = rs.getString(1).trim(),
                           tech = rs.getString(4).trim(),
                           rawDate = rs.getString(6).trim(),
                           startTime = rs.getString(7).trim(),
                           _length = rs.getString(9).trim(),
                           description = rs.getString(33).trim(),
                           customernumber = rs.getString(35).trim(),
                           custname = rs.getString(45).trim(),
                           location = rs.getString(46).trim(),
                           calltype = rs.getString(54).trim(),
                           notes = rs.getString(268).trim();   
//                  String formattedDate = month+"/"+day+"/"+year;
//                  System.out.println(formattedDate);
//                  String tech = rs.getString(142).trim();
//                  String rawDate = rs.getString(144);
                  System.out.println(rawDate);
                  String day = rawDate.substring(8,10);
                  String month = rawDate.substring(5,7);
                  String year = rawDate.substring(0,4);
                  formatNumber(day);
                  formatNumber(month);
//                  startTime = rs.getString(145);
//                  String _length = rs.getString(147);
                  int hour = Integer.valueOf(startTime.substring(11,13)).intValue();
                  String minute = startTime.substring(14,16);
                  int minutes = Integer.valueOf(minute).intValue();
                  minutes = minutes / 60;
                  double length = (Integer.valueOf(_length).intValue())/100;
                  // print values
                  //System.out.println ("Service_Call_ID = " + Surname);
                  if (hour!=0)
                       sortJob(new Job(servicecallid, custname, new MyDate(month,day,year), hour+minutes,length, description, customernumber, location, calltype, notes), _myTechList, tech);
              // close statement and connection
              stmt.close();
              con.close();
              catch (java.lang.Exception ex) {
                  ex.printStackTrace();
          //draw techs and blocks of jobs!!!!!
          //***TECHS***\\
         Tech _tempTech = new Tech("DOOKIE");
          int multiplier = 2;
          if (_myTechList.hasNext())
               g.setColor(Color.BLACK);
               _tempTech = _myTechList.getNext();
               g.drawString(_myTechList.getName(),5,(_spacing)*multiplier);
               System.out.println("printJobs(g, "+_myTechList.getName()+","+multiplier+","+_spacing+","+_spacing2+")");
               printJobs(g,_myTechList,multiplier, _spacing,_spacing2);
               multiplier++;
          while(_tempTech.hasNext())
               g.setColor(Color.BLACK);
               g.drawString(_tempTech.getName(),5,(_spacing)*multiplier);
               System.out.println("printJobs(g, "+_tempTech.getName()+","+multiplier+","+_spacing+","+_spacing2+")");
               printJobs(g,_tempTech,multiplier, _spacing,_spacing2);
               multiplier++;
               _tempTech = _tempTech.getNext();
          g.setColor(Color.BLACK);
          g.drawString(_tempTech.getName(),5,(_spacing)*multiplier);
          System.out.println("printJobs(g, "+_tempTech.getName()+","+multiplier+","+_spacing+","+_spacing2+")");
          printJobs(g,_tempTech,multiplier, _spacing,_spacing2);
          //***TIME BLOCKS***\\\
     private void printTechList() {
          // TODO Auto-generated method stub
          boolean temp = !_myTechList.hasNext();
          Tech tempTech = _myTechList;
          System.out.println("BEGINNING TECH LIST PRINTOUT!!!!");
          while (tempTech.hasNext() || temp)
               System.out.println(tempTech.getName());
               if (temp)
                    temp = !temp;
               else
                    tempTech = tempTech.getNext();
          System.out.println(tempTech.getName());
          System.out.println("END TECH LIST PRINTOUT!!!");
     private void formatNumber(String month) {
          // TODO Auto-generated method stub
          if (month.equals(new String("01")))
               month = new String("1");
          else if (month.equals(new String("02")))
               month = new String("2");
          else if (month.equals(new String("03")))
               month = new String("3");
          else if (month.equals(new String("04")))
               month = new String("4");
          else if (month.equals(new String("05")))
               month = new String("5");
          else if (month.equals(new String("06")))
               month = new String("6");
          else if (month.equals(new String("07")))
               month = new String("7");
          else if (month.equals(new String("08")))
               month = new String("8");
          else if (month.equals(new String("09")))
               month = new String("9");
     private void printJobs(Graphics g, Tech techList, int multiplier, int _spacing, int _spacing2) {
          Job tempJob = techList.getJobs();
          boolean temp = false;
          if (tempJob != null)
          {     temp = !tempJob.hasNext();
          while (tempJob.hasNext() || temp)
               g.setColor(Color.RED);
               String _tempDate = new String(tempJob.getDate().toString());
//               System.out.println("This job has date of: "+_tempDate);
               int horizontalMultiplier = 0;
               if (_tempDate.equals(_monday))
                    horizontalMultiplier = 0;
               else if (_tempDate.equals(_tuesday))
                    horizontalMultiplier = 1;
               else if (_tempDate.equals(_wednesday))
                    horizontalMultiplier = 2;
               else if (_tempDate.equals(_thursday))
                    horizontalMultiplier = 3;
               else if (_tempDate.equals(_friday))
                    horizontalMultiplier = 4;
               else
                    horizontalMultiplier = 5;
//               System.out.println("HorizontalMultiplier = "+horizontalMultiplier);
               if (horizontalMultiplier !=5)
                    if (tempJob.getJobCallType().equals(new String("TM"))) g.setColor(new Color(0,255,0));
                    else if (tempJob.getJobCallType().equals(new String("SU"))) g.setColor(new Color(0,255,255));
                    else if (tempJob.getJobCallType().equals(new String("SPD"))) g.setColor(new Color(44,148,67));
                    else if (tempJob.getJobCallType().equals(new String("QUO"))) g.setColor(new Color(0,255,255));
                    else if (tempJob.getJobCallType().equals(new String("MCC"))) g.setColor(new Color(255,0,255));
                    else if (tempJob.getJobCallType().equals(new String("MC"))) g.setColor(new Color(128,0,255));
                    else if (tempJob.getJobCallType().equals(new String("CBS"))) g.setColor(new Color(0,0,255));
                    else if (tempJob.getJobCallType().equals(new String("AS"))) g.setColor(new Color(255,255,255));
                    else g.setColor(Color.red);
                    g.fillRect(/*START X*/(int)(60+(horizontalMultiplier*_spacing2)+(tempJob.getStarTime()-8)*(_spacing2/9)+1),/*START Y*/_spacing*(multiplier-1)+1,/*LENGTH*/(int)(tempJob.getJobLength()*(_spacing2/9)-1),/*WIDTH*/_spacing-1);
                    System.out.println("g.fillRect("+((int)(60+(horizontalMultiplier*_spacing2)+(tempJob.getStarTime()-8)*(_spacing2/9)+1))+","+(_spacing*(multiplier-1)+1)+","+((int)(tempJob.getJobLength()*(_spacing2/9)-1))+","+(_spacing-1)+") :: Multiplier = "+multiplier+" :: JOB NAME = "+tempJob.getJobName()+" :: JOB NUMBER = "+tempJob.getJobNumber());
                    g.setColor(Color.BLACK);
                    g.setFont(new Font("Monofonto", Font.PLAIN, 22));
                    if ((int)(tempJob.getJobLength()*(_spacing2/9)-1) >0)
                         g.drawString(formatStringLength(tempJob.getJobName().toUpperCase(), tempJob.getJobLength()), (int)(60+(horizontalMultiplier*_spacing2)+(tempJob.getStarTime()-8)*(_spacing2/9)+1), (_spacing*(multiplier)+1)-_spacing/2+5);
                    g.setFont(_defaultFont);
                    if (!temp)
                         tempJob = tempJob.getNext();
                         if (tempJob.hasNext() == false)
                              temp = true;
                    else
                         temp = !temp;
               else
                    System.out.println("*g.fillRect("+((int)(60+(horizontalMultiplier*_spacing2)+(tempJob.getStarTime()-8)*(_spacing2/9)+1))+","+(_spacing*(multiplier-1)+1)+","+((int)(tempJob.getJobLength()*(_spacing2/9)-1))+","+(_spacing-1)+") :: Multiplier = "+multiplier+" :: JOB NAME = "+tempJob.getJobName()+" :: JOB NUMBER = "+tempJob.getJobNumber());
                    if (!temp)
                         tempJob = tempJob.getNext();
                         if (tempJob.hasNext() == false)
                              temp = true;
                    else
                         temp = !temp;
     //     g.fillRect((int)(60+(tempJob.getStarTime()-8)*(_spacing2/9)+1),_spacing*(multiplier-1)+1,(int)(tempJob.getJobLength()*(_spacing2/9)-1),_spacing-1);
     private String formatStringLength(String string, double jobLength) {
          // TODO Auto-generated method stub
          if (jobLength*3>string.length())
               return string;
          return string.substring(0, new Double(jobLength*3).intValue());
     private void sortJob(Job job, Tech techList, String techName) {
          Tech _tempTech2;
          if (techName.equals(techList.getName()))
               techList.insertJob(job);
               System.out.println("ADDED " + job.getJobName() +" TO " + techName);
          else
               _tempTech2 = techList.getNext();
               while (!_tempTech2.getName().equals(techName) && _tempTech2.hasNext())
                    _tempTech2 = _tempTech2.getNext();
//                    System.out.println(_tempTech2.getName()+" vs. " + techName);
               if (_tempTech2.getName().equals(techName))
                    _tempTech2.insertJob(job);
                    System.out.println("ADDED " + job.getJobName() +" TO " + techName);
               else
                    System.out.println("TECH NAME: "+_tempTech2.getName()+" NOT FOUND :: COULD NOT INSERT JOB");
     private int findCharPosition(String _resolution2, char c) {
          // TODO Auto-generated method stub
          for (int i = 0; i < _resolution2.length(); i++)
               if (_resolution2.charAt(i) == c)
                    return i;
          return 0;
     public void mouseReleased(MouseEvent arg0) {
          // TODO Auto-generated method stub
          System.out.println("Mouse clicked at coordinates: "+arg0.getX()+", "+arg0.getY()+"\nAttempting to intelligently find the job number");
           * Find the tech
          int techNum = arg0.getY()/(_yRes / (_techs+1));
          String techName= new String("");
          int counter = 0;
          Tech temp = _myTechList;
          boolean found = true;
          while(temp.hasNext() && found)
               counter++;
               if (counter == techNum)
                    techName = temp.getName();
                    found = false;
               else
                    temp = temp.getNext();
          System.out.println("The "+techNum+"th tech was selected... which means you clicked "+techName);
           * Find the day
          int day = (arg0.getX()-60)/(0 + ((_xRes-60)/5));
          String days[] = {_monday, _tuesday, _wednesday, _thursday, _friday};
          System.out.println("The day you chose was "+days[day]);
           * Find the time
          int blocksIn = ((arg0.getX()-60)/(((_xRes-60)/5)/9))%9;
          System.out.println(blocksIn+" blocks inward!!!!");
           * Find the job
           *           - temp is already initialized to the current tech!!
          System.out.println(temp.getName()+" has "+temp.getNumberOfJobs()+" jobs");
          Job current = temp.getJobs();
          Queue jobQueue = new Queue();
          boolean first = true;
          while(current.hasNext() || first)
               if(current.getDate().toString().equals(days[day]))
                    jobQueue.enqueue(current);
                    System.out.println("Queued the job on "+current.getDate().toString()+"::"+current.getJobNumber());
                    if (first)
                         first = false;
                         current = current.getNext();
                    else
                         current = current.getNext();
               else
                    System.out.println("Did not queued the job on "+current.getDate().toString()+"::"+current.getJobNumber());
                    if (first)
                         first = false;
                         current = current.getNext();
                    else
                         current = current.getNext();
          if(current.getDate().toString().equals(days[day]))
               jobQueue.enqueue(current);
               System.out.println("Queued the job on "+current.getDate().toString()+"::"+current.getJobNumber());
          else
               System.out.println("Did not queue the job on "+current.getDate().toString()+"::"+current.getJobNumber());
          blocksIn+=8;
          while(!jobQueue.isEmpty())
               try {
                     * Get a job off the queue... now check the times
                    Job dqJob = (Job)jobQueue.dequeue();
                    System.out.println(dqJob.getStarTime()+"<="+blocksIn +" && "+(dqJob.getStarTime()+dqJob.getJobLength()-1)+">="+blocksIn+" :: "+dqJob.getJobName());
                    if (dqJob.getStarTime()<=blocksIn && dqJob.getStarTime()+dqJob.getJobLength()-1>=blocksIn)
                         System.out.println("MONEY!!!! Found job: "+dqJob.getJobName());
                         new JobDisplayer(dqJob, _xRes, _yRes);
               } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
     public void mouseEntered(MouseEvent arg0) {
          // TODO Auto-generated method stub
     public void mouseExited(MouseEvent arg0) {
          // TODO Auto-generated method stub
     public void mousePressed(MouseEvent arg0) {
          // TODO Auto-generated method stub
     public void mouseClicked(MouseEvent arg0) {
          // TODO Auto-generated method stub
     public void nextDay() {
          // TODO Auto-generated method stub
          if (_dayOption.equals(new String("work_week")))
               cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)+7);
               setDaysFiveStraight();
          this.repaint();
     public void prevDay() {
          // TODO Auto-generated method stub
          if (_dayOption.equals(new String("work_week")))
               cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR)-7);
               setDaysFiveStraight();
               this.repaint();
          this.repaint();
}Sorry for the huge chunk of code.
Thanks in advance,
Jeff

Sorry for the huge chunk of code.
Mm, yes, I'm far too lazy to read all that.
But you should be overriding paintComponent(), not paint().
http://www.google.co.uk/search?hl=en&q=java+swing+painting&btnG=Google+Search&meta=
I've not bothered to work out from that pile of magic numbers exactly what you're tring to draw but is it not something that JTable would happily do?

Similar Messages

  • How to repaint a JPanel in bouncing balls game?

    I want to repaint the canvas panel in this bouncing balls game, but i do something wrong i don't know what, and the JPanel doesn't repaint?
    The first class defines a BALL as a THREAD
    If anyone knows how to correct the code please to write....
    package fuck;
    //THE FIRST CLASS
    class CollideBall extends Thread{
        int width, height;
        public static final int diameter=15;
        //coordinates and value of increment
        double x, y, xinc, yinc, coll_x, coll_y;
        boolean collide;
        Color color;
        Rectangle r;
        bold BouncingBalls balls; //A REFERENCE TO SECOND CLASS
        //the constructor
        public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c, BouncingBalls balls) {
            width=w;
            height=h;
            this.x=x;
            this.y=y;
            this.xinc=xinc;
            this.yinc=yinc;
            this.balls=balls;
            color=c;
            r=new Rectangle(150,80,130,90);
        public double getCenterX() {return x+diameter/2;}
        public double getCenterY() {return y+diameter/2;}
        public void move() {
            if (collide) {
            x+=xinc;
            y+=yinc;
            //when the ball bumps against a boundary, it bounces off
            //bounce off the obstacle
        public void hit(CollideBall b) {
            if(!collide) {
                coll_x=b.getCenterX();
                coll_y=b.getCenterY();
                collide=true;
        public void paint(Graphics gr) {
            Graphics g = gr;
            g.setColor(color);
            //the coordinates in fillOval have to be int, so we cast
            //explicitly from double to int
            g.fillOval((int)x,(int)y,diameter,diameter);
            g.setColor(Color.white);
            g.drawArc((int)x,(int)y,diameter,diameter,45,180);
            g.setColor(Color.darkGray);
            g.drawArc((int)x,(int)y,diameter,diameter,225,180);
            g.dispose(); ////////
        ///// Here is the buggy code/////
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.canvas.repaint();
    //THE SECOND CLASS
    public class BouncingBalls extends JFrame{
        public Graphics gBuffer;
        public BufferedImage buffer;
        private Obstacle o;
        private List<CollideBall> balls=new ArrayList();
        private static final int SPEED_MIN = 0;
        private static final int SPEED_MAX = 15;
        private static final int SPEED_INIT = 3;
        private static final int INIT_X = 30;
        private static final int INIT_Y = 30;
        private JSlider slider;
        private ChangeListener listener;
        private MouseListener mlistener;
        private int speedToSet = SPEED_INIT;
        public JPanel canvas;
        private JPanel p;
        public BouncingBalls() {
            super("fuck");
            setSize(800, 600);
            p = new JPanel();
            Container contentPane = getContentPane();
            final BouncingBalls xxxx=this;
            o=new Obstacle(150,80,130,90);
            buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
            gBuffer=buffer.getGraphics();
            //JPanel canvas start
            final JPanel canvas = new JPanel() {
                final int w=getSize().width-5;
                final int h=getSize().height-5;
                @Override
                public void update(Graphics g)
                   paintComponent(g);
                @Override
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    gBuffer.setColor(Color.ORANGE);
                    gBuffer.fillRect(0,0,getSize().width,getSize().height);
                    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
                    //paint the obstacle rectangle
                    o.paint(gBuffer);
                    g.drawImage(buffer,0,0, null);
                    //gBuffer.dispose();
            };//JPanel canvas end
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            addButton(p, "Start", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    CollideBall b = new CollideBall(canvas.getSize().width,canvas.getSize().height
                            ,INIT_X,INIT_Y,speedToSet,speedToSet,Color.BLUE,xxxx);
                    balls.add(b);
                    b.start();
            contentPane.add(canvas, "Center");
            contentPane.add(p, "South");
        public void addButton(Container c, String title, ActionListener a) {
            JButton b = new JButton(title);
            c.add(b);
            b.addActionListener(a);
        public boolean collide(CollideBall b1, CollideBall b2) {
            double wx=b1.getCenterX()-b2.getCenterX();
            double wy=b1.getCenterY()-b2.getCenterY();
            //we calculate the distance between the centers two
            //colliding balls (theorem of Pythagoras)
            double distance=Math.sqrt(wx*wx+wy*wy);
            if(distance<b1.diameter)
                return true;
            return false;
        synchronized void repairCollisions(CollideBall a) {
            for (CollideBall x:balls) if (x!=a && collide(x,a)) {
                x.hit(a);
                a.hit(x);
        public static void main(String[] args) {
            JFrame frame = new BouncingBalls();
            frame.setVisible(true);
    }  And when i press start button:
    Exception in thread "Thread-2" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-3" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-4" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    and line 153 is: balls.canvas.repaint(); in Method run() in First class.
    Please help.

    public RepaintManager manager;
    public BouncingBalls() {
            manager = new RepaintManager();
            manager.addDirtyRegion(canvas, 0, 0,canvas.getSize().width, canvas.getSize().height);
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.manager.paintDirtyRegions(); //////// line 153
       but when push start:
    Exception in thread "Thread-2" java.lang.IllegalMonitorStateException
    at java.lang.Object.notifyAll(Native Method)
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-3" java.lang.IllegalMonitorStateException
    at java.lang.Object.notifyAll(Native Method)
    at fuck.CollideBall.run(CollideBall.java:153)
    i'm newbie with Concurrency and i cant handle this exceptons.
    Is this the right way to do repaint?

  • What component Should I use?, Jpanel doesn't work

    Hi
    I need a program that has a window that can go fullscreen and windowed (I did that with a Jframe in fullscreen mode with a jpnale and a 800x600 Jpanel and destroying them with an object that maneges them), I did it with a jframe that contained a Jpanel, I used a Jpanel to avoid the flickering on the screen but I also need to change the font type and the font size, but the setFont on the Jpanel doesn't change the font (as I have realized and also read here [http://forum.java.sun.com/thread.jspa?forumID=257&threadID=150588] ), so I'm lost, I might have to redo the whole thing, but I just wanted to know what component should I use for a window that is going to have custom graphics and need diffrent fonts and diffrent font sizes and work in fullscreen without flickering
    Thank you for your attention, I would aprecciate any help given

    for example:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSlider;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    public class JPanelFont extends JPanel
      private Font font = getFont();
      private String myString = "Fubars Rule";
      private int fontSize = font.getSize();
      private JSlider slider = new JSlider(0, 100, fontSize);
      public JPanelFont()
        setPreferredSize(new Dimension(620, 250));
        setLayout(new BorderLayout());
        JPanel inputPanel = createInputPanel();
        add(inputPanel, BorderLayout.SOUTH);
      private JPanel createInputPanel()
        JPanel ip = new JPanel();
        slider.setMajorTickSpacing(20);
        slider.setMinorTickSpacing(5);
        slider.setPaintTicks(true);
        slider.setPaintLabels(true);
        ip.add(slider);
        slider.addChangeListener(new ChangeListener()
          public void stateChanged(ChangeEvent evt)
            fontSize = (Integer)slider.getValue();
            repaint();
        return ip;
      @Override
      protected void paintComponent(Graphics g)
        Graphics2D g2 = (Graphics2D)g;
        Object originalHint = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        super.paintComponent(g2);
        myPaint(g2);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, originalHint);
      private void myPaint(Graphics2D g2)
        font = font.deriveFont(Font.BOLD, fontSize);
        g2.setFont(font);
        g2.drawString(myString, 20, 100);
      private static void createAndShowUI()
        JFrame frame = new JFrame("Dynamic JPanel Font");
        frame.getContentPane().add(new JPanelFont());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }Edited by: Encephalopathic on May 21, 2008 9:18 PM

  • 24" iMac stand doesn't align with the body??

    When I look at my 24" iMac, the unit itself doesn't align very well with the stand. I noticed that from many different angles.
    It looks a little bit wired, but the unit swing very smoothly.
    Does anyone has the same problem too??
    Will it be better if I remove the stand and install it again?
    Thanks

    Welcome to the Apple Discussions.
    It takes a special card that you must purchase from Apple to detach the stand from the iMac. I would suggest that if it doesn't appear to be attached correctly that you have an Apple Certified Technician check it out for you and make any necessary adjustments.

  • Elements 12 Layer doesn't align vertically with background. (Elements 12)

    Layer doesn't align vertically with background.

    Your last post was empty. Note that you can't post images via e-mail, you have to use a web browser and do it in the forum at http://forums.adobe.com/thread/1424478?tstart=60.
    Cheers,
    Neale
    Insanity is hereditary, you get it from your children
    If this post or another user's post resolves the original issue, please mark the posts as correct and/or helpful accordingly. This helps other users with similar trouble get answers to their questions quicker. Thanks.

  • Report parameters doesn't appear correctly

    I have a report .rdl under Visual Studio2010 and sql server2008.
    the report language is arabic and all the fields appears correctly, but the parameters doesn't appear correct it shows stange characers(not question marks) and all the remaining fields show arabic characters correct.
    i run the report on internet explorer9.
    i don't know what is the problem, i searched alot and there is nothing new. what can i do??

    Hi nermo,
    You have mentioned that the report is work fine on Chrome. It may be a compatibility issue of IE9. At this time, I suggest that you first check this issue in IE9 Compatibility View mode. Please refer to the following steps:
    1. Launch the IE 9, and press Alt+T to select the Tools.
    2. Click Compatibility View settings.
    3. Check the “Display intranet sites in Compatibility View” option, and click Close.
    Reference:
    Fix site display problems with Compatibility View 
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • Game Center doesn't work correctly

    Game Center on iPod Touch 2nd Gen doesn't work correctly under iOS 4.2.1
    It shows wrong language (Englist but not my native language. My region setting is right and the system language right too.)
    Besides, the "Games" page only has a button "Find Game Center Games", while it should show my Game Center Games.
    The Friends page shows all my friends. But when I press a friend the sub page doesn't show the game my friend and I have in common.
    I've restored my device several times, but it didn't help.
    How to solve it?

    I've had exactly the same problem on my 2nd gen since early May when it just stopped working out of the blue.
    There are a few threads here on the subject. I believe that every 2nd gen is affected as I've yet to hear a 2nd gen owner say that theirs works.
    Other than waiting for Apple to fix it I don't think there is a solution.

  • My graphics tablet doesn't align with screen in Photoshop Elements 10

    Hello,
    I had been using my Wacom Bamboo tablet on Photoshop Elements 10 with no problems whatsoever. Today it seems is a different story. As you can see in the image below, the tablet seems to not be aligned correctly with the screen. I am limited to draw in only the section I have scribbled in. I am unable to access any of the screen to draw, use tools etc because it just wont let me when using the tablet. When I use the mouse it is fine.
    I have adjusted all of the settings and made sure everything is correct with my tablet driver and the settings of my tablet, I have no problem with any other program on my computer. I have two tablets and the same problem happens with both. I have tried un-installing Elements but the problem is still there when I re-install it.
    I really am at a loss, it seems like such a simple thing to fix yet I am completely stumped on this one. Please help as I use my tablet on a daily basis and this really is gutting!!!

      PSE will respect the Wacom settings and sensitivities. Go to your tablet control panel and check your pre-sets. Or select he brush tool in the Elements Editor and change the settings to suit.

  • AddChild doesn't work correctly in 11.9

    comparing the two releases listed below, somehow my Flash program doesn't work correctly on the latest version anymore, nothing was changed in my program but after upgrading to the latest Flash Player, it doesn't work properly anymore, specifically, the items I add through the addChild method doesn't appear properly, was there any changes in between these versions that could have affected the addChild behavior? I'm testing with Windows  7 IE debug version and I see no script errors
    Released 10/8/2013) Flash Player 11.9.900.117 (156.2 MB)
    (Released 9/24/2013) Flash Player 11.8.800.175 (Win IE only) (50 MB)

    Could you please open a new bug report on this over at bugbase.adobe.com?  When adding the bug, please include sample code, test url or a test swf so we can quickly test this out internally.  If you'd like to keep this private, feel free to email the attachment to me directly ([email protected]). 
    Once added, please post back with the bug URL and I'll investigate internally.
     

  • IPhoto doesn`t work correctly with german "umlaut" (ä,ö,ü) in keywords

    iPhoto doesn`t work correctly with german "umlaut" (ä,ö,ü) in keywords. They get to ä̈,ö̈, ü̈ when I write the keyword a second time. Can anybody tell me why. Thank you. Heinz

    It apparently does not like non-standard English characters - use A-Z and 0-9 adn you should be OK
    report to Apple - iPhoto menu ==> provide iPhoto feedback
    LN

  • After upgrade my iphone 4 to IOS6, sound doesn't work correctly

    After upgrade my iphone 4 to IOS6, sound doesn't work correctly.
    During a phone call, there is no sound. But if I turn on the speaker, there is sound. itune works fine since it's on the speaker.

    Dear All
    i have done the same activity ( buy a new iphone 4 -> upgrade to ios5 - > configure email) with success-
    than when i start to move the contacts from old mobile to iphone (using the microsim) i receive the same crash
    in disgnosis e use i saw 2 dump with this title 'latestCrash-Preferences.plist and LatestCrash.plist. in each file the date is the same and i read:
    Exception Tyle: EXC_CRASH (SIGABRT)
    Exception code: 0x00000000, 0x00000000
    Chrashed Thread: 6
    in thread 6: name: Dispatch queue:
    com.apple.addressBookUI.ContactsSettingPlugin
    and thaan a lot of data.
    Have you any idea?
    thank in advance
    Fabio

  • Translation from CS5 to Cloud doesn't  work correct, navi and linked images are broken.

    Translation from CS5 to Cloud doesn't  work correct, <navi> and linked images are broken.
    The data of CS5 was created at another PC. I installed Cloud version into two different PC. One has had the site data since dreamweaver CS5 and it works correct in Cloud version. Another PC got the site data from remote server and it doesn't work correct. <navi> and linked image are broken.

    Another PC got the site data from remote server and it doesn't work correct. <navi> and linked image are broken.
    This implies your site is not properly defined in DW.  Go to Site > Manage Sites.
    Or simply go to your other installation of DW and export the site definition file from Manage Sites.
    Save it to a flash stick or other removable drive.  Then import the STE file into your 2nd installation of  DW.
    Nancy O.

  • ITunes 10.4 full screen with Win7-64bit doesn't work correctly.

    iTunes 10.4 full screen with Win7-64 doesn't work correctly. I have the Windows taskbar on the left side of my screen. Maximized iTunes is panned to the left.

    Same issue here. When the Windows taskbar is position on the top of the screen and then the iTunes windows is maximised, it's position is as if the Windows taskbar is at the bottom of the screen so the top of the iTunes window sits under the taskbar.
    For those wanting a workaround, hold shift and right click the iTunes icon in the taskbar/quick launch bar and click restore, at least then you can adjust it to be full screen manually.
    System:
    Windows 7 Ultimate x64
    iTunes 10.4
    ATI 5750 video card

  • Numeric fields not aligned correctly in report preview

    Hi
    I have the next problem:
    On my report, I aligned the numeric fields to the right of a column, but when i run the preview on ASP, the numeric fields are aligned to the left.
    But when I export the report to PDF, the numbers align correctly.
    I figured out a workaround to this, introducing the numeric fields into text fields, since they do align correctly. The problem is that I have too many reports to apply this workaround to all of them.
    Could it be a known issue of Crystal Reports XI?
    Is there any other workaround?
    Thanks in advance

    Hi Poonam
    Maybe I wasn't quite explicit before,
    In preview mode my report displays correctly as well. The problem comes when I run it through an ASP, which is needed for my application.
    I'm running the CR version 11.5.0.313. I was asking if it could be a known issue of XI version because when I had version 9 I didn't have this problem.
    It could also be that through the time, I changed something in the way the report is displayed, and didn't realize about that before, but I haven't been lucky to notice any change related.
    Thanks for your time,
    Gil
    Edited by: Gil Gonzalez on Oct 21, 2008 12:11 AM

  • WRT54G version 6 - router setup screen via Internet Explorer 7 doesn't display correctly

    Hi,
    I've just set up my WRT54G router.  I'm able to connect to the internet and I'm able to connect directly to the router via IE but the setup screen doesn't display correctly.  I've tried resetting the computer and updating the firmware but it still doesn't display correctly.  Almost all of the text is missing except for the Linksys logo and a few drop down menus.  Any help/suggestions would be great, thanks.

    Hi gang,
    There a number of things that you can do to solve this problem but most of them involve changing the rules that you have already configured in your ZoneAlarm profile. My preferred solution is to:
    -unplug your router from the WAN (why not?)
    -turn off zone alarm
    -access your router's administration page at http://192.168.1.1
    -find the admin page where you can switch admin access from http to https
    --- **save your changes !!**
    -reboot your router
    -plug the WAN cable back into your router
    -turn ZoneAlarm back on
    -access your admin page at https://192.168.1.1 ( note the 's')
    Bob is your sister's brother! Your admin page should work as it is supposed to. Your router and ZoneAlarm should be playing nicely together. You haven't borked your finely tuned zonealarm rules. You were going to bookmark your admin page anyway, and if you want to allow remote administration, you would want to use https anyway. Nothing is broken and you fixed two things. "Its a good thing."Message Edited by ubuibi on 12-27-200609:10 AM
    There are really only 10 kinds of people in the world;
    Those who understand binary and those who don't.
    ubuibi

Maybe you are looking for