Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #15589 > unrolled thread
| Started by | bilsch <bilsch01@gmail.com> |
|---|---|
| First post | 2012-06-25 15:31 -0700 |
| Last post | 2012-06-29 13:07 -0700 |
| Articles | 15 on this page of 75 — 16 participants |
Back to article view | Back to comp.lang.java.programmer
I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-25 15:31 -0700
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-25 16:15 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-25 16:47 -0700
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-25 18:10 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-26 13:04 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-26 14:01 -0700
Re: I need a different approach - suggestions please Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-26 17:21 -0400
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-27 14:44 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-27 14:56 -0700
Re: I need a different approach - suggestions please Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-06-27 18:13 -0400
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-27 18:48 -0700
Re: I need a different approach - suggestions please Patricia Shanahan <pats@acm.org> - 2012-06-27 15:21 -0700
Re: I need a different approach - suggestions please Jail Bush Cronies <do.not@ask.me> - 2012-06-27 18:46 -0400
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-26 14:25 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 14:32 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-26 17:49 -0400
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 15:20 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-27 17:30 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-27 18:09 -0700
Re: I need a different approach - suggestions please Wanja Gayk <brixomatic@yahoo.com> - 2012-07-02 11:21 +0200
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-25 18:36 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-26 13:24 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 13:49 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-26 14:04 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 14:34 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-26 16:26 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 16:47 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-26 20:04 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-26 22:18 -0400
Re: I need a different approach - suggestions please Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-06-26 22:59 -0400
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-27 21:30 -0400
Re: I need a different approach - suggestions please Wanja Gayk <brixomatic@yahoo.com> - 2012-07-02 11:32 +0200
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-07-02 09:47 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-26 20:06 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-27 11:42 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-27 14:09 -0700
Re: I need a different approach - suggestions please Patricia Shanahan <pats@acm.org> - 2012-06-27 15:11 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-27 21:59 -0400
Re: I need a different approach - suggestions please Devil's Advocate <legal@hell.org> - 2012-06-27 22:17 -0400
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-27 21:40 -0400
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-27 19:12 -0700
Re: I need a different approach - suggestions please Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-06-27 20:47 -0500
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-27 19:12 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-27 21:28 -0400
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-27 19:14 -0700
Re: I need a different approach - suggestions please Hydrangea <hydrangea393@foo.mail.quuzzle.edu> - 2012-06-27 22:28 -0400
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-27 21:05 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-27 22:32 -0400
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-27 21:08 -0700
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-26 14:10 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 14:35 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-26 17:51 -0400
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 15:20 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-26 19:35 -0400
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-26 16:44 -0700
Re: I need a different approach - suggestions please Arne Vajhøj <arne@vajhoej.dk> - 2012-06-26 22:06 -0400
Re: I need a different approach - suggestions please Patricia Shanahan <pats@acm.org> - 2012-06-27 08:15 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-27 18:36 -0700
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-27 18:54 -0700
Re: I need a different approach - suggestions please B1ll G4tes <wm.gat3s@micro5oft.quux> - 2012-06-27 22:23 -0400
Re: I need a different approach - suggestions please Lew <lewbloch@gmail.com> - 2012-06-28 09:55 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-28 04:02 -0700
Re: I need a different approach - suggestions please Mike Winter <mlwinter@gmail.com> - 2012-06-28 04:55 -0700
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-28 07:33 -0700
[OT] Message IDs (Re: I need a different approach - suggestions please) Mike Winter <mlwinter@gmail.com> - 2012-06-28 08:45 -0700
Re: [OT] Message IDs (Re: I need a different approach - suggestions please) markspace <-@.> - 2012-06-28 09:39 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-28 09:44 -0700
Re: I need a different approach - suggestions please Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-06-28 12:51 -0400
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-28 09:58 -0700
Re: I need a different approach - suggestions please markspace <-@.> - 2012-06-28 07:32 -0700
Re: I need a different approach - suggestions please Roedy Green <see_website@mindprod.com.invalid> - 2012-06-26 03:49 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-26 13:59 -0700
Re: I need a different approach - suggestions please Patricia Shanahan <pats@acm.org> - 2012-06-29 08:12 -0700
Re: I need a different approach - suggestions please Gene Wirchenko <genew@ocis.net> - 2012-06-29 10:02 -0700
Re: I need a different approach - suggestions please bilsch <bilsch01@gmail.com> - 2012-06-29 13:07 -0700
Page 4 of 4 — ← Prev page 1 2 3 [4]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2012-06-28 09:55 -0700 |
| Message-ID | <1081ae45-365f-41ab-a71f-07737f6c4bea@googlegroups.com> |
| In reply to | #15704 |
On Wednesday, June 27, 2012 7:23:02 PM UTC-7, B1ll G4tes wrote: > On 27/06/2012 9:54 PM, Lew wrote: > > GUI actions are all things that happen on the GUI, such as creating > > a 'JFrame', calling 'pack()', playing with 'Graphics', or anything else that > > is part of the GUI. > > Not all Graphics objects are created equal in that regard. Some are > associated with GUI things, e.g. the one you get calling getGraphics on > a JComponent. Some are not, e.g. if you get one to draw on a BufferedImage. And this useful nuance is good when one is ready to delve into the fine points. There are GUI calls that are thread-safe, or so the Javadocs claim. It is relatively harmless as a rule of thumb, however, to assume none are until one is confident of the difference. Much as I buy my mushrooms in the grocery store, otherwise I assume all I find are toxic absent greater expertise than mine. Furthermore, drawing on a BufferedImage is a graphical action, but not /per se/ a GUI one. Transferring that BufferedImage to a JComponent is a GUI action. -- Lew
[toc] | [prev] | [next] | [standalone]
| From | bilsch <bilsch01@gmail.com> |
|---|---|
| Date | 2012-06-28 04:02 -0700 |
| Message-ID | <jshdkn$tc3$1@dont-email.me> |
| In reply to | #15696 |
On 6/27/2012 6:54 PM, Lew wrote:
> bilsch wrote:
>> Lew wrote:
>>> There are a few mistakes in your code.
>>>
>>> You don't need to call 'super()' in the constructor explicitly.
>>> That's what happens by default anyway.
>>>
>>> You called the constructor directly from the 'main()' routine. That means
>>> you called it from the primary thread of the program. You don't know this
>>> yet, probably, unless you've already studied concurrency in Java a little bit.
>>>
>>> The problem is that the GUI won't work right if you do that. You have to
>>> move GUI actions onto the "Event Dispatch Thread" (EDT), a background
>>> thread that the system creates to handle all GUI actions.
>>>
>>> Also, you start all the action from the constructor. That's bad. As its name
>>> implies, a constructor's purpose is to _construct_ an object, not run its logic.
>>> Run the logic after construction completes and the instance is no longer in a
>>> partially-built state.
>>>
>>> And make your indentation consistent with the Java coding conventions (available
>>> on line).
>>>
>>> So all together, you'd do something like:
>>>
>>> public static void main(String[] arguments) {
>>> java.awt.EventQueue.invokeAndWait( new Runnable() {
>>> @Override public void run() {
>>> CalcGUIQ1 calculator = new CalcGUIQ1();
>>> calculator.setVisible(true);
>>> }
>>> });
>>> }
>>
>> With help I've gotten some errors out of the program but I have reached
>> a point where something just won't work how it should. Your comments
>
> What doesn't work, and how should it?
>
>> here lead me to believe the reason is the basic way I have things laid
>> out. But I don't know how to:
>>
>> > move GUI actions onto the "Event Dispatch Thread" (EDT), further I
>> dont know how to write an EDT, or what specifically are 'GUI actions' as
>> opposed to other lines that relate to the GUI.
>
> You don't write the EDT. Did you read the tutorial link I provided?
>
> <http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html>
>
> GUI actions are all things that happen on the GUI, such as creating
> a 'JFrame', calling 'pack()', playing with 'Graphics', or anything else that
> is part of the GUI. Non-GUI actions are things like writing files, calculating
> values, updating the logical model, or anything else that is not part of
> the GUI.
>
> Do please read the tutorial to which I linked. There's a reason I provided
> that link.
>
>
>> Also, I thought the stuff I have in the constructor belonged there.
>
> Not all of it. The program itself must run from a *completely*
> constructed object. You start the program from inside the
> constructor, therefore it is running on an *incompletely*
> constructed object.
>
>> I dont know where to call the constructor from if not from 'main'.
>
> You should call the constructor from 'main()', provided you properly
> guard it inside the 'invokeAndWait()' call.
>
> Why did you think I recommended otherwise?
>
>> I did some reading about threads being unsafe.
>>
>> It would be very helpful to me if you could show how to rearrange the
>> code like you say would be better. If you have the time, it would be
>> very helpful. Thanks.
>
> What was wrong with what I already showed you (and you quoted)?
>
I looked at the link when you provided it. It said dont read this until
you first read the basic stuff about concurrence in previous topics. I
read that stuff.
Here's the code that should work but doesnt. A stripped down version of
my program is in the 2 files copied below. It is a simple calculator
like in Windows accessories. The example below only does addition and
subtraction. It isn't completely written - never writes the answer to
the textbox I haven't got that far yet. The code below is supposed to
work as follows: A number is sent to the textbox using button clicks and
when '+' button is clicked the displayed string is converted to double.
The displayed string remains displayed until the first digit of the next
number is entered then the displayed string is cleared and the second
number begins in the display. When '=' is clicked the second displayed
number (actually a string) is converted to double and added to the first
double number. The operation should be controlled by the 'opFlag' and
'addFlag' settings. It should clear the textbox when the second number
is entered but it does not. Print statements are included to show
variable values.
THE GUI FILE:
import java.awt.*;
import javax.swing.*;
public class KalcGUI extends JFrame {
Krunch crunchNu = new Krunch(this);
// set up row 1
JPanel row1 = new JPanel();
JTextField number1 = new JTextField(30);
// set up row 2
JPanel row2 = new JPanel();
JButton sev = new JButton("7");
JButton ate = new JButton("8");
JButton nin = new JButton("9");
JButton fou = new JButton("4");
JButton fiv = new JButton("5");
JButton six = new JButton("6");
JButton b04 = new JButton("");
JButton one = new JButton("1");
JButton two = new JButton("2");
JButton tre = new JButton("3");
JButton zro = new JButton("0");
JButton dot = new JButton(".");
JButton equ = new JButton("=");
JButton add = new JButton("+");
JButton sub = new JButton("--");
public KalcGUI() {
super();
setTitle("Calculator");
//setLookAndFeel();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridLayout layout = new GridLayout(2, 1, 10, 10);
setLayout(layout);
//add listeners
dot.addActionListener(crunchNu);
zro.addActionListener(crunchNu);
one.addActionListener(crunchNu);
two.addActionListener(crunchNu);
tre.addActionListener(crunchNu);
fou.addActionListener(crunchNu);
fiv.addActionListener(crunchNu);
six.addActionListener(crunchNu);
sev.addActionListener(crunchNu);
ate.addActionListener(crunchNu);
nin.addActionListener(crunchNu);
equ.addActionListener(crunchNu);
add.addActionListener(crunchNu);
sub.addActionListener(crunchNu);
FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER, 10, 10);
row1.add(number1);
row1.setLayout(layout1);
add(row1);
GridLayout layout2 = new GridLayout(5, 3, 10, 10);
row2.setLayout(layout2);
row2.add (sev);
row2.add (ate);
row2.add (nin);
row2.add (fou);
row2.add (fiv);
row2.add (six);
row2.add (one);
row2.add (two);
row2.add (tre);
row2.add (zro);
row2.add (dot);
row2.add (equ);
row2.add (add);
row2.add (sub);
add(row2);
pack();
setVisible(true);
}
public static void main(String[] arguments) {
KalcGUI frame = new KalcGUI();
}
}
THE CALCULATION FILE:
import javax.swing.*;
import java.awt.event.*;
public class Krunch implements ActionListener{
KalcGUI gui;
String strng1 = "";
boolean invFlag = false;
boolean addFlag = false;
boolean subFlag = false;
boolean opFlag = false;
int neg = 0;
String noChar = "";
Double operand1 = 0.0;
Double operand2 = 0.0;
public Krunch(KalcGUI in) {
gui = in;
}
public void actionPerformed(ActionEvent event){
//String strng1 = "";
String btn = event.getActionCommand();
// opflag clears display
if (opFlag){
System.out.println(opFlag);
// THIS SHOULD CLEAR THE TEXTBOX //
gui.number1.setText(noChar);
opFlag = false;
}
if (btn == "=") {operand2=Double.parseDouble(strng1);
if (addFlag) {
operand1 += operand2;
addFlag = false;
}
if (subFlag) {
operand1 += operand2;
subFlag = false;
}
}
if( btn.equals( "1" ) || btn.equals( "2" ) || btn.equals( "3" )
|| btn.equals( "4" )
|| btn.equals( "5" ) || btn.equals( "6" ) ||
btn.equals( "7" ) || btn.equals( "8" )
|| btn.equals( "9" ) || btn.equals( "0" ) ||
btn.equals( "." )) {
strng1 += btn;
}
gui.number1.setText(strng1);
if (btn == "+") {
addFlag = true;
opFlag = true;
System.out.println(addFlag);
System.out.println(opFlag);
operand1=Double.parseDouble(strng1);}
if (btn == "--") {
subFlag = true;
opFlag = true;
operand1=Double.parseDouble(strng1);}
}
}
[toc] | [prev] | [next] | [standalone]
| From | Mike Winter <mlwinter@gmail.com> |
|---|---|
| Date | 2012-06-28 04:55 -0700 |
| Message-ID | <4ac364c9-9527-40a9-a32f-3617e777c9d7@googlegroups.com> |
| In reply to | #15712 |
On Thursday, June 28, 2012 12:02:48 PM UTC+1, bilsch wrote: > Here's the code that should work but doesnt. [snip] I did outline why it doesn't in your other thread, "It doesn't see my 'if' statements". In addition to the other issues raised in both threads, your program suffers from logic errors which you don't seem to have addressed yet. See <news:o_sGr.321702$3i1.7177@fx10.am4> posted yesterday (27th) at 01:04 GMT. Kind regards, Mike
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-28 07:33 -0700 |
| Message-ID | <jshpv3$812$2@dont-email.me> |
| In reply to | #15713 |
On 6/28/2012 4:55 AM, Mike Winter wrote: > to have addressed yet. See <news:o_sGr.321702$3i1.7177@fx10.am4> > posted yesterday (27th) at 01:04 GMT. That link is completely mangled for me.
[toc] | [prev] | [next] | [standalone]
| From | Mike Winter <mlwinter@gmail.com> |
|---|---|
| Date | 2012-06-28 08:45 -0700 |
| Subject | [OT] Message IDs (Re: I need a different approach - suggestions please) |
| Message-ID | <e6e08178-a4b6-40ec-8c00-f21a8381b686@googlegroups.com> |
| In reply to | #15720 |
On Thursday, June 28, 2012 3:33:07 PM UTC+1, markspace wrote: > On 6/28/2012 4:55 AM, Mike Winter wrote: > > to have addressed yet. See <news:o_sGr.321702$3i1.7177@fx10.am4> > > posted yesterday (27th) at 01:04 GMT. > > > That link is completely mangled for me. It's the message ID for the post I wrote, but I know some news readers won't act on it properly. Hell, I might've written it incorrectly as it's been a long time since I used Usenet regularly. But that's why I mentioned the name of the thread, and the date and time of the post. ;) Mike
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-28 09:39 -0700 |
| Subject | Re: [OT] Message IDs (Re: I need a different approach - suggestions please) |
| Message-ID | <jsi1be$q71$1@dont-email.me> |
| In reply to | #15722 |
On 6/28/2012 8:45 AM, Mike Winter wrote: > It's the message ID for the post I wrote, but I know some news > readers won't act on it properly. Hell, I might've written it > incorrectly as it's been a long time since I used Usenet regularly. > But that's why I mentioned the name of the thread, and the date and > time of the post. ;) Here's a link using Google, which might work for more folks: <https://groups.google.com/d/msg/comp.lang.java.programmer/QNe2-BxD_8A/3L6ld8jBGJwJ>
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2012-06-28 09:44 -0700 |
| Message-ID | <dd2pu79t385m8ol3t3qab53mh7n6ofirpm@4ax.com> |
| In reply to | #15720 |
On Thu, 28 Jun 2012 07:33:07 -0700, markspace <-@.> wrote:
>On 6/28/2012 4:55 AM, Mike Winter wrote:
>> to have addressed yet. See <news:o_sGr.321702$3i1.7177@fx10.am4>
>> posted yesterday (27th) at 01:04 GMT.
>That link is completely mangled for me.
It works for me in Agent. It switched me over to the other
thread. I tried the link in the post you replied to and your post,
and both worked.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2012-06-28 12:51 -0400 |
| Message-ID | <jsi239$teb$1@dont-email.me> |
| In reply to | #15720 |
On 6/28/2012 10:33 AM, markspace wrote: > On 6/28/2012 4:55 AM, Mike Winter wrote: >> to have addressed yet. See <news:o_sGr.321702$3i1.7177@fx10.am4> >> posted yesterday (27th) at 01:04 GMT. > > > That link is completely mangled for me. Thunderbird doesn't properly support news URIs that don't specify a server. It's been on my todo list for years now. :-) -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-28 09:58 -0700 |
| Message-ID | <jsi2ga$m5$1@dont-email.me> |
| In reply to | #15726 |
On 6/28/2012 9:51 AM, Joshua Cranmer wrote: > On 6/28/2012 10:33 AM, markspace wrote: >> On 6/28/2012 4:55 AM, Mike Winter wrote: >>> to have addressed yet. See <news:o_sGr.321702$3i1.7177@fx10.am4> >>> posted yesterday (27th) at 01:04 GMT. >> >> >> That link is completely mangled for me. > > Thunderbird doesn't properly support news URIs that don't specify a > server. No, it doesn't. ;) I'll bike over to their office and yell at them. ;) ;)
[toc] | [prev] | [next] | [standalone]
| From | markspace <-@.> |
|---|---|
| Date | 2012-06-28 07:32 -0700 |
| Message-ID | <jshptj$812$1@dont-email.me> |
| In reply to | #15712 |
On 6/28/2012 4:02 AM, bilsch wrote:
> if( btn.equals( "1" ) || btn.equals( "2" ) || btn.equals( "3" )
> || btn.equals( "4" )
> || btn.equals( "5" ) || btn.equals( "6" ) || btn.equals(
> "7" ) || btn.equals( "8" )
> || btn.equals( "9" ) || btn.equals( "0" ) || btn.equals(
> "." )) {
Wow, you actually changed it. Good job.
I have to say that I like ".0123456789".contains( btn ) better. It's
much shorter. ;-)
> if (btn == "+") {
You really do need to change all of the other string comparisons to
.equals() too. This == stuff is going to fail unpredictably for you.
It tests for object identity (i.e., to objects are the same object) and
is only going to succeed for strings by luck at this point. .equals()
checks that the contents of the string are the same.
I'll stop there because any other errors might be masked by these ==
comparisons for strings.
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2012-06-26 03:49 -0700 |
| Message-ID | <7s4ju7lcde55pdegmp613d1lkk7a8ktgej@4ax.com> |
| In reply to | #15589 |
On Mon, 25 Jun 2012 15:31:32 -0700, bilsch <bilsch01@gmail.com> wrote,
quoted or indirectly quoted someone who said :
> JButton sev = new JButton("7");
> JButton ate = new JButton("8");
> JButton nin = new JButton("9");
you code will simplify if use use a array of JButtorns or some
subclass of JButtons.
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you get stuck trying to solve a computer program:
1. Go into the kitchen and make coffee.
2. If that fails, go for a walk.
3. If that fails, take a nap.
Why? To avoid being swamped with details, to see the big picture,
to allow in some random noise to kick you out of your thinking rut.
[toc] | [prev] | [next] | [standalone]
| From | bilsch <bilsch01@gmail.com> |
|---|---|
| Date | 2012-06-26 13:59 -0700 |
| Message-ID | <jsd7r4$76r$1@dont-email.me> |
| In reply to | #15594 |
On 6/26/2012 3:49 AM, Roedy Green wrote:
> On Mon, 25 Jun 2012 15:31:32 -0700, bilsch<bilsch01@gmail.com> wrote,
> quoted or indirectly quoted someone who said :
>
>> JButton sev = new JButton("7");
>> JButton ate = new JButton("8");
>> JButton nin = new JButton("9");
>
> you code will simplify if use use a array of JButtorns or some
> subclass of JButtons.
I realize there are better alternatives. I don't know any right
offhand. I have many more buttons than shown in the example.
Thanks for the advise. I like your website.
[toc] | [prev] | [next] | [standalone]
| From | Patricia Shanahan <pats@acm.org> |
|---|---|
| Date | 2012-06-29 08:12 -0700 |
| Message-ID | <f92dnc-p5ZZ9WHDSnZ2dnUVZ_sSdnZ2d@earthlink.com> |
| In reply to | #15589 |
On 6/25/2012 3:31 PM, bilsch wrote: > I'm trying to make a program that works like the calculator in Windows > Accessories - all input is from button clicks. Below I listed a > stripped down version of the GUI and a little of the processing behind > it. It is in two small files. I had intended that the program would > display a sequence of digits from button clicks, which I would then > convert into a Double precision number. The problem is I am constrained > to initialize the string within the method that accumulates the sequence > of digits. Everytime the method is called the string is reinitialized > with the result that my sequence of digits is only ever one digit long. > My plan would work if I could initialize the string outside the method, > however variable scope in Java doesn't allow it. ... I'm going back to the base article, to suggest a basically different approach. During my spare time over the last couple of weeks I've been studying an unfamiliar C++ graphics library. I realized that my normal approach to learning languages and libraries was entirely different from yours. I wrote a series of very simple, small programs, each of which introduced only one new technique. For example, my program for learning to connect a button to the code that should run when it is clicked created a window containing one button, and wrote "hello" to standard out each time it was clicked. When that was working I advanced to two buttons doing different things. Each learning program incorporated at most one new technique. The programs I was really trying to write did not use any new graphics techniques - I had tried everything out in smaller programs. Have you considered a step-by-step approach, as an alternative to writing an application and then trying to make it work? Patricia
[toc] | [prev] | [next] | [standalone]
| From | Gene Wirchenko <genew@ocis.net> |
|---|---|
| Date | 2012-06-29 10:02 -0700 |
| Message-ID | <1jnru7tn1dp1b6u9lnu9c2vlg3t1iiplkc@4ax.com> |
| In reply to | #15748 |
On Fri, 29 Jun 2012 08:12:24 -0700, Patricia Shanahan <pats@acm.org>
wrote:
[snip]
>I'm going back to the base article, to suggest a basically different
>approach.
>
>During my spare time over the last couple of weeks I've been studying an
>unfamiliar C++ graphics library. I realized that my normal approach to
>learning languages and libraries was entirely different from yours.
>
>I wrote a series of very simple, small programs, each of which
>introduced only one new technique. For example, my program for learning
>to connect a button to the code that should run when it is clicked
>created a window containing one button, and wrote "hello" to standard
>out each time it was clicked. When that was working I advanced to two
>buttons doing different things.
>
>Each learning program incorporated at most one new technique. The
>programs I was really trying to write did not use any new graphics
>techniques - I had tried everything out in smaller programs.
>
>Have you considered a step-by-step approach, as an alternative to
>writing an application and then trying to make it work?
I thought that I had mentioned that approach in this thread, but
no. I use the same approach as you when learning languages. For
general computing, I code a times table. First, I code the simplest
thing that I can to get it going. Then, I make adjustments in
whatever ways help me learn. Typically, the first version will not
have the columns line up, and that is the first change. I might have
to do something special to get right justification. I sometimes add
input for what range the table is to be for or for what operator. And
the list can go on. After that, a real-use program is much easier to
do.
Sincerely,
Gene Wirchenko
[toc] | [prev] | [next] | [standalone]
| From | bilsch <bilsch01@gmail.com> |
|---|---|
| Date | 2012-06-29 13:07 -0700 |
| Message-ID | <jsl1tr$4tp$1@dont-email.me> |
| In reply to | #15748 |
On 6/29/2012 8:12 AM, Patricia Shanahan wrote: > On 6/25/2012 3:31 PM, bilsch wrote: >> I'm trying to make a program that works like the calculator in Windows >> Accessories - all input is from button clicks. Below I listed a >> stripped down version of the GUI and a little of the processing behind >> it. It is in two small files. I had intended that the program would >> display a sequence of digits from button clicks, which I would then >> convert into a Double precision number. The problem is I am constrained >> to initialize the string within the method that accumulates the sequence >> of digits. Everytime the method is called the string is reinitialized >> with the result that my sequence of digits is only ever one digit long. >> My plan would work if I could initialize the string outside the method, >> however variable scope in Java doesn't allow it. > ... > > I'm going back to the base article, to suggest a basically different > approach. > > During my spare time over the last couple of weeks I've been studying an > unfamiliar C++ graphics library. I realized that my normal approach to > learning languages and libraries was entirely different from yours. > > I wrote a series of very simple, small programs, each of which > introduced only one new technique. For example, my program for learning > to connect a button to the code that should run when it is clicked > created a window containing one button, and wrote "hello" to standard > out each time it was clicked. When that was working I advanced to two > buttons doing different things. > > Each learning program incorporated at most one new technique. The > programs I was really trying to write did not use any new graphics > techniques - I had tried everything out in smaller programs. > > Have you considered a step-by-step approach, as an alternative to > writing an application and then trying to make it work? > > Patricia Yes, I do generally use a stepwise approach. I appreciate the value of that.
[toc] | [prev] | [standalone]
Page 4 of 4 — ← Prev page 1 2 3 [4]
Back to top | Article view | comp.lang.java.programmer
csiph-web