🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #309

Re: Java program to simulate circuits.. help with graphics area ..

#309
From: Jim Sculley
Date: Sat, 05 May 2001 04:41
32 lines
2513 bytes
Aaron T wrote:
> 
> Okay I have got to build a program that will be able to draw gates to the
> screen (such as AND, OR, NOT etc) and flip flips, sources etc, pretty basic
> stuff. Also pins must be recorded on the canvas as the gates should be able
> to be connected.
> 
> I've been hard pressed to find a tutorial that deals with anything past the
> very basics of 2DGraphics in java, like drawing to screeen and so forth..
> 
> What I need to be able to do is draw to screen, but then later have the user
> able to select any gate and move it around. I kind of know how to do the
> moving with a update() or paint() method that is called by a mouse movement,
> but how do I make each shape (I'm using GeneralPath as the shape for a
> certain gate) a seperate 'object' that is able to be selected at will?

One approach is to make the various objects individual classes that know
how to paint and size themselves.  You could subclass JPanel and
override paintComponent(), getPreferredSize(), and perhaps some of the
other getXXXSize methods.  With this approach you can attach the
listener right to the component itself, and you don't have to bother
with figuring out which area of a single image (with several objects
painted on it) was clicked.

Once you have the components worked out, you will likely want to create
a custom layout manager that lets you drag things around, and perhaps
snaps to a 'grid' to make it easy to align components.  You can use a
'null' LayoutManager fo testing, but a custom layout will give you
better control.


Jim S.
Technical Details
Message-ID: <3AF3847C.CD977D7@abraxis.com>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy.com!news1
References: <3af36d74$0$25514$7f31c96c@news01.syd.optusnet.com.au>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113ae9,b3cb45071f1608e7
X-Google-Attributes: gid113ae9,public
X-Google-Thread: 10d6db,b3cb45071f1608e7
X-Google-Attributes: gid10d6db,public
X-Google-ArrivalTime: 2001-05-04 22:22:36 PST
Path: arc1-ca.pugleaf.net!newsfeed.google.com!newsfeed.stanford.edu!pln-w!spln!dex!extra.newsguy.com!newsp.newsguy.com!news1
From: Jim Sculley <niceguy@abraxis.com>
Newsgroups: aus.computers.java,comp.lang.java.help
Subject: Re: Java program to simulate circuits.. help with graphics area ..
Date: Sat, 05 May 2001 00:41:32 -0400
Organization: http://extra.newsguy.com
Lines: 32
Message-ID: <3AF3847C.CD977D7@abraxis.com>
References: <3af36d74$0$25514$7f31c96c@news01.syd.optusnet.com.au>
NNTP-Posting-Host: p-763.newsdawg.com
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.73 [en] (WinNT; U)
X-Accept-Language: en