Charlie Wall

Greenhorn
+ Follow
since Nov 06, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Charlie Wall

Hi guys

I have a small (well big to me) problem that I need some help with
I have a math expression in a String, that I want to split into 4 pieces as in the following example:

String math = "23+4=27"
int num1 = (23 STORES HERE)
int num2 = (4 STORES HERE)
String operator = (+ STORES HERE)
int answer = (27 STORES HERE)

Note that the operator can be either + - * /

I appreciate your help
9 years ago
Thanks a lot! That cleared things out.
9 years ago
Hi guys

I need help solving the following problem: How can I make a call to paintComponent within the JPanel-class, from another Class?

In class TestClass:



In class MyPanel:

9 years ago

Campbell Ritchie wrote:… and welcome to the Ranch

If your freehand drawing is not a Polygon, you should create an object to encapsulate it. Add that object, which encapsulates all the points, to the List.
You may do well to create a Shape (or similar) interface and have all your different shapes implement that interface.

Only use // comments for short things. For anything of any length use /* comments */. That way you won't have problems with line length. I shall try to change your comment's format.




Thank you, I will use /* instead of // in the future.
My drawing is not a Polygon, it is a line. Mayby I should change it to Polygon instead? Do you think that will solve my problem?
9 years ago
I have a problem with my application that is giving me headace. I hope someone can help me understand what is going on.

I have a paint program in Java where I can draw objects. The objects are stored in an arrayList. In the menubar the user can chooce "Back", which means the last item in the arrayList is removed. After that I want the program to loop through the arrayList and draw the remaining items.

My problem is that when I try to do that it will not work from the menu (menuItem2). If I instead add the code to one of the colorpanels (yellowPanel), from where the user can pick colors, it works fine.

menuItem2 uses ActionListener and yellowPanel uses MouseListener.




In class Draw:




In class FreeHand (class Rectangle looks the same except for it is using drawRec instead of drawLine)


9 years ago
I am buildning a paint application in java, where the user can choose from a combobox wheather he/she wants to draw a rectangle or by free hand. The objects are stored in an arrayList. The user can also choose in the menubar to go back one step, which means to remove the last drawn item from the arrayList and then loop through the arraylist to draw the remaining objects.
It works fine with rectangles. When I create a rectangle it creates only one rectangle, which I add to the arrayList.
My problem is with the free hand. When I draw by free hand (using mousePressed and mouseDragged) I add every "dot" of the line as an object. Which means that when I remove the last item in the arrayList it only removes one dot of the line, not the whole line.
I need to add the dots together as one line, but how can I do that?

Thank you for your help, I really appreciate it.


9 years ago