How to initialize Graphics object without using paint method??

This is a code to make sierpinski triangle using IFS.
I am using a button called "Iterate" which calls funtion paint() .
paint1() gets called from paint on pressing the button.
I want to convert a square into Sierpinski triangle by iterations.
I want to make a square first .If I put that code in paint() then it gets called everytime.
so problem lines are: Graphics g;
g.drawLine(0,0,99,0);
g.drawLine(0,0,0,99);
g.drawLine(0,99,99,99);
g.drawLine(99,0,99,99);
it gives error as object not initialised.
rest of the working code is as follows.
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class mys31 extends Applet implements ActionListener{
String msg ="";
Button iterate;
int i,j;
double [][]t;
double [][]s;
double []a;
double []b;
double []c;
double []d;
double []e;
double []f;
public void init() {
t=new double[100][100];
s=new double[100][100];
a=new double[]{0.5,0.5,0.5};
b=new double[]{0.0,0.0,0.0};
c=new double[]{0.0,0.0,0.0};
d=new double[]{0.5,0.5,0.5};
e=new double[]{1.0,1.0,50.0};
f=new double[]{1.0,50.0,50.0};
for(i=0;i<100;i++)
t[0]=1.0;
t[0][i]=1.0;
t[99][i]=1.0;
t[i][99]=1.0;
for(i=0;i<100;i++)
for(j=0;j<100;j++)
s[i][j]=0.0;
iterate = new Button("Iterate");
add(iterate);
iterate.addActionListener(this);
} // end init
public void actionPerformed(ActionEvent ae){
String str = ae.getActionCommand();
if(str.equals("Iterate"))
msg=" working";
repaint();
} //end of action Performed
public void paint (Graphics g) {
g.drawString(msg,200,200);
paint1(g);
} // end paint
public void paint1(Graphics g)
int j=0,i;
for(i=0;i<100;i++)
for(j=0;j<100;j++)
if(t[i][j]==1)
s[(int)(a[0]*i b[0]*j e[0])][(int)(c[0]*i + d[0]*j + f [0])]=1;
s[(int)(a[1]*i b[1]*j e[1])][(int)(c[1]*i + d[1]*j + f [1])]=1;
s[(int)(a[2]*i b[2]*j e[2])][(int)(c[2]*i + d[2]*j + f [2])]=1;
g.setColor(Color.red);
for(i=0;i<100;i++)
for(j=0;j<100;j++)
t[i][j]=s[i][j];
s[i][j]=0.0;
if(t[i][j]==1.0)
g.drawLine(i,j,i,j);
}//end paint1
} // end class

I don't see a question here.
Anyway I would suggest using double buffering - drawing on a BufferedImage and drawing the BufferedImage inside paint.
You will have to call repaint every iteration.

