• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphics2D

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I was trying to generated curve using Graphics2D object, but I do not get a neat curve, but a broken one.
Can any one suggest me how to draw continous curves.
I put my program here for reference:
============
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
public class Shape extends JPanel{
int[] xCords = new int[2001];
int[] yCords = new int[2001];
int iCounter=0;
Shape(){
for(int x=-1000,y=0;x<1000;x++,iCounter++){
y = x;
//System.out.println("x="+x+"y="+y+"iCounter="+iCounter);
xCords[iCounter] = (int)x+50;
yCords[iCounter] =(int)y+50;
}
System.out.println("The last counter = "+iCounter);
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2D = (Graphics2D)g;
//g2D.translate(100,100);
int a = 2;
int b = 5;
int c = 7;

g2D.drawLine(-100,0,100,0);
g2D.drawLine(0,-100,0,100);
//g2D.drawPolyline(xCords,yCords,xCords.length);
g2D.drawPolygon(xCords,yCords,xCords.length);
}
public static void main(String args[]){
JFrame frame = new JFrame("Second Example");
Shape panel = new Shape();
panel.setBackground(new Color(157,102,193));
final JTextField textField = new JTextField(20);
//panel.add(textField);
frame.pack();
frame.getContentPane().add(panel);
frame.setBounds(0,0,600,600);
frame.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
textField.setText(e.getX()+","+e.getY());
}
});
frame.setVisible(true);
}
}
===========
 
reply
    Bookmark Topic Watch Topic
  • New Topic