• No results found

This starts by establishing new topics encountered:

New - we've done frames, like creating windows on screen, and as well as that we've done paint methods, so using graphics to draw lines and things on screen,

Yeah

Um, I'm trying to think, using, what was it, window, window action listener, something like that, so you're assigning like when you hit the cross on the window it closes, things like that. Yeah, apart from that we've done buttons, briefly

So what's your reaction to that, is it kind of OK?

Yeah I mean its err I quite like it because its getting to be a bit more you know you're coding something that the sort of thing that you'd actually see on computers like everyday kind of thing like buttons, things like that, so its quite nice to see we're moving on to something a bit more advanced

Right OK there's two things there, one is that it corresponds to actual applications

Yeah

That are useful, and the other is that its visual, you can actually see it - which is the most interesting? or maybe they are both interesting?

Yeah dunno probably they are both interesting yeah but definitely the fact that you can see it, yeah it helps to create interest in it.

The student is saying that the fact that UI objects can be seen makes it more interesting. There is a possibility that the interest derives from the fact that it is easier to understand if the objects are in a sense visible. An alternative is that the objects are recognised as being used in 'professional' applications.

The mechanism of Java event-handling is seen by him as entirely in terms of embodied cognition, with the application 'listening' for an event - and there is no recognition of ActionListener as an interface:

179

One aspect of that is ActionListener um did that make sense?

Yes, sort of, cause it seems to be like in a crude way I guess the way I see it is if the method, its telling the program that you're running to listen for a particular event so for the window closing its listening yeah its kind of almost I dunno if its right but its like its always running and waiting to see if the action happens its kind of hard to explain its kind of listening.

Yeah yeah yeah so the idea of calling it an action listener idea makes sense.

Yeah

And you find it quite straight - you know, is it straight-forward to program?

What I've done so far, yeah.

OK now this relates to the idea of an interface

OK

Do you remember that?

I remember it from last term - I can't quite remember what it is.

So Matthew is happy with the embodied notion of the program listening, but does not see this as a example of the idea of an interface, introduced last term in the rather abstract context of timing.

The interview then moved on to ideas of class and object:

If you had to tell somebody what is an object, in Java, what would you say?

(29 second pause) I'm not entirely sure

So just as at the previous interview, Matthew cannot formulate a description of what an object is.

OK could you give me an example of an object, which, you know, you've used in programming?

Is it, like, when you create an object do you, say I have like, this is like what we did for the last exercise, say you had a class called Line and to create which had various methods and things of that

180

to display all the information for a line, and is it you create the object by saying public Line, this would be in a different class but public Line and then just the name of the line, or the name of what you wanted to refer to

Yeah, do you want to write that down? (he writes down

public Line line() )

So even in the case of an example, he does not have a strong grasp of the object concept, and certainly not the syntax. A short tutorial about

public Line line1 = new Line();

then followed. Line() was not recognised as a constructor invocation. However he can use the terms field and method appropriately:

This Line class - what methods would you have?

Ones for getting the start point, like co-ordinates

Ah OK yeah

So you'd create some fields x and y

OK so these would be data fields

Yeah

They'd be ints

Yeah

So you might have an x1 y1 as start points, x2 y2 as the endpoint OK so you'd have that there, and you say you'd have a method to get those? Yeah err OK so those data fields would they be public or private?

Private.

Why would you make them private?

So you can't accidentally change them.

Matthew has very recently done an exercise on this - but his answers are immediate, direct and correct. This is very significant:

181  He does not recognise constructor use  He correctly talks about fields and methods

 He grasps the notion of encapsulation as implemented with access control and accessor methods

This might be seen as 'illogical'. How can he talk about fields and methods, when he cannot say what an object is? But he does.

Even after this discussion of an example, he still cannot say what an object in general is, or what a class is:

What are Java objects in general?

(21 seconds pause) Just a way of calling classes and methods, or.. OK OK What would you say a class is?

(12 seconds pause) Probably just a list of methods including a constructor

OK so in a class you'd have a constructor and you'd have methods and data fields

Yeah

Yeah OK so when you actually program Java you define classes

Yeah

What's the connection between classes and objects?

(5 seconds) The object will contain.. the.. everything the class has in it?

The object will contain everything the class has in it. Like, methods do you mean?

Yeah. Well.. um.. is it just using all the methods and things in the class?

So an object uses, or can use, the methods in the class?

Yeah

So Matthew suggests a class is a set of methods which an object can use, like a library, but also that an object is a set of methods. There is a possibility that he would like a tutorial on 'what is an object' at this point, but this is resisted, and the idea of 'type' pursued.

182

OK so I mean it can be said in different ways - there are different versions of it. Yeah OK. One way - if I say the word 'type' to you, what do you think of in terms of type?

Type..

OK not very much

