Thread: JPanel Problems
View Single Post
  #3 (permalink)  
Old 10-10-2007, 11:07 PM
Riftwalker Riftwalker is offline
Member
 
Join Date: Jul 2007
Posts: 10
Riftwalker is on a distinguished road
I'm pretty sure that this is the case, but I'll post the pertinent code for each.

JPanel 1 (the one that works)
Code:
public class displayPanel extends JPanel implements Scrollable { private mainWindow mainWin; private Graphics2D g2; private sequenceDisplayPanel sdPanel; private int contigNum = 0; private Contig[] contigArray; private interactiveRectangle[] rectArray; private displayPanel displaypanel; private Rectangle backbone; private String contigName; public displayPanel(mainWindow mw, sequenceDisplayPanel sdP) { mainWin = mw; sdPanel = sdP; displaypanel = this; setPreferredSize(new Dimension(1000,500)); setBackground(Color.WHITE); displaypanelMListener clickListener = new displaypanelMListener(); addMouseListener(clickListener); } public void paintComponent(Graphics g) { super.paintComponent(g); g2 = (Graphics2D)g; try { g2.setColor(Color.BLACK); g2.drawString(contigName, 40, 35); g2.fill(backbone); for(int j = 40; j < contigArray[contigNum].getContigLength(); j += 100) { g2.drawString(String.valueOf(j-40), j , 50); g2.drawLine(j, 55, j, 80); } for(int i = 0; i < rectArray.length; i++) { Rectangle tempRect = rectArray[i]; g2.setColor(Color.BLUE); g2.fill(tempRect); } } catch(NullPointerException nullPointerException){} }
JPanel 2 (the one with problems)
Code:
public class sequenceDisplayPanel extends JPanel implements Scrollable { private JFrame mainWin; private Graphics2D g2; private interactiveRectangle[] rectArray; private sequenceDisplayPanel sdPanel; private int paintY = 20; private int rectNum = 0; public sequenceDisplayPanel(JFrame mW) { mainWin = mW; sdPanel = this; setPreferredSize(new Dimension(1000,100)); setBackground(Color.WHITE); } public void paintComponent(Graphics g) { super.paintComponent(g); g2 = (Graphics2D)g; try { g2.drawString(rectArray[rectNum].getContigName(), 20, paintY); paintY += 15; String tempString = rectArray[rectNum].getContigSeq(); int xDistance = 20; for(int i = 0; i < tempString.length(); i++) { if(i < (rectArray[rectNum].getStartOfUsedRegion() -1) || i > (rectArray[rectNum].getEndOfUsedRegion()-1)) g2.setColor(Color.BLACK); else g2.setColor(Color.RED); g2.drawString(String.valueOf(tempString.charAt(i)), xDistance, paintY); xDistance += 8; } g2.setColor(Color.BLACK); paintY +=20; String totalLength = ("The total length is: " + String.valueOf(rectArray[rectNum].getTotalLength())); g2.drawString(totalLength, 20, paintY); paintY += 20; } catch(NullPointerException nullPointerException){} }
Now this isn't the complete code for each class but it's the only drawing I have in each, etc.
Reply With Quote