Thread View: aus.computers.java
4 messages
4 total messages
Started by Aaron T
Sat, 05 May 2001 02:54
Java program to simulate circuits.. help with graphics area ..
Author: Aaron T
Date: Sat, 05 May 2001 02:54
Date: Sat, 05 May 2001 02:54
20 lines
2004 bytes
2004 bytes
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? Any help on the forum, email or pointers to websites would be great.. I've sifted the sun site, used the books I've bought and nothing seems to go into any great detail on this. Thanks very much Aaron Todd
Re: Java program to simulate circuits.. help with graphics area ..
Author: Jim Sculley
Date: Sat, 05 May 2001 04:41
Date: Sat, 05 May 2001 04:41
32 lines
2513 bytes
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.
Re: Java program to simulate circuits.. help with graphics area ..
Author: TOK Logic Australia Software Eng...
Date: Sat, 05 May 2001 07:20
Date: Sat, 05 May 2001 07:20
9 lines
1549 bytes
1549 bytes
Don't overload update - repaint when you need to. You can use any image
or imageIcon, maintain PositionX and PositionY as a function of Screen
width, and Screen Height. Use Java 2D Drag and Drop if you need to, but
I think you can do it with Java 1.1.
see http://www.tok2.net
Cheers,
Terry O'K.
Re: Java program to simulate circuits.. help with graphics area ..
Author: Joel Wellington
Date: Mon, 07 May 2001 05:12
Date: Mon, 07 May 2001 05:12
39 lines
2661 bytes
2661 bytes
You by any chance dont go to Curtin University in Perth do you? I did a unit where I had to do the exact same program. I made each type of gate an object. The gates methods included draw, position and logic state. Draw a staright line to an input pin on a gate and have seperate applet 'state' which calculates the login. This way only need an edit state and a calculaate state so you dont need to calculate at every drawing update. Joel On Sat, 5 May 2001 10:54:48 +0800, "Aaron T" <toddam@dingoblue.net.au> 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? > >Any help on the forum, email or pointers to websites would be great.. I've >sifted the sun site, used the books I've bought and nothing seems to go into >any great detail on this. > >Thanks very much >Aaron Todd > > > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads