Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Paint method is not called using this.repaint()

843805Jan 11 2007 — edited Jan 12 2007
I am developing a drawing application. the mainClass.java is a frame which contains the GUI for the application. I am using command pattern for it.
the drawing area is a drawPanel.java class. mainClass.java contains a menubar, which has menuItem as drawline. Onclick of drawLine, the control goes to drawLine.java class. this class makes object of drawPanel, passes x, y co-ordinates to a function in drawPanel, which then calls paint method using this.repaint().
i have debugged my code, but the control after repaint returns to drawline.java class. it does not paint.
here is my code -
mainClass.java

public static void main(String s[]) {
mainClass example = new mainClass();
JFrame frame = new JFrame("Action Example");
// frame.addWindowListener(new B);
frame.setJMenuBar(example.menuBar);
frame.getContentPane().add(example.toolBar, BorderLayout.NORTH);


frame.getContentPane().add(example.panel.drawing());

// panel is drawPane object. drawing() draws panel

frame.setSize(400,400);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

drawLine.java

DrawPanel d = new DrawPanel();

d.drawLine(250,200,300,350);
d.repaint();

drawPanel.java

int xStart, yStart, xEnd, yEnd;
public void drawLine(int x1, int y1, int x2, int y2)
{
this.xStart = x1;
this.yStart = y1;
this.xEnd = x2;
this.yEnd = y2;

// this.repaint();
}

public void paint(Graphics g)
{


g.drawLine(xStart,yStart,xEnd,yEnd);
}

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 9 2007
Added on Jan 11 2007
6 comments
57 views