Results 1 to 3 of 3

Thread: drawing on my swing window

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800

    drawing on my swing window

    ok i have my swing window...but now i'd like to draw shapes on it, like i've done in applets. i've been trying some different combinations of stuff, but they dont' seem to work, is it a different process with a window?

    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class window
    {
        public static void main(String [] args)
        {        
            JFrame frame = new JFrame("Ants");
            Dimension WindowSize = new Dimension(200, 200);
            
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setSize(400,400);
            frame.setVisible(true);
        }
    }
    thanks guys

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You should place some kind of JPanel in the frame's content pane. This panel ought to be of your own class (derived from JPanel). Then you can override the paint method.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    You can override the paint() method with any class that you create that is a subclass of the following.
    [list=a][*]Canvas class[*]Subclasses of the Component class that are not part of the AWT[*]Container class and it's subclasses: Window, Frame, Dialog, Panel, Applet[/list=a]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width