Java2D graphics Development

Hey!...
My Applet is basically split into two parts....a JTree on the left and a text area on the right...i have two arrays...x3Points and y3Points that contain the map co-ordinates that are retrieved from the server side. They contain data like following for example.....
x3points (-119.169)
y3points (45.7601)
x3points (-119.259)
y3points (45.8506)
I am trying to display these points in the text area using the following code syntax....but nothing show up :(...can neone help pls!
for(int i=0;i<x3Points.length-1;i++)
g2.draw(new Line2D.Double(x3Points,y3Points,x3Points[i+1],y3Points[i+1]));
Thank You...An

oups i meant this one :
for(int i=0;i<x3Points.length-1;i++)
g2.draw(new Line2D.Double(x3Points[ i  ],y3Points[ i  ],x3Points[i+1],y3Points[i+1]));
i think u need to specify the [  i  ] like u did with [i+1].
try and w'll see!

Similar Messages

  • Adding JButtons to a Java2d Graphics program

    Hi,
    I apologise to all you seasoned programmers if this seems an easy question, but I can't seem to see the solution to this one.
    I'm trying to add 2 JButtons to an existing Java2D graphics program. When I run the program I get the following error,
    'java.lang.IllegalArgumentException: adding a window to a container'
    I can't seem to see how to correct this error. My current code is as follows,
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    public class PacMan2Clicks extends JFrame implements ActionListener {
        public static int mode = 0;
        private static JButton rightButton;
        private static JButton leftButton;
        public PacMan2Clicks() {
            Container contentPane = getContentPane();
            JPanel panel = new JPanel();
            leftButton = new JButton("Leftt");
            leftButton.addActionListener(this);
            panel.add(leftButton);
            rightButton = new JButton("Right");
            rightButton.addActionListener(this);
            panel.add(rightButton);
            contentPane.add(panel, BorderLayout.SOUTH);
        public void paintComponent(Graphics g) {
            Dimension d = getSize();
            Graphics2D g2 = (Graphics2D)g;
            int size = 100;
            Ellipse2D.Double head =
                    new Ellipse2D.Double(0, 0, size, size);
            Ellipse2D.Double eye =
                    new Ellipse2D.Double(size/2-1, size/5-1,
                    size/10, size/10);
            GeneralPath mouth = new GeneralPath();
            mouth.moveTo(size, size/4);
            mouth.lineTo(size/8, size/2);
            mouth.lineTo(size, size*3/4);
            mouth.closePath();
            Area pacman = new Area(head);
            pacman.subtract(new Area(eye));
            pacman.subtract(new Area(mouth));
            g2.setPaint(Color.yellow);
            g2.fill(pacman);
            g2.setPaint(Color.black);
            g2.draw(pacman);
        public void actionPerformed(ActionEvent event) {
            if(event.getSource().equals(rightButton)) {
            } else if(event.getSource().equals(leftButton)) {
        public static void main(String[] args) {
            JFrame frame = new JFrame("Drawing stuff");
            frame.add(new PacMan2Clicks());
            frame.setSize(600, 600);
            //frame.setContentPane(new PacMan2Clicks());
            frame.setVisible(true);
            frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
    }Any help appreciated. Thank you.

    Your public class extends JFrame so it is a JFrame. In your main method you create a new JFrame and try to add the enclosing class (a JFrame by extension) to it. So you can either:
    1 &#8212; remove the JFrame extension from the class declaration and leave the code in the main method as&#8212;is:
    public class PM2C implements ActionListener {or,
    2 &#8212; leave the JFrame extension and remove the new JFrame instance in the main method.
    public class PM2C extends JFrame implements ActionListener {
        public PM2C(String title) {
            super(title);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            Container contentPane = getContentPane();
            JPanel panel = new JPanel();
            leftButton = new JButton("Leftt");
            leftButton.addActionListener(this);
            panel.add(leftButton);
            rightButton = new JButton("Right");
            rightButton.addActionListener(this);
            panel.add(rightButton);
            contentPane.add(panel, BorderLayout.SOUTH);
            setSize(600, 600);
            setVisible(true);
        public static void main(String[] args) {
            new PM2C("Drawing stuff");
    }

  • Graphical Development Environment

    Hello all, can I download a Graphical Development environment anywhere. I searched on
    www.java.sun.com, but found nothing.
    TIA, Jules Hoenen

    Or Forte for Java: http://www.sun.com/forte/ffj/index.html
    A list of other IDEs (graphical development environments) can be found at http://java.sun.com/j2se/tools.html
    My current favorite is Eclipse: http://www.eclipse.org/downloads/index.php

  • Java2D graphics question ?

    hi,
    i had to tell that i have absolutely no experience with 2D features, and i would like to embellish my interface without having to read a lot of docs and tutorial, so my question is simple for swing's guru
    I would like to apply the GradiantPaint(say form blue to white) to the backgournd color of a
    JPanel object, can anyone tell me how to do it ?
    thanks for your help

    I have never tried this so i cannot tell you for definate extend JPanel similar to this and use JPanelGrad in the exact same way you would JPanel
    public class JPanelGrad extends JPanel
      GradientPaint gp;
      public JPanelGrad(GradientPaint gp)
        super();
        this.gp=gp;
      public JPanelGrad(GradientPaint gp, LayoutManager layout, boolean isDoubleBuffered)
        super(layout, isDoubleBuffered);
        this.gp=gp;
      public void paint(Graphics _g)
        super(_g);//this statment will slow down painting and i think it is will make no difference to remove it...
                           //i think that in JPanel it simply calls paintComponent(g); paintBorder(g); paintChildren(g);
                           //try it both ways - preferablely remove it
        Graphics2D g=(Graphics2D)_g;
        g.fill(new Rectangle(0, 0, getWidth(), getHeight()));
        g.setPaint(gp);
        paintComponent(g);
        paintBorder(g);
        paintChildren(g);
                      //these three methods r to be in this order;
    JPanelGrad panel=new JPanelGrad(new GradientPaint(0, 0, Color.blue, 10, 0, Color.white));
    Simple as. Bamkin

  • Java2D graphics -GIS(pls help)

    Hey!...
    My Applet is basically split into two parts....a JTree on the left and a text area on the right...i have two arrays...x3Points and y3Points that contain the map co-ordinates that are retrieved from the server side. They contain data like following for example.....
    x3points (-119.169)
    y3points (45.7601)
    x3points (-119.259)
    y3points (45.8506)
    I am trying to display these points in the text area using the following code syntax....but nothing show up :(...can neone help pls!
    for(int i=0;i<x3Points.length-1;i++)
    g2.draw(new Line2D.Double(x3Points,y3Points,x3Points[i+1],y3Points[i+1]));
    Thank You...An

    I don't think you can paint graphics inside a JTextArea.
    import java.awt.*;
    import java.awt.geom.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class ShowingPoints {
      public static void main(String[] args) {
        TreeNode root = new DefaultMutableTreeNode("Root Node");
        TreeModel model = new DefaultTreeModel(root);
        JTree tree = new JTree(model);
        tree.setPreferredSize(new Dimension(200,200));
        double[] xPoints = {
          -20.0, 15.5, 84.1, 65.3
        double[] yPoints = {
          12.9, 15.3, 19.0, 44.3
        LinePlotter lp = new LinePlotter(xPoints, yPoints);
        lp.setPreferredSize(new Dimension(200,200));
        JPanel panel = new JPanel();
        panel.add(tree);
        panel.add(lp);
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JScrollPane(panel));
        f.setSize(400,300);
        f.setLocation(300,300);
        f.setVisible(true);
    class LinePlotter extends JPanel {
      List xData, yData;
      final double PAD = 25.0;
      public LinePlotter(double[] xPoints, double[] yPoints) {
        xData = new ArrayList();
        yData = new ArrayList();
        for(int i = 0; i < xPoints.length; i++) {
          xData.add(new Double(xPoints));
    yData.add(new Double(yPoints[i]));
    setBackground(Color.white);
    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
    RenderingHints.VALUE_ANTIALIAS_ON);
    if(xData.size() == 0 || yData.size() == 0 ||
    xData.size() % 2 != 0 || yData.size() % 2 != 0 || xData.size()/yData.size() != 1)
    return;
    double
    xMin = ((Double)Collections.min(xData)).doubleValue(),
    xMax = ((Double)Collections.max(xData)).doubleValue(),
    yMin = ((Double)Collections.min(yData)).doubleValue(),
    yMax = ((Double)Collections.max(yData)).doubleValue();
    double
    width = getWidth(),
    height = getHeight(),
    yOffset = height - PAD,
    yDataOffset = (yMin >= 0 ? yMin : yMax > 0 ? 0 : yMax),
    xDataOffset = (xMin >= 0 ? xMin : xMax > 0 ? 0 : xMax),
    vertSpace = height - 2*PAD,
    vScale = vertSpace/(yMax - yMin),
    yOrigin = yOffset + (yMin > 0 ? 0 : yMax > 0 ? vScale*yMin : - vertSpace),
    horizSpace = width - 2*PAD,
    hScale = horizSpace/(xMax - xMin),
    xOrigin = PAD - (xMin >= 0 ? 0 : xMax > 0 ? hScale*xMin : - horizSpace);
    double x1, y1, x2, y2;
    for(int i = 0; i < xData.size(); i += 2) {
    x1 = xOrigin + hScale*(((Double)xData.get(i)).doubleValue() - yDataOffset);
    y1 = yOrigin - vScale*(((Double)yData.get(i)).doubleValue() - yDataOffset);
    x2 = xOrigin + hScale*(((Double)xData.get(i + 1)).doubleValue() - xDataOffset);
    y2 = yOrigin - vScale*(((Double)yData.get(i + 1)).doubleValue() - yDataOffset);
    g2.draw(new Line2D.Double(x1, y1, x2, y2));

  • Java2D graphics -GIS (Help pls)

    Hey!...
    My Applet is basically split into two parts....a JTree on the left and a text area on the right...i have two arrays...x3Points and y3Points that contain the map co-ordinates that are retrieved from the server side. They contain data like following for example.....
    x3points (-119.169)
    y3points (45.7601)
    x3points (-119.259)
    y3points (45.8506)
    I am trying to display these points in the text area using the following code syntax....but nothing show up :(...can neone help pls!
    for(int i=0;i<x3Points.length-1;i++)
    g2.draw(new Line2D.Double(x3Points,y3Points[i],x3Points[i+1],y3Points[i+1]));
    Thank You...An

    if your using Swing than use JPanel and turn of opaque or make your one JComponent
    if your using awt to build your application then use canvas.
    if you need more information look in the swing part of the forum or look at java doc and tutor. I suggest to you to d/l the doc/tut of your specific j2se.

  • Printing graphics - URGENT!

    Hi all,
    I am trying to send a Java2D graphics to a printer. I am reading the file name from JFileChooser. Here is my code:
         if(jfc.getFileFilter().getDescription() == psFileFilterDescription){
              File psfile=new File(jfc.getCurrentDirectory(),jfc.getSelectedFile().getName() + ".ps");
              FileOutputStream out = new FileOutputStream(psfile);
              int w=getSize().width;
              int h=getSize().height;
              System.out.print("Writing PS File "+psfile+"\nw:"+w+" h:"+h);
              BufferedImage mImage=new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
              Graphics2D gBuff=mImage.createGraphics();
              paint(gBuff);
         sendToPrinter(mImage);
    private void sendToPrinter(BufferedImage bImage){
    PrinterJob pj = PrinterJob.getPrinterJob();
    // show the print dialog and conditionally proceed
    // with printing if the dialog returns true
    if (pj.printDialog()) {
    // get the default page format
    PageFormat pf = pj.defaultPage();
    // show the page configuration dialog
    // note - this doesn't work in Solaris/JDK1.2beta4
    pj.pageDialog(pf);
    // create a book
    Book b = new Book();
    b.append((Printable)bImage, pf);//How can I convert a BufferedImage to support Printable interface
    // arrange for this book to be the source for our printer job
    pj.setPageable(b);
    // actually invoke the printing
    try {
    pj.print();
    catch (PrinterException ex) {
    ex.printStackTrace(System.err);
    // provide a print method for this component. This implements
    // the Printable interface,
    public int print(Graphics g, PageFormat form, int page) {
    // check for a Graphics2D and apply the page orientation and
    // printable area transforms to it
    if(page == 0) {
    if (g instanceof Graphics2D) {
    AffineTransform tr = new AffineTransform(form.getMatrix());
    tr.translate(form.getImageableX(), form.getImageableY());
    ((Graphics2D)g).transform(tr);
    super.paint(g);
    return PAGE_EXISTS;
    else
    return NO_SUCH_PAGE;
    Does anyone have any ideas on what I should do here?
    Thanks,
    Payam.

    i have a problem with this code.
    public void actionPerformed(ActionEvent e)
              if(e.getSource()==openItem)
                   JFileChooser chooser = new JFileChooser();
                   chooser.setCurrentDirectory(new File("."));
                   chooser.setFilefilter(new javax.swing.filechooser.FileFilter()
                   { public boolean accept(File f)
                        String name = f.getName().toLowerCase();
                        return name.endsWith(".gif")
                        ||name.endsWith(".jpg")
                        ||name.endsWith(".png")
                        ||f.isDirectory();
                   public String getDescription()
                        return "Image files";
              int r = chooser.showOpenDialog(this);
              if(r==JFileChooser.APPROVE_OPTION)
                   String name =chooser.getSelectedFile().getAbsolutePath();
                   panel.loadImage(name);
    all variables used have been allocated memory.

  • What happen to User Interface Development under JDeveloper 9.0.3

    Does anyone know what happen to the user interface development environment that was there under ver 9.0.2 but seems to be missing on ver 9.0.3

    Are you talking about Swing graphical development?
    If you are just right click on the Java file and choose the visual editor.

  • Is it possible to integrate a mentor graphics drawing file using labview or any labview toolkit..!!!

    I m having a mentor graphics drawing file having drawn with the components like resistor,capacitors etc..I need to develop an application to interface to the file using labview or adding a toolkit to labview to access the components like resistors etc .Can any body  help me about this....?
    Thanks in advance...!
    Certified Labview Associate Developer(CLAD)
    Don't Forget to Rate the answers.!!! You can do it in few seconds

    Hi Lynn ,
    Basically i want to read the mentor graphics drawing file data in a labview front panel, so that i can display the components as we see in the mentor graphics development enviornement and should be able to click on the components to perform the tests associated with the same.For this,i think i need to have the BOM kind of data only as i need the components data associated with the drawing file,after this i would create a custom control for each and every component and then call the tests associated with it as soon as the user clicks on the same.I hope you understand my requirements.
    Thanks & regards,
    Dinesh Kumar
    Certified Labview Associate Developer(CLAD)
    Don't Forget to Rate the answers.!!! You can do it in few seconds

  • Dual graphics cards and single 4K display - Mac Pro (late 2013)

    I'm considering a new Mac Pro as my next graphics/development workstation. I see that the new Mac Pros have dual graphics cards (i.e. dual D300, D500, D700.) I was wondering if there is any benefit to having the second graphics card if I only have only one 4K display connected via Display Port 1.2? Would the two cards work in tandem to output to the single 4k display? Can the second GPU still be used for OpenCL, even if it is not connected to a display?
    Thanks

    There is no option to have only one Dxxx, and yes some apps do and no the number of displays does not affect video output.
    Whether it is right for you vs say a maxed out iMac or something else is something you should continue to research and consider.
    www.barefeats.com and www.macperformanceguide.com as well as other forums and sites.

  • Intel HD Graphics 3000 processor on the new Mac Mini Server

    Does the Intel HD Graphics 3000 processor on the new Mac Mini Server support 3D Monitors?
    I'm in the process of purchasing a 3D LED Monitor (27" S27A950D Series 9 LED 3D Monitor) and would like to know if it will be fully compatible with the Intel HD Graphics 3000 processor that came with the Mac Mini Server (Mid 2011).
    Will it be possible to play 3D Games and watch 3D movies with this graphics card?
    Also, does the new Mac Mini Server come with 1st or 2nd Generation Intel Core Processor?

    http://www.intel.com/content/www/us/en/architecture-and-technology/hd-graphics/h d-graphics-developer.html

  • Which visual studio on Microsoft need to be downloaded for design and programming video games?

    I found only for developing of apps

    Hello rousse101,
    Would you mind to describe video games in detail? I'm not quite sure the meaning of your video game. As far as I know, almost all games are actually apps, video in games are just playing some movies and do not have Interaction.
    Flash Player Games seems have interaction but I don't know whether VS can develop it.
    Anyway, if you want to develop an Game, you should choose your library first, for example, for DirectX, you can refer to the following blog:
    http://blogs.msdn.com/b/vcblog/archive/2012/09/25/directx-graphics-development-with-visual-studio-2012.aspx
    Or XNA:
    https://msdn.microsoft.com/en-us/library/bb975644(v=xnagamestudio.31).aspx
    However, none of them are pending on VS. You need the SDK and also VS installed together then you can develop Games.
    By the way, this is not the right forum for your issue, we talk about install/uninstall Visual Studio issues here.
    Best regards,
    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How do i convert a picture back to a image array and extract the coulor table.

    Been trying to do so for the past 2 weeks and the folks at NI India also are unable to support me. please help. I am on labview 6.1
    Ankur

    I suppose that you are talking about a LV picture.
    My opinion is that LV 6 was an absolute pity for picture management. LV 7 is only a pity.
    Your problem could be solved in a breath using a few of the IMAQ vision tools. Unfortunately, NI has decided to keep separated its image management tools from its graphic development environment. I think that this situation should be discussed...
    With LV 6, there is probably a solution that use the Flatten to String function, convert the string to a 1D-array of bytes, remove the 32 bytes or so the Flatten function has added before the actual picture bytes, then reshape the array according to the initial picture size. I have done that in the past for a 8byte picture. Not sure if it is as simple for a colored picture. Not sure either if I'll have some time to spare on the problem today.
    Hope you will find here some more constructive help !
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        

  • How to read EDF files in LabVIEW?

    Hi all.
    I'm trying to read a EDF file (brain signals, EEG) into LabVIEW but I can't figure out how to do it. Would like to meet this challenge without converting the EDF file before processing. 
    Are there someone out there who can help me? I'm using LabVIEW 2010
    Kind regards
    Solved!
    Go to Solution.

    Hi Clausny,
    LabVIEW supports numerous data types through DataPlugins available here (login may be required), this includes the *.EDF (European Data Format).
    Supported Features:
    EDF (European Data Format) files. 
    EDF+ files.
    Large blocked data files.
    Writing of EDF files.
    All channels are saved into one channel group.
    Saving of all numeric and waveform channels.
    All channels must have the same channel length and the same "Waveform x-step width" property value.
    "Waveform x-name" and "Waveform x-unit" properties will be ignored when writing to EDF file.
    Non-Supported Features:
    Annotations. Those will be supported in a later version.
    The EDF DataPlugin also integrates into the NI Biomedical Startup Kit. The Biomedical Startup Kit uses the LabVIEW graphical development environment to analyze biomedical signals.
    Also the link here gives a brief introduction on how to use DataPlugins with your version of LabVIEW.
    Hope this helps with your application.
    Thanks
    Jamie
    Jamie S.
    Applications Engineer
    National Instruments

  • [SOLVED] SLiM locked in Virtual Box

    So I installed the newest iso, got things ok in terminal and installed SLiM, but I'm stuck at the SLiM login. Neither root nor user works. I've tried console as username to force xterm, but all I get is a black screen with an X for a mouse. tried exit and nothing happened. I really need to get back to no GUI so I can edit the options for SLiM and get myself started. I'm going to be running Razor-QT on top of Openbox and SliM as login. Problem is I can't install Razor until I can visit the AUR..... Anyway, if someone can get me the hell out of slim I'd appreciate it.
    Last edited by al0ngcam3asp1d3r (2012-08-01 00:25:50)

    TheCuban wrote:Type "console" as a username, should give you a console. If it doesn't, it it kinda "freezes" on you, then hit ALT + F1 and you should be good to go!
    You freaking rock bro. I'm sorry to be a pain in the ass to everyone, but most of my experience is in Ubuntu (I know that's like the f word) but I've run arch before and adored it, and have decided to use it as the base of a new distro which is like Bugtraq (I'm the graphics developer for the new version in dev) built on Arch for speed, so I'm I'm going to probably ask a lot of questions, however I am good at RTFM so I'll try not to ask any stupid questions.

Maybe you are looking for

  • How to populate a form from an xml file with multiple records

    I want to be able to create a single form that will add pages as needed based upon the number of records being imported from an xml file. I have an IRS form that does this exactly, but I do not know how to re-create it.  I entered data into the form,

  • Question about Forte...

    Ok, I'm pretty sure this is the wrong forum to ask, but I haven't found a better one. I apologize for that. Now, I've just downloaded and installed Forte for Java CE. It installs fine, when I run it it shows the nice pic where it loads and initialize

  • Bluetooth to iphone to ipod touch

    When trying to bluetooth iPhone with Sons iPod touch. The two devices are unable to connect to each other. Please advise on possible resolution ? Thanks

  • Exception while working with Tibco adapter for Tuxedo!!

    Dear friends,:-) Greetings! I am facing an exception while working with "Tuxedo Adapter". I have installed TIBCO Adapter for Tuxedo on my machine which has both bea_Client and Server. I am trying to do a PurchaseOrder POC, which is already given in o

  • How to display sample text using dynpage ?

    Hi All,          I am developing the portal using dynpage technology.  I do not know whether I am posting this thread in the right place. How to display a sample text in the portal using dynpage? I have written it using HTMLFragment.  But it could no