No (laughs)

So if I say int and char and double and float, what are they?

They're types of fields.

This is very striking, showing the same pattern. He can say nothing about 'type' as such, but he immediately and confidently says that int and so on are types of fields.

Interview Summary

1. He can talk about some ideas (field, method, encapsulation, constructor) associated with the object/class concept, in the context of one example, sometimes confidently but not uniformly.

2. He cannot talk about class and object in general 3. He can talk about examples of types

4. He does not respond to 'type' itself.

5. We can characterise this then as at this point, he can handle some examples of the ideas of class/object, and of type. But these instances have not yet been compressed into structured frames for class/object or type.

8.5.5 Interview Five

This started by establishing that the module had continued with more work on Swing- related topics.

183

The interview sought to investigate Matthew's grasp of this, and so a simple GUI program was examined. This was looked at in the NetBeans IDE - the program consisted of just one class, and was a simple calculator, which when running would look like:

The code is listed below. It was reviewed briefly, and then some points were examined: This is in the class called Main - that's public Main() - so what is that then?

Is that your constructor?

So now he can correctly identify a constructor in code.

Those five instructions (starting with setBounds in the constructor).. they don't refer to - they're method names, but there's no object name there - there's no object.setbounds - so what object is it talking about?

Is it talking about the object main, which is or yeah which I guess is your JFrame?

So he can see that a method invocation in a constructor refers to the object being constructed.

What do you make of that bit there? (Pointing at public static void main() )

Um I guess its yeah you're testing if you like to see whether um to see what to see if everything is working um so you're just running your one and only class. Without that your program would not run. Because you need the main method.

OK so the special thing about public static void main - what's special about that?

Um oh its that's what runs the code

184 OK

It just - I dunno it just - I don't think its ever really been explained like you know - you just what it will do is it'll just run through your code.. and produce the results from it, I guess

This is interesting because it shows that Matthew 1. Thinks that a class can be 'run'

2. Does not have a clear grasp that main is simply where execution starts. Java event-handling is rather mis-understood:

Quite a significant part of this is the button.addActionListener(this) - what's that all about?

Um.. you're assigning an actionListener to the button, so the button is well the button is effectively listening to see if its being clicked or not

The button is listening?

Oh its its it’s the setting er yes I guess its not the actual button its um I dunno its setting up a listener its listening to see if the button's being pressed or not.

OK that's quite interesting - what is listening?

Um

Because its not the button listening to itself

Is it - is the actionListener listening to it? Or.. is it .. or the constructor?

OK in the - here, we call the method addActionListener, button.addActionListener, and there's an argument this, addActionListener this. So what is this referring to?

Um.. would it be the program, or

At this point an explanation of the event-handling mechanism was attempted by the interviewer. A reason for the confusion here is discussed in the next chapter.

package interview; import java.awt.Color;

185 import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField;

public class Main extends JFrame implements ActionListener {

JTextField num1; JTextField num2; JButton button;

JLabel label = new JLabel(); public Main() { // set up frame.. setBounds(200, 200, 200, 200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Calculator"); setLayout(null);

// set up input textfields num1 = new JTextField(); num2 = new JTextField(); add(num1);

add(num2);

num1.setBounds(10, 10, 100, 20); num2.setBounds(10, 50, 100, 20); // set up label for output

label = new JLabel(); add(label);

label.setBounds(10, 110, 100, 20);

186

label.setBorder(BorderFactory.createLineBorder(Color.black) );

// set up Add button

button = new JButton("+"); add(button);

button.setBounds(10, 80, 50, 20); button.addActionListener(this); }

public static void main(String[] args) { Main main = new Main();

}

public void actionPerformed(ActionEvent e) { if (e.getSource() == button) {

// do the add process

double n1 = Double.parseDouble(num1.getText()); double n2 = Double.parseDouble(num2.getText()); double result = n1 + n2; label.setText("" + result); } } }

Interview summary

In a GUI programming context Matthew has a reasonably strong grasp of the practicalities of Swing programming.

187

This started with establishing that work had continued on using a JTable with data sourced from a database using code supplied. Then the task of exchanging two ints was introduced. Matthew immediately solved this with the standard third location approach - he recalled seeing this in class. The extension of this to using objects rather than primitive

types was presented, and he produced a corresponding solution (see Figure 8.8).

He was unsure whether this would work, and was prompted to draw a diagram showing how the references changed, following a reminder that references were pointers to objects. The result (Figure 8.9) shows two mistakes. Firstly he draws the arrows in the (normatively) wrong directions - for example, the first

s3=s1

yields an arrow from s1 to s3.

Secondly, the arrow goes to the pointer, not what the pointer points to. In other words the normative version is

Figure 8.8 String value exchange

Same error as Jennifer

Figure 8.8 String value exchange