Rob Camick

+ Follow
since Jun 13, 2009
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rob Camick

I see 4 parameters in the PreparedStatement, but you only set values for 3 of them.
4 hours ago
You can add a TableModelListener to the TableModel of your JTable.

When data in a cell is changed an event will be generated and you can then update your database.

See this answer for an example.

Or you may want to use a Table Cell Listener instead of the TableModelListener, for the reasons listed in the link.

5 days ago

a Buffered Image which you have to draw() onto a Component like a JPanel.

You can create an ImageIcon using the BufferedImage and then add the Icon to the JButton.
5 days ago
Swing is built on top of AWT so Swing does use may AWT glasses.

However, there is no need to use AWT components. All the AWT components have been replaced by Swing components, so use the Swing components.

While learning to use Swing components you will also learn basic AWT concepts.

can you please suggest me a good swing tutorial?

See: Creating a GUI with JFC / Swing
1 week ago

I want to draw a vertical  line on the graph and make it move from left to fright depending on the arrow keys.

And now you are changing the requirement.

Your first requirement was to add dots, so you could use either approach.

Now you want to dynamically change the drawing, which means you can't use a BufferedImage.

You need to use the other approach to dynamically recreate the drawing. So you need to use the `Draw On Component` example from the link I gave you. You will need to:

1. keep the dots you want to paint in an ArrayList
2. have another property that will change the location of the vertical line, something like changeLinePosition(). You would pass a positive/negative value to change the location.

1 week ago

Should the casting part be doing so that scope of g2 is available to painting the empty graph?

Any time you want to paint to the BufferedImage you need access to the Graphics2D of that image. So you have two options:

1. When you create the BufferedImage you also update in instance variable in your class for the Graphics2D object, the same way you do for the "image" variable
2. You just access the Graphics2D object in each method that wants to paint to the BufferedImage

Using the second approach you would do:

1 week ago

while holding ctrl key , it results in 2 , and when not pressing control key , its still 2.

Yes, because you are just printing a static value from the ActionEvent class.

You need to invoke the getModifiers() method of the ActionEvent to see if any modifier key was used when the button was clicked.

Here is a basic ActionListener that displays the modifier keys that were pressed when the button was clicked:

1 week ago

but a lot of the stuff is not clearly explained.

Don't blame your lack of understanding on the language! Spend more time reading the tutorials and learning instead of posting unnecessary comments in the forum.

You did NOT ask a single question about the link I provided you earlier. We can't guess what you find confusing.

The code you posted above looked nothing like the code from the examples I gave you. Learning by example is a good way to learn. Most people would start with the working example and then customize the example to do what they want.

Your original question complained about not being able to draw multiple dots. Yet the code you posted above had all kinds of complex code related to drawing a graph.

Learn first how to simplify the problem and solve one problem at a time.

The fewer the lines of code you look at, the easier it is to understand.
1 week ago

I am using the buffer method

You are missing the concept of using a BufferedImage.

The sole purpose of the paintComponent() method is to paint the BufferedImage.

Other events in your code will paint ON the BufferedImage.

I simplified the example from my link.

The code below will simply use a Timer to paint a new "dot" to the BufferedImage every second:

Understand how the code works and modify your code so you are able to paint your dots based on your requirements.

Once that works, then you can modify the "createEmptyImage()" logic to paint your default graph lines onto the BufferedImage.
1 week ago
1. With Swing you override the paintComponent() method of a JPanel
2. A painting method should NOT do I/O. You want the method to be efficient since you can't control when the component will be repainted.
3. Read the Graphics API. There is a drawImage(…) method that allows you to specify the size of the image to be painted. So you would use the getWidth() and getHeight() methods of the JPanel to determine the image size.
1 week ago

The purpose of the program is to randomly generate a dungeon.

Which is why you pass parameters to the class so it can be painted in your randomly generated location.

I am differentiating a door from a continuing corridor by drawing an arrow to represent the continuing corridor.

We can only suggest a solution based on the information provided. In the code provided you are simply drawing a Rectangle so I suggested a simpler approach.

If you need a GeneralPath it doesn't change the suggestion. A GeneralPath is a Shape and you can still construct it in the constructor, not in the painting method. So you can still use the getShape() method and the contains() method.
1 week ago
Not really sure what all your code is doing but:

1. your GeneralPath is really just a rectangle with a width and height of 10
2. custom painting code should never update properties of your class. You can't control how often the object will be painted
3. you can pass parameters to your class to control where the object is painted

Using the above suggestions your class might look something like:

1. you pass the x/y location as a parameter
2. You use a Shape to control the object you want to paint. This will allow you to use a GeneralPath, Rectangle, Oval etc.
3. In this case it is easier to just use a Rectangle
4. The getShape() method was added. Now as you iterate through the ArrayList you invoke the getShape() method on each instance and then invoke the contains(…) method.
1 week ago

How do I implement the "isopaque override" technique?

The easiest way is to just use setOpaque( false ).

But it still won't help.

Read the "Additional Paint Properties" section found in: Painting in AWT and Swing.
1 week ago

I am using an ArrayList to store references to Graphical Objects drawn with a GeneralPath method

Just store the GeneralPath object.

You just invoke the contains(…) method on the GeneralPath object as you iterate through the ArrayList.
1 week ago