Results 1 to 5 of 5
Thread: Repaint problem
- 10-28-2009, 01:38 PM #1
Member
- Join Date
- Oct 2009
- Location
- Mars
- Posts
- 3
- Rep Power
- 0
Repaint problem
Hi I'm kind of new to java and I have a problem with 2d graphics repaint method, I have a JFrame which is split in to 2 sections via a borderlayout. The bottom part of the JFrame consist of 4 JTextfields & 1 JButton.
The Center section of the JFrame consist of a JPanel, the 4 JTextfields enable the user to enter the width,height,angle,angle end of an Arc2D.Double shape, the JButton is then pressed to draw the shape on the center JPanel, now I dont have a problem drawing the shape, but everytime I enter new values in to the JTextfields and press the button, instead of the old shape to be wiped clean and a new shape drawn again & again, hence could someone tell me what I can do to enable the old shape to dissapear if a new shape is drawn via repaint().
Here is the code Please could someone help me:(
p.s the code is divided in to 2 classes
package com.rail.network.my;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Arc2D;
public class ThreadTest2 extends JFrame{
protected JTextField jtf1,jtf2,jtf3,jtf4;
BorderLayout bdl = new BorderLayout();
JPanel jpSouth,jpTop,jpCenter;
public ThreadTest2(){
jtf1 = new JTextField(2);
jtf2 = new JTextField(2);
jtf3 = new JTextField(2);
jtf4 = new JTextField(2);
JButton jbtn = new JButton("Send");
jpSouth = new JPanel();
final centerPaint cp = new centerPaint();
Container content = this.getContentPane();
content.setLayout(new BorderLayout());
ActionListener listner = new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println("test tabbed pane");
int awidth = Integer.parseInt(jtf1.getText());
int aheight = Integer.parseInt(jtf2.getText());
int aangleS = Integer.parseInt(jtf3.getText());
int aangleEnd = Integer.parseInt(jtf4.getText());
cp.initializeCords(awidth, aheight, aangleS, aangleEnd);
}};
jbtn.addActionListener(listner);
jpSouth.add(jtf1);
jpSouth.add(jtf2);
jpSouth.add(jtf3);
jpSouth.add(jtf4);
jpSouth.add(jbtn);
content.add(jpSouth,BorderLayout.SOUTH);
content.add(cp,BorderLayout.CENTER);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame windo = new ThreadTest2();
windo.setVisible(true);
}
}
package com.rail.network.my;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.geom.Arc2D;
import javax.swing.JPanel;
public class centerPaint extends JPanel{
BasicStroke stroke = new BasicStroke(2.0f);
int width=0;
int height=0;
int angleS=0;
int angleEnd=0;
public centerPaint(){}
public void initializeCords(int width,int height,int angleS,int angleEnd){
this.width=width;
this.height=height;
this.angleS=angleS;
this.angleEnd=angleEnd;
this.revalidate();
this.repaint();
}
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setBackground(Color.gray);
g2.setPaint(Color.blue);
g2.setStroke(stroke);
Shape s = new Arc2D.Double(40,60,width,height,angleS,angleEnd,Ar c2D.OPEN);
g2.fill(s);
g2.draw(s);
}
}
- 10-28-2009, 02:32 PM #2
in frame leve in ThreadTest2 u try to call repaint..
cp.initializeCords(awidth, aheight, aangleS, aangleEnd);
repaint();Ramya:cool:
- 10-28-2009, 02:41 PM #3
Member
- Join Date
- Oct 2009
- Location
- Mars
- Posts
- 3
- Rep Power
- 0
repaint problem
Yes i know that, but as I said, every time I enter new vlaues to draw another shape, instead of the old shape to dissapear when a new shape is created, the old shape still appears on the jpanel, is there something I'm doing wrong, did not quite understand your last reply
- 10-28-2009, 02:44 PM #4
instead of doing repaint in panel level ..do in frame level.iam asking u to put inside actionPerformed meth after calling initializeCords
Ramya:cool:
- 10-28-2009, 03:02 PM #5
Member
- Join Date
- Oct 2009
- Location
- Mars
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Problem in mouse click n repaint
By Preethi in forum New To JavaReplies: 4Last Post: 07-04-2008, 11:16 AM -
repaint problem
By amith in forum Java 2DReplies: 2Last Post: 07-01-2008, 12:10 AM -
Problem in repaint
By Preethi in forum AWT / SwingReplies: 16Last Post: 03-18-2008, 08:10 PM -
Repaint problem
By swimberl in forum Java 2DReplies: 1Last Post: 02-16-2008, 09:12 PM -
Repaint problem
By swimberl in forum Java 2DReplies: 0Last Post: 01-06-2008, 03:28 AM


LinkBack URL
About LinkBacks
Reply With Quote
D

Bookmarks