Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

paint won't call graphics  RSS feed

 
ciaran Hurst
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have a java program that refuses to call the paint method when i call repaint. I know that i can call update as well but I believe that this won't paint swing only awt. I may be wrong on that . Therefore i need to call paint
code is below can anyone see whats the problem
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.util.HashMap;
import java.util.Iterator;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import java.util.Map;
public class DrawMethods extends ShannonTracer{

private ShannonData traceData;
private HashMap paintedButtons;
private JButton temp;
private JPanel panel;
private Dimension buttonDimension;
private Point buttonLocation, startPoint, endPoint;
private int buttonX,buttonY;
private double buttonHeight,buttonWidth;
private Graphics graphics;
private Rectangle rr;
public DrawMethods(ShannonData data, JPanel thePanel ){
panel = thePanel;
traceData = data;
paintedButtons = new HashMap();
paintedButtons = traceData.getPaintedButtons();
//drawlines();
//this.update(graphics);
//DrawMethods.this.paint(graphics);
repaint();
//panel.updateUI();
//panel.paintComponents(gg);
//this.update(gg);
}

private void drawlines(){
Iterator iter = paintedButtons.entrySet().iterator();
while(iter.hasNext()){
Map.Entry e =(Map.Entry)iter.next();
temp = (JButton)paintedButtons.get(e.getKey().toString());
getButtonDimensions(temp);
startPoint = calculateStart();
}
}

private void getButtonDimensions(JButton button){
buttonWidth = button.getWidth();
buttonHeight = button.getHeight();
buttonLocation = button.getLocation(); //can use getLocation().y or .x
buttonDimension = button.getSize();
}

private Point calculateStart(){
Point start = new Point();
Point end = new Point();
start.x = (int)((double) buttonLocation.x + (buttonWidth/2.0));
start.y = (int)((double)buttonLocation.y + (buttonHeight/2.0));
end.x=start.x+0;
end.y=start.y+200;
return start;
}

public void paint(Graphics g){
JOptionPane.showMessageDialog(null,"I am a dope");
g.setColor(Color.yellow);
Font font = new Font("arial",Font.ITALIC,55);
g.drawString("bigears" + g.getFont(),200,100);

}


}
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What class does ShannonTracer extend? and does it override the update(Graphics g) method? And maybe not call paint(g)?
 
ciaran Hurst
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya i fixed it. Basically i was making it more complicated than it needed to be.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!