[Cialug] GUI Programming
Matthew Nuzum
newz at bearfruit.org
Wed Mar 6 22:55:19 CST 2013
I agree that this is a common hangup, the fact that it is event driven. On embedded devices like the Arduino the same principle is used to respond to interrupts.
I do a lot of GUI programming, but I do it with HTML, CSS and Javascript. That said, it works like this:
function Button1Clicked(btn) {
alert('I was clicked!');
}
function main () {
while(true) {
// this loop repeats again and again forever
doNothingButWaitForEvents();
}
}
Your application sits there and does pretty much nothing, just spinning and waiting. When a user clicks a button then a bit of code that was waiting for the button to be clicked runs.
Even if you don't do GUI programming, this kind of code can be very useful, especially as you get into larger and more modularized code. At that point it's often called the Observer Pattern http://en.wikipedia.org/wiki/Observer_pattern
Imagine that you have an object that occasionally does something interesting, like make a note of the CPU temperature whenever it changes. Some other part of the app may generate a report when that interesting thing happens. (for example, send a text message to you to notify you that your CPU is about to melt) The object that does the monitoring will emit a signal or an event when it goes into action. The code that does the notification is set to listen to that signal, and when it happens it kicks into motion.
In either case (gui events or observer pattern) you have a callback function. It just gets assigned to the button or to the signal and when the button is clicked or the signal fired the callback runs. A lot of your code on simpler apps is creating numerous callback functions. One for every widget on the screen that can emit a signal.
Sometime, hopefully soon, something will click and you'll get it. After that, it's pretty easy stuff. Until then, try not to pull too much hair out. :-)
On Mar 6, 2013, at 1:22 PM, Scott Yates wrote:
> I am not sure if this is the problem, but one of the big things to realize
> about most modern GUI programming is that it is "event driven".
>
> This is probably not where your confusion lies, but just in case I thought
> I would mention it.
>
> If you need more to read:
> http://en.wikipedia.org/wiki/Event-driven_programming
>
>
>
> On Wed, Mar 6, 2013 at 1:15 PM, Todd Walton <tdwalton at gmail.com> wrote:
>
>> I hate it when programming books use card games or pizza ordering
>> programs to aid learning of the language. It fails to interest me.
>> O'Reilly has some sort of magical voodoo stuff they use to get around
>> having to use games and pizza, and yet still teach you a language.
>> Other publishers could learn something from them, I think.
>>
>> I'm not a professional programmer, but it does take up a good chunk of
>> my workday. I'm taking a second level programming class right now at
>> Simpson, based on Java. Last time I took a Java class it was taught
>> by an evil villain (the guy wore all white suits and a pink bowtie)
>> and I was scarred. This time it's going better, though. The
>> instructor is very cool and we're not creating pizza programs. But I
>> have trouble understanding GUI programming. I feel like there's some
>> basic lesson where they explained the reasoning, the concepts, the
>> things you're supposed to keep in mind, that I missed. I'm great with
>> logic, and I grok the whole object oriented thing. Not a prob.
>> Polymorphism. Inheritance. Cool stuff. But I don't get GUI
>> programming.
>>
>> Question: If you are a programmer, how often do you program GUIs?
>> Visual stuff other than markup?
>>
>> --
>> Todd
>> _______________________________________________
>> Cialug mailing list
>> Cialug at cialug.org
>> http://cialug.org/mailman/listinfo/cialug
>>
> _______________________________________________
> Cialug mailing list
> Cialug at cialug.org
> http://cialug.org/mailman/listinfo/cialug
More information about the Cialug
mailing list