The Artima Developer Community
Sponsored Link

Java Answers Forum
Graphics

2 replies on 1 page. Most recent reply: Feb 25, 2005 4:45 AM by Dimitris Paras

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Dimitris Paras

Posts: 12
Nickname: dimpars
Registered: Feb, 2005

Graphics Posted: Feb 24, 2005 8:01 AM
Reply to this message Reply
Advertisement
I have developed a standalone application using, new project->standard->java application, in netbeans developer enviroment. I tried to draw my results with the following lines...

Graphics g;
Color col1= new Color(255,100,100);
g.setColor(col1);
g.drawLine(x1,y1,x2,y2);

all the above lines are integrated in a method called public void paint(). paint() method is in the class.Main of my project.

My problem is that through the
public static void main(String[] args) {}

i cannot call paint() because paint() is not a static one to call it from public static void main(String[] args). If i change paint() to static paint() the compiler finds error.

The only thing i want to do is to draw some lines after my algortihm terminates. :) What should i do?


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Graphics Posted: Feb 24, 2005 10:38 AM
Reply to this message Reply
1. Wich eror appears if you make paint static?

2. What is the sense of all this?
You did not create a frame or anything else to draw something
You didn't initialize g (in fact, you can't. You must GET g from somewhere)


Use a class like this:
import javax.*;
import java.awt.*;
import java.awt.geom.*;
 
public class MyFrame extends JFrame {
    public MyFrame () {
        this.setSize (640, 480);
    }
    public void paint(Graphics g){
        super.paint (g); // this method overrides the standard paint method of the JFrame, so we better call the standard method first
        g.draw(new Line2D.Double (60,50, 300, 500);
    }
    public static void main (String[] args} {
        //do something important
        new MyFrame().show();
    }
}



This is a very rude example.
Normally you would create a class extending JPanel and paint on the panel (of course the panel needs a frame or diaog as parent), but it shows the basics.

Dimitris Paras

Posts: 12
Nickname: dimpars
Registered: Feb, 2005

Re: Graphics Posted: Feb 25, 2005 4:45 AM
Reply to this message Reply
thanks this is fine for the begining! i would like to ask you sthn else. When i run the program it never ends and i have to close the window by pressing button x. Is it normal?what should i do? thx again!!!

Flat View: This topic has 2 replies on 1 page
Topic: online powerpoint synchronization Previous Topic   Next Topic Topic: Is Java...

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use