Similar Messages

  • Graphics without using paint

    Hi!
    I want to draw somthing without using paint. Does anyone know how to do that?
    f.eks
    I want to call a function with some parameters, and then the function draws something for me with these parameters.
    Thanks for helping:)
    Best regards
    Stian

    Sure... You could use the function to generate an image file and load that using ImageIcon and pass that to a JLabel.
    But that's not going to work nearly as fast as just using paint.

  • How to connect to AD without using ADWS?

    How to connect to AD without using ADWS? Is it possible to do it? If yes, can teach me how to connect to AD and find their attributed?

    Hi Noobycy,
    There are few tools to find AD attributes without ADWS. See options you have below
    1.ADFIND -
    http://www.joeware.net/freetools/tools/adfind/  This is a command Line tool
    2.
    The ADSIEDIT tool
    from the Windows Support Tools is a great tool to "explore" the AD.
    http://technet.microsoft.com/en-us/library/cc731547.aspx
    3. ADUC -
    http://www.boostsolutions.com/blog/how-to-find-attributes-of-objects-in-active-directory/
    Regards, MassonTech

  • How we generate Surrogate Keys without using identify column

    Hi All,
    How we generate Surrogate Keys without using identify column.
    Regards,
    Manish

    There are various options
    1.IDENTITY columns - simplest to implement
    2. Using NEWID(), NEWSEQUENTIALID() functions (if you want to use GUID values as surrogate keys)
    3. SEQUENCE object (if SQL 2012 and above)
    4. Using custom functions to generate keys yourself
    This is an good article which compares use of GUIDs against integers as surrogate keys
    http://blog.jonathanoliver.com/integers-vs-guids-and-natural-vs-surrogate-keys/
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How do i install opensolaris without using the virtual box??

    hi.
    i am new to solaris
    i am currently using a windows XP OS
    i got down the opensolaris cd from SUN
    how do i install opensolaris without using a virtual box ?

    The OpenSolaris CD is a "Live CD". You can boot off of the CD, and either run the OpenSolaris operating system directly, or you can select the "Install" icon on the LiveCD desktop. You can find full instructions here: http://dlc.sun.com/osol/docs/content/IPS/getst1.html
    Do you want to keep your Windows OS on the disk? If so, then you want to follow the instructions for partitioning your disk (unless you already have a spare partition).
    -- Alan

  • How to create an instance for RemoteSession without using create() method

    How to create an instance for RemoteSession without using create() method?

    What's RemoteSession? Not in the JDK. And does the question have anything to do with concurrency?

  • Hello! I'm out of the country and all my iWeb information is on my computer at home. Now I need to make changes on the webpage... how can i do that without using the computer i made the page on? Thank you!!

    Hello! I'm out of the country and all my iWeb information is on my computer at home. Now I need to make changes on the webpage... how can i do that without using the computer i made the page on? Thank you!!

    iWeb uses the domain.sites2 files to store its assets.
    You'll find it here :
    ~/Library/Application Support/iWeb/
    where ~ is your Home directory.
    If you take a computer with you, you have to store that file in the same location.
    It's not different from taking documents with you if you want to edit them.
    A solution is to remotely control your computer at home.
    TeamViewer, LogMeIn, Apple Remote Desktop or any VNC application you can use, like "Chicken of the VNC".

  • Note:304522.1 How to Move Queue Tables without using export import

    Trying to use the pkg available in Metalink "Note:304522.1 How to Move Queue Tables without using export import"
    Using the 10.1.0.x and upwards Package, I'm getting the following error on a single consumer queue table with an xmltype payload:
    SQL> exec move_aqt.move('XFORM_TEST_INT','INTERFACE_XML_QUEUE','SMALLBLOCK');
    BEGIN move_aqt.move('XFORM_TEST_INT','INTERFACE_XML_QUEUE','SMALLBLOCK'); END;
    ERROR at line 1:
    ORA-20000: ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "SYS.MOVE_AQT", line 652
    ORA-06512: at line 1
    We've tried in multiple environments, always with the same results.
    Trace file shows:
    *** 2006-11-08 10:06:47.154
    *** SERVICE NAME:(SYS$USERS) 2006-11-08 10:06:47.147
    *** SESSION ID:(379.954) 2006-11-08 10:06:47.147
    qtable move procedure starting execution at 08-11-2006 10:06:47 for queue table XFORM_TEST_INT.INTERFACE_XML_QUEUE
    qtable move procedure experienced an exception at 08-11-2006 10:06:47
    qtable move error message ORA-06502: PL/SQL: numeric or value error
    qtable move procedure ended execution at 08-11-2006 10:06:47
    Can anyone help with this? Has anyone used this before successfully (or not successfully). We urgently need this working today to test moving our queue table into a tablespace with a smaller block size for performance reasons in production.
    Thanks for the help!
    Tony

    Thank you,
    Yes we've done that. They've confirmed a problem with the links/scripts on the note. The 10.1 and up version was not really 10.1 and up.
    As they would not have a new version available in time for the move we needed to perform, we switched our approach to using dbms_redefinition instead.
    Thanks for the reply,
    Tony

  • HT4993 how to unlock my passcode without using itunes

    how to unlock my passcode without using itunes

    cannot be done without itunes
    http://support.apple.com/kb/ht1212

  • How to connect from java without using oracle client installation

    hi ,
    Please tell me how to connect from java without using oracle client
    Thanks & Regars

    http://www.orafaq.com/wiki/JDBC#Thin_driver

  • HT4061 I bought my mom an iPad for Christmas this year.  We can't use it as it will not recognize her passwords.  How do I reset it without using passwords.  I want this thing wiped clean, just like it came from the store so that I might start over.

    I bought my mom an iPad for Christmas this year.  We can't use it as it will not recognize her passwords.  How do I reset it without using passwords.  I want this thing wiped clean, just like it came from the store so that I might start over.  This is very frustrating!

    How can I unlock my iPad if I forgot the passcode?
    http://www.everymac.com/systems/apple/ipad/ipad-troubleshooting-repair-faq/ipad- how-to-unlock-open-forgot-code-passcode-password-login.html
    iOS: Device disabled after entering wrong passcode
    http://support.apple.com/kb/ht1212
    How can I unlock my iPad if I forgot the passcode?
    http://tinyurl.com/7ndy8tb
    How to Reset a Forgotten Password for an iOS Device
    http://www.wikihow.com/Reset-a-Forgotten-Password-for-an-iOS-Device
    Using iPhone/iPad Recovery Mode
    http://ipod.about.com/od/iphonetroubleshooting/a/Iphone-Recovery-Mode.htm
    You may have to do this several times.
     Cheers, Tom

  • Hey guys i please i need a help on my ipad. i have received an ipad from anonymous person but she has already logged in to iclouds, since i dont know her password how do i sign out without using password on ios 8?

    Hey guys i please i need a help on my ipad. i have received an ipad from anonymous person but she has already logged in to iclouds, since i dont know her password how do i sign out without using her password on ios 8?

    You can't. Your mysterious benefactor must remove the device from her (I guess you know it's a her?) iCloud account by logging into icloud.com, going to Find my iPhone and removing from there.
    Matt

  • How to fill polygon without using paint component ?

    hello,
    i have a class called "public class Arrow2DRhombus implements Shape" with the following constructor:
    public Arrow2DRhombus(Point2D begin, Point2D end) {
            this.x1 = begin.getX();
            this.y1 = begin.getY();
            this.x2 = end.getX();
            this.y2 = end.getY();
            this.initArrow();the code for .initArrow():
    private void initArrow(){
            int length = (int) Math.sqrt(Math.pow(Math.abs(x1-x2),2) +
                           Math.pow(Math.abs(y1-y2),2));
            length=length-19;
    Polygon poly = new Polygon();
            poly.addPoint((int) x1,(int) y1);
            poly.addPoint((int) x1+ length,(int) y1);
              poly.addPoint((int) x1+ length+10,(int) y1+5);
              poly.addPoint((int) x1+ length+20,(int) y1);
              poly.addPoint((int) x1+ length+10,(int) y1-5);
              poly.addPoint((int) x1+ length,(int) y1);
            double rad = this.calcAngle((float) this.x1,(float) this.y1,(float) this.x2,(float) this.y2);
            AffineTransform tx = AffineTransform.getRotateInstance(rad,x1,y1);
            this.arrow = tx.createTransformedShape((Shape)poly);
        }is there a way i can fill the polygon "poly" with the code above .
    i know that i can fill a polygon using when using paintcomponent(Graphics g)
    but here how can i do it.
    10x

    I don't really understand the question. "Filling" a shape implies (to me) that you have a Graphics Object and are doing custom painting. So you would do this:
    a) in the paintComponent() method of a component
    b) in the paintIcon method of an Icon
    c) by painting onto a BufferedImage
    I'm sure there are other ways, but I don't think you just "fill" a Shape object.

  • How to Set Distinct SQL Clause on View Object without using Expert Mode.

    Hi to all Actually i have a View Object usign 3 entities
    if i use expert mode in my VO, it generate
    QRSLT WHERE
    instruction and force to include all columns on my dynamic where clause on select statement i can't include columns because get me duplicate rows
    How i can include disctinct clause without usign expert mode or any other solution?
    Note that in normal mode without expert mode QRSLT WHERE is not generate and all work fine
    For example
    select * ( select id , name from table) QRSLT WHERE loc = ..
    if i use expert mode it generate QRSLT WHERE and if loc is not predicated colums get me and error :
    ( ORA-00904: invalid identifier )
    in simple mode of View Object all work fine..
    Any suggestion on It will be appreciate.....
    Tnx

    My problem is that when use expert mode
    it's change simple select statement for a select that use
    select * from (select column....)
    qrslt WHERE (column=somevalue)
    this kind of select force me to include all where conditions of qrslt on my select columns and this get duplicate rows
    thats beacuse i need include distinct without use expert mode
    Anny Help on this?

  • How to use paint method to draw in many componets.

    Hi!
    I have code like this:
    public class MainPanel extends JPanel{
       JPanel p1;
       JPanel p2;
       public MainPanel(){
           super(new BorderLayout());
           p1 = new JPanel();
           p2 = new JPanel();
           add(p1 , BorderLayout.Center);
           add(p2 , BorderLayout. West);
           setVisible(true);
    @Override
        protected void paintComponent(Graphics g) {
           g.setColor(Color.red);
           g.fillrect(10,10,10,10);
    }This code is onle an example. Supose, this code will paint black rectangle on "main panel" to which p1 and p2 are added. What should i do to be able to paint this rectangle on p1 or p2 without creating separate classes in which i will override paintComponents() method for p1 and p2. I would like to avoid creating separete classes for each panels. Is there any way to do that using one paint Components method. Thanks in advance for all respone.

    (where's Darryl when you need him?)Erm, Pete, since when did I become an expert lol?
    Lost my hard disk, its been hiccuping for a couple of weeks now. I'm running on an old 20 GB PATA with a 5GB c drive. No IDE, no offline Javadoc. I'll get a HDD in the morning, but I hope I can spin up the old disk at least once and recover the last week's "work" ... just fun stuff actually.
    Why does this code draw rectangles just for split second?repaint() (and consequently paint(), paintComponent() and other painting methods) may be called by the system any time it is detected that the component needs to be repainted. Since you do not have a override for paintComponent, it will perform its default painting and paint the entire component, wiping out your rectangle.
    For persistent drawing on a JPanel or JComponent I know only one way: override paintComponent. If you need to avoid this, you could go with morgalr's suggestion to use JLabel.
    For this you would draw the triangle/rectangle/whatever to a BufferedImage, then call label.setIcon with a new ImageIcon constructed from the BufferedImage.
    Also, avoid obtaining a Graphics reference via getGraphics. During the lifetime of a visible component, various different Graphics references may be passed into the paintComponent method, so the reference you obtain may not be current. getGraphics can also return null.
    luck, db

Maybe you are looking for

  • Acrobat Pro 9.1 no longer creates PDFs from Word 2007

    I upgraded from Acrobat 7 to 9 specifically to gain more control over settings when making PDFs from Word 2007. This worked as I had hoped until the 9.1 vulnerability upgrade was installed. Now it will no longer create PDFs from Word 2007 documents a

  • How do I find out about my warrenty on here because I cannot find my paper work?

    I just dropped my phone and my whole screen cracked and I need to find out how I look up my warrenty so I can know what I have to do or pay for a new phone?

  • Using Store Business Document on parked FI documents

    When an FI document is parked the Store Business Document is not active. I have searched for config where this can be turned on, but I can not find anything. Is there a way to store atachments to an SAP document before it is posted? We are using Arch

  • Problem on installing Windows XP

    I am new to mac, and have been using PC all my life. I know an ok amount on the mac but not too well. I followed the instructions in Boot Camp Assistant and created a partition, then inserted my Windows XP Home Edition SP1 cd and ran the installation

  • IOS 7.0.4 I-Messages not delivered

    Despite trying all sorts of resets, & shutdowns, I-Message continues to say "not delivered".  The not delivered message comes up straight away. What am I